diff --git a/lib/embulk/output/bigquery/value_converter_factory.rb b/lib/embulk/output/bigquery/value_converter_factory.rb index ac0bae3..0e575b2 100644 --- a/lib/embulk/output/bigquery/value_converter_factory.rb +++ b/lib/embulk/output/bigquery/value_converter_factory.rb @@ -224,6 +224,13 @@ def string_converter val # Users must care of BQ timestamp format } end + when 'TIME' + Proc.new {|val| + next nil if val.nil? + with_typecast_error(val) do |val| + Time.parse(val).strftime("%H:%M:%S.%6N") + end + } when 'RECORD' Proc.new {|val| next nil if val.nil? diff --git a/test/test_value_converter_factory.rb b/test/test_value_converter_factory.rb index fcfa116..a5f84c1 100644 --- a/test/test_value_converter_factory.rb +++ b/test/test_value_converter_factory.rb @@ -262,6 +262,15 @@ def test_datetime assert_equal "2016-02-26 00:00:00", converter.call("2016-02-26 00:00:00") end + def test_time + converter = ValueConverterFactory.new( + SCHEMA_TYPE, 'TIME', + timestamp_format: '%H:%M:%S' + ).create_converter + assert_equal nil, converter.call(nil) + assert_equal "00:03:22.000000", converter.call("00:03:22") + end + def test_record converter = ValueConverterFactory.new(SCHEMA_TYPE, 'RECORD').create_converter assert_equal({'foo'=>'foo'}, converter.call(%Q[{"foo":"foo"}]))