Module: RedshiftConnector::RedshiftDataType

Defined in:
lib/redshift_connector/redshift_data_type.rb

Class Method Summary collapse

Class Method Details

.type_cast(row, manifest_file) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/redshift_connector/redshift_data_type.rb', line 4

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'
      Time.parse(value)
    when 'date'
      Date.parse(value)
    when 'boolean'
      value == 'true' ? true : false
    else
      raise "not support data type: #{type}"
    end
  end
end