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

Coordinate string date behavior #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion embulk-output-bigquery.gemspec
Original file line number Diff line number Diff line change
@@ -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."
Expand Down
19 changes: 13 additions & 6 deletions lib/embulk/output/bigquery/value_converter_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
10 changes: 8 additions & 2 deletions test/test_value_converter_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down