Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add TIME type conversion to string converter #168

Merged
merged 6 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
p-eye marked this conversation as resolved.
Show resolved Hide resolved
}
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
hiroyuki-sato marked this conversation as resolved.
Show resolved Hide resolved
converter = ValueConverterFactory.new(SCHEMA_TYPE, 'RECORD').create_converter
assert_equal({'foo'=>'foo'}, converter.call(%Q[{"foo":"foo"}]))
Expand Down