Class: OdpsDatahub::OdpsTableRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/odps/odps_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ OdpsTableRecord

Returns a new instance of OdpsTableRecord.



32
33
34
35
# File 'lib/fluent/plugin/odps/odps_table.rb', line 32

def initialize(schema)
  @mSchema = schema
  @mValues = Array.new(@mSchema.getColumnCount)
end

Instance Attribute Details

#mSchemaObject (readonly)

Returns the value of attribute mSchema.



30
31
32
# File 'lib/fluent/plugin/odps/odps_table.rb', line 30

def mSchema
  @mSchema
end

#mValuesObject (readonly)

Returns the value of attribute mValues.



30
31
32
# File 'lib/fluent/plugin/odps/odps_table.rb', line 30

def mValues
  @mValues
end

Instance Method Details

#getColumnsCountObject



37
38
39
# File 'lib/fluent/plugin/odps/odps_table.rb', line 37

def getColumnsCount
  @mSchema.getColumnCount
end

#getTableSchemaObject



41
42
43
# File 'lib/fluent/plugin/odps/odps_table.rb', line 41

def getTableSchema
  @mSchema
end

#getValue(idx) ⇒ Object



45
46
47
48
49
50
# File 'lib/fluent/plugin/odps/odps_table.rb', line 45

def getValue(idx)
  if idx < 0 or idx >= @mSchema.getColumnCount
    raise "idx out of range"
  end
  @mValues.at(idx)
end

#setBigInt(idx, value) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/fluent/plugin/odps/odps_table.rb', line 56

def setBigInt(idx, value)
  if value.is_a?Integer
    setValue(idx, value)
  else
    raise "value show be Integer"
  end
end

#setBoolean(idx, value) ⇒ Object



72
73
74
75
76
77
# File 'lib/fluent/plugin/odps/odps_table.rb', line 72

def setBoolean(idx, value)
  if value != false and value != true
    raise "value must be bool"
  end
  setValue(idx, value)
end

#setDateTime(idx, value) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/fluent/plugin/odps/odps_table.rb', line 79

def setDateTime(idx, value)
  if value.is_a?Integer and value >= $DATETIME_MIN_TICKS and  value <= $DATETIME_MAX_TICKS
    setValue(idx, value)
  elsif value.is_a?DateTime or value.is_a?Time
    if value.to_i*1000 >= $DATETIME_MIN_TICKS and  value.to_i*1000 <= $DATETIME_MAX_TICKS
      setValue(idx, value.to_i*1000)
    else
      raise "DateTime out of range or value show be Integer and between -62135798400000 and 253402271999000."
    end
  elsif value.is_a?String
    begin
      tmpTime = Time.parse(value)
      setValue(idx, tmpTime.to_i*1000)
    rescue
      raise "Parse string to datetime failed, string:" + value
    end
  else
    raise "DateTime cell should be in Integer or Time or DateTime format."
  end
end

#setDouble(idx, value) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/fluent/plugin/odps/odps_table.rb', line 64

def setDouble(idx, value)
  if value.is_a?Float
    setValue(idx, value)
  else
    raise "value show be Float"
  end
end

#setNullValue(idx) ⇒ Object



52
53
54
# File 'lib/fluent/plugin/odps/odps_table.rb', line 52

def setNullValue(idx)
  setValue(idx, nil)
end

#setString(idx, value) ⇒ Object



100
101
102
103
104
105
106
# File 'lib/fluent/plugin/odps/odps_table.rb', line 100

def setString(idx, value)
  if value.is_a?String and value.length < $STRING_MAX_LENTH
    setValue(idx, value)
  else
    raise "value show be String and len < " + $STRING_MAX_LENTH.to_s
  end
end