From a4b25bd4b814d9f7f5efb3df0af8fc19a48f0a8f Mon Sep 17 00:00:00 2001 From: potato2003 Date: Wed, 6 Nov 2019 13:40:52 +0900 Subject: [PATCH 1/2] 0.6.4 --- CHANGELOG.md | 4 ++++ embulk-output-bigquery.gemspec | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44e1bed..04b8622 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.6.4 - 2019-11-06 + +* [enhancement] Add DATETIME type conveter (thanks to @kekekenta) + ## 0.6.3 - 2019-10-28 * [enhancement] Add DATE type conveter (thanks to @tksfjt1024) diff --git a/embulk-output-bigquery.gemspec b/embulk-output-bigquery.gemspec index a33cc9e..595d9f4 100644 --- a/embulk-output-bigquery.gemspec +++ b/embulk-output-bigquery.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |spec| spec.name = "embulk-output-bigquery" - spec.version = "0.6.3" + spec.version = "0.6.4" spec.authors = ["Satoshi Akama", "Naotoshi Seo"] spec.summary = "Google BigQuery output plugin for Embulk" spec.description = "Embulk plugin that insert records to Google BigQuery." From 9e59f02cf83535e4e1910fef202c43df489dbe28 Mon Sep 17 00:00:00 2001 From: giwa Date: Wed, 6 May 2020 16:55:42 +0900 Subject: [PATCH 2/2] coordinate time format behavior for date convert in STRING update comment fix test case --- .../bigquery/value_converter_factory.rb | 19 +++++++++++++------ test/test_value_converter_factory.rb | 10 ++++++++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/embulk/output/bigquery/value_converter_factory.rb b/lib/embulk/output/bigquery/value_converter_factory.rb index fd6b7e2..9af61b1 100644 --- a/lib/embulk/output/bigquery/value_converter_factory.rb +++ b/lib/embulk/output/bigquery/value_converter_factory.rb @@ -204,12 +204,19 @@ def string_converter } end when 'DATE' - Proc.new {|val| - next nil if val.nil? - with_typecast_error(val) do |val| - TimeWithZone.set_zone_offset(Time.parse(val), zone_offset).strftime("%Y-%m-%d") - end - } + if @timestamp_format + Proc.new {|val| + next nil if val.nil? + with_typecast_error(val) do |val| + TimeWithZone.set_zone_offset(Time.parse(val), zone_offset).strftime("%Y-%m-%d") + end + } + else + Proc.new {|val| + next nil if val.nil? + val # Users must care of BQ timestamp format + } + end when 'DATETIME' if @timestamp_format Proc.new {|val| diff --git a/test/test_value_converter_factory.rb b/test/test_value_converter_factory.rb index df17ccd..f9445ff 100644 --- a/test/test_value_converter_factory.rb +++ b/test/test_value_converter_factory.rb @@ -241,11 +241,17 @@ def test_timestamp end def test_date + converter = ValueConverterFactory.new( + SCHEMA_TYPE, 'DATE', + timestamp_format: '%Y/%m/%d' + ).create_converter + assert_equal nil, converter.call(nil) + assert_equal "2016-02-26", converter.call("2016/02/26") + + # Users must care of BQ date format by themselves with no timestamp_format converter = ValueConverterFactory.new(SCHEMA_TYPE, 'DATE').create_converter assert_equal nil, converter.call(nil) assert_equal "2016-02-26", converter.call("2016-02-26") - assert_equal "2016-02-26", converter.call("2016-02-26 00:00:00") - assert_raise { converter.call('foo') } end def test_datetime