Skip to content

Commit 9e59f02

Browse files
committed
coordinate time format behavior for date convert in STRING
update comment fix test case
1 parent a4b25bd commit 9e59f02

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

lib/embulk/output/bigquery/value_converter_factory.rb

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,19 @@ def string_converter
204204
}
205205
end
206206
when 'DATE'
207-
Proc.new {|val|
208-
next nil if val.nil?
209-
with_typecast_error(val) do |val|
210-
TimeWithZone.set_zone_offset(Time.parse(val), zone_offset).strftime("%Y-%m-%d")
211-
end
212-
}
207+
if @timestamp_format
208+
Proc.new {|val|
209+
next nil if val.nil?
210+
with_typecast_error(val) do |val|
211+
TimeWithZone.set_zone_offset(Time.parse(val), zone_offset).strftime("%Y-%m-%d")
212+
end
213+
}
214+
else
215+
Proc.new {|val|
216+
next nil if val.nil?
217+
val # Users must care of BQ timestamp format
218+
}
219+
end
213220
when 'DATETIME'
214221
if @timestamp_format
215222
Proc.new {|val|

test/test_value_converter_factory.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,17 @@ def test_timestamp
241241
end
242242

243243
def test_date
244+
converter = ValueConverterFactory.new(
245+
SCHEMA_TYPE, 'DATE',
246+
timestamp_format: '%Y/%m/%d'
247+
).create_converter
248+
assert_equal nil, converter.call(nil)
249+
assert_equal "2016-02-26", converter.call("2016/02/26")
250+
251+
# Users must care of BQ date format by themselves with no timestamp_format
244252
converter = ValueConverterFactory.new(SCHEMA_TYPE, 'DATE').create_converter
245253
assert_equal nil, converter.call(nil)
246254
assert_equal "2016-02-26", converter.call("2016-02-26")
247-
assert_equal "2016-02-26", converter.call("2016-02-26 00:00:00")
248-
assert_raise { converter.call('foo') }
249255
end
250256

251257
def test_datetime

0 commit comments

Comments
 (0)