diff --git a/target_bigquery/db_sync.py b/target_bigquery/db_sync.py index d487c43..72bc562 100644 --- a/target_bigquery/db_sync.py +++ b/target_bigquery/db_sync.py @@ -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' @@ -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'} diff --git a/tests/unit/test_db_sync.py b/tests/unit/test_db_sync.py index 186813e..828cb6a 100644 --- a/tests/unit/test_db_sync.py +++ b/tests/unit/test_db_sync.py @@ -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"} @@ -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'))