Skip to content

Commit

Permalink
fix: use TimeWithZone for time type, but timezone doesn't affect any …
Browse files Browse the repository at this point in the history
…changes
  • Loading branch information
p-eye committed Aug 14, 2024
1 parent 8e7df4a commit 489b6b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
20 changes: 7 additions & 13 deletions lib/embulk/output/bigquery/value_converter_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,13 @@ def string_converter
}
end
when 'TIME'
if @timestamp_format
Proc.new {|val|
next nil if val.nil?
with_typecast_error(val) do |val|
Time.strptime(val, @timestamp_format).strftime("%H:%M:%S.%6N")
end
}
else
Proc.new {|val|
next nil if val.nil?
Time.parse(val).strftime("%H:%M:%S.%6N")
}
end
# TimeWithZone doesn't affect any change to the time value
Proc.new {|val|
next nil if val.nil?
with_typecast_error(val) do |val|
TimeWithZone.set_zone_offset(Time.parse(val), zone_offset).strftime("%H:%M:%S.%6N")
end
}
when 'RECORD'
Proc.new {|val|
next nil if val.nil?
Expand Down
12 changes: 8 additions & 4 deletions test/test_value_converter_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,15 @@ def test_time
assert_equal "00:03:22.000000", converter.call("00:03:22")
assert_equal "15:22:00.000000", converter.call("3:22 PM")
assert_equal "03:22:00.000000", converter.call("3:22 AM")

# Users must care of BQ datetime format by themselves with no timestamp_format
converter = ValueConverterFactory.new(SCHEMA_TYPE, 'TIME').create_converter
assert_equal nil, converter.call(nil)
assert_equal "00:00:00.000000", converter.call("2016-02-26 00:00:00")

# TimeWithZone doesn't affect any change to the time value
converter = ValueConverterFactory.new(
SCHEMA_TYPE, 'TIME', timezone: 'Asia/Tokyo'
).create_converter
assert_equal "15:00:01.000000", converter.call("15:00:01")

assert_raise { converter.call('foo') }
end

def test_record
Expand Down

0 comments on commit 489b6b2

Please sign in to comment.