Skip to content

Commit

Permalink
add TIME type conversion to string converter
Browse files Browse the repository at this point in the history
  • Loading branch information
p-eye committed Jul 22, 2024
1 parent ee1b21d commit 34de823
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/embulk/output/bigquery/value_converter_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
9 changes: 9 additions & 0 deletions test/test_value_converter_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]))
Expand Down

0 comments on commit 34de823

Please sign in to comment.