Module: QueueryClient::RedshiftDataType

Defined in:
lib/queuery_client/redshift_data_type.rb

Constant Summary collapse

FALSE_VALUES =
[
  false, 0,
  "0", :"0",
  "f", :f,
  "F", :F,
  "false", :false,
  "FALSE", :FALSE,
  "off", :off,
  "OFF", :OFF,
].to_set.freeze

Class Method Summary collapse

Class Method Details

.type_cast(row, manifest_file) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/queuery_client/redshift_data_type.rb', line 15

def self.type_cast(row, manifest_file)
  row.zip(manifest_file.column_types).map do |value, type|
    next nil if (value == '' and type != 'character varing') # null becomes '' on unload

    case type
    when 'smallint', 'integer', 'bigint'
      value.to_i
    when 'numeric', 'double precision'
      value.to_f
    when 'character', 'character varying'
      value
    when 'timestamp without time zone', 'timestamp with time zone'
      value # Ruby does not have a class without timezone
    when 'date'
      Date.parse(value)
    when 'boolean'
      FALSE_VALUES.include?(value) ? false : true
    else
      raise "not support data type: #{type}"
    end
  end
end