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.



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

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

Instance Attribute Details

#mSchemaObject (readonly)

Returns the value of attribute mSchema.



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

def mSchema
  @mSchema
end

#mValuesObject (readonly)

Returns the value of attribute mValues.



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

def mValues
  @mValues
end

Instance Method Details

#getColumnsCountObject



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

def getColumnsCount
  @mSchema.getColumnCount
end

#getTableSchemaObject



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

def getTableSchema
  @mSchema
end

#getValue(idx) ⇒ Object



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

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

#setBigInt(idx, value) ⇒ Object



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

def setBigInt(idx, value)
  if value.is_a?Integer
    setValue(idx, value)
  elsif value.is_a?String
    setValue(idx, value.to_i)
  else
    raise "value show be Integer, idx:" + idx.to_s + " value:" + value.to_s
  end
end

#setBoolean(idx, value) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fluent/plugin/odps/odps_table.rb', line 77

def setBoolean(idx, value)
  if value.is_a?String
    if value == "true"
      setValue(idx, true)
    elsif value == "false"
      setValue(idx, false)
    else
      raise "value must be true or false, idx:" + idx.to_s + " value:" + value.to_s
    end
  elsif value != false and value != true
    raise "value must be bool or string[true,false], idx:" + idx.to_s + " value:" + value.to_s
  else
    setValue(idx, value)
  end
end

#setDateTime(idx, value) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/fluent/plugin/odps/odps_table.rb', line 93

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, idx:" + idx.to_s + " value:" + value.to_s
  end
end

#setDecimal(idx, value) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/fluent/plugin/odps/odps_table.rb', line 114

def setDecimal(idx, value)
  if value.is_a?String
    setValue(idx, value)
  elsif value.is_a?Float
      setValue(idx, value.to_s)
  elsif value.is_a?BigDecimal
    setValue(idx, value.to_s)
  else
    raise "value can not be convert to decimal, idx:" + idx.to_s + " value:" + value.to_s
  end
end

#setDouble(idx, value) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/fluent/plugin/odps/odps_table.rb', line 67

def setDouble(idx, value)
  if value.is_a?Float
    setValue(idx, value)
  elsif value.is_a?String
    setValue(idx, value.to_f)
  else
    raise "value show be Float, idx:" + idx.to_s + " value:" + value.to_s
  end
end

#setNullValue(idx) ⇒ Object



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

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

#setString(idx, value) ⇒ Object



126
127
128
129
130
131
132
# File 'lib/fluent/plugin/odps/odps_table.rb', line 126

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 + ", idx:" + idx.to_s + " value:" + value.to_s
  end
end