lib/embulk/output/bigquery/value_converter_factory.rb in embulk-output-bigquery-0.6.3 vs lib/embulk/output/bigquery/value_converter_factory.rb in embulk-output-bigquery-0.6.4
- old
+ new
@@ -208,10 +208,24 @@
next nil if val.nil?
with_typecast_error(val) do |val|
TimeWithZone.set_zone_offset(Time.parse(val), zone_offset).strftime("%Y-%m-%d")
end
}
+ when 'DATETIME'
+ if @timestamp_format
+ Proc.new {|val|
+ next nil if val.nil?
+ with_typecast_error(val) do |val|
+ Time.strptime(val, @timestamp_format).strftime("%Y-%m-%d %H:%M:%S.%6N")
+ end
+ }
+ else
+ Proc.new {|val|
+ next nil if val.nil?
+ val # Users must care of BQ timestamp format
+ }
+ end
when 'RECORD'
Proc.new {|val|
next nil if val.nil?
with_typecast_error(val) do |val|
JSON.parse(val)
@@ -249,9 +263,14 @@
}
when 'DATE'
Proc.new {|val|
next nil if val.nil?
val.localtime(zone_offset).strftime("%Y-%m-%d")
+ }
+ when 'DATETIME'
+ Proc.new {|val|
+ next nil if val.nil?
+ val.localtime(zone_offset).strftime("%Y-%m-%d %H:%M:%S.%6N")
}
else
raise NotSupportedType, "cannot take column type #{type} for timestamp column"
end
end