Skip to content

Commit

Permalink
add fix for dates (#112)
Browse files Browse the repository at this point in the history
Co-authored-by: jmriego <[email protected]>
  • Loading branch information
jmriego and jmriego authored May 23, 2022
1 parent 2e98ad0 commit 8206827
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions target_bigquery/db_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def bigquery_type(property_type, property_format):
#
# TODO: Detect if timezone postfix exists in the JSON and find if DATETIME or
# TIMESTAMP which includes time zone is the better column type
if property_format == 'date-time':
if property_format in ['date', 'date-time']:
return 'timestamp'
elif property_format == 'time':
return 'time'
Expand Down Expand Up @@ -128,7 +128,7 @@ def column_schema_avro(name, schema_property):
else:
result_type = 'string'

elif property_format == 'date-time':
elif property_format in ['date', 'date-time']:
result_type = {
'type': 'long',
'logicalType': 'timestamp-micros'}
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_db_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def mapper(schema_property):
# Incoming JSON schema types
json_str = {"type": ["string"]}
json_str_or_null = {"type": ["string", "null"]}
json_date = {"type": ["string"], "format": "date"}
json_dt = {"type": ["string"], "format": "date-time"}
json_dt_or_null = {"type": ["string", "null"], "format": "date-time"}
json_t = {"type": ["string"], "format": "time"}
Expand Down Expand Up @@ -96,6 +97,7 @@ def mapper(schema_property):
# Mapping from JSON schema types ot BigQuery column types
self.assertEqual(mapper(json_str), ('string', 'NULLABLE'))
self.assertEqual(mapper(json_str_or_null), ('string', 'NULLABLE'))
self.assertEqual(mapper(json_date), ('timestamp', 'NULLABLE'))
self.assertEqual(mapper(json_dt), ('timestamp', 'NULLABLE'))
self.assertEqual(mapper(json_dt_or_null), ('timestamp', 'NULLABLE'))
self.assertEqual(mapper(json_t), ('time', 'NULLABLE'))
Expand Down

0 comments on commit 8206827

Please sign in to comment.