File tree Expand file tree Collapse file tree 2 files changed +21
-8
lines changed
lib/embulk/output/bigquery Expand file tree Collapse file tree 2 files changed +21
-8
lines changed Original file line number Diff line number Diff line change @@ -204,12 +204,19 @@ def string_converter
204
204
}
205
205
end
206
206
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
213
220
when 'DATETIME'
214
221
if @timestamp_format
215
222
Proc . new { |val |
Original file line number Diff line number Diff line change @@ -241,11 +241,17 @@ def test_timestamp
241
241
end
242
242
243
243
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
244
252
converter = ValueConverterFactory . new ( SCHEMA_TYPE , 'DATE' ) . create_converter
245
253
assert_equal nil , converter . call ( nil )
246
254
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' ) }
249
255
end
250
256
251
257
def test_datetime
You can’t perform that action at this time.
0 commit comments