Skip to content

Commit 34de823

Browse files
committed
add TIME type conversion to string converter
1 parent ee1b21d commit 34de823

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/embulk/output/bigquery/value_converter_factory.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,13 @@ def string_converter
224224
val # Users must care of BQ timestamp format
225225
}
226226
end
227+
when 'TIME'
228+
Proc.new {|val|
229+
next nil if val.nil?
230+
with_typecast_error(val) do |val|
231+
Time.parse(val).strftime("%H:%M:%S.%6N")
232+
end
233+
}
227234
when 'RECORD'
228235
Proc.new {|val|
229236
next nil if val.nil?

test/test_value_converter_factory.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ def test_datetime
262262
assert_equal "2016-02-26 00:00:00", converter.call("2016-02-26 00:00:00")
263263
end
264264

265+
def test_time
266+
converter = ValueConverterFactory.new(
267+
SCHEMA_TYPE, 'TIME',
268+
timestamp_format: '%H:%M:%S'
269+
).create_converter
270+
assert_equal nil, converter.call(nil)
271+
assert_equal "00:03:22.000000", converter.call("00:03:22")
272+
end
273+
265274
def test_record
266275
converter = ValueConverterFactory.new(SCHEMA_TYPE, 'RECORD').create_converter
267276
assert_equal({'foo'=>'foo'}, converter.call(%Q[{"foo":"foo"}]))

0 commit comments

Comments
 (0)