Skip to content

Commit 93c1c35

Browse files
committed
pass timestamp_parser to schema_from_record
1 parent d0cd954 commit 93c1c35

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

bigquery/schema_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def bq_schema_field(name, bq_type, mode):
7575
field = bq_schema_field(k, bq_type, mode)
7676
if bq_type == "record":
7777
try:
78-
field['fields'] = schema_from_record(v)
78+
field['fields'] = schema_from_record(v, timestamp_parser)
7979
except InvalidTypeException, e:
8080
# recursively construct the key causing the error
8181
raise InvalidTypeException("%s.%s" % (k, e.key), e.value)

bigquery/tests/test_schema_builder.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,33 @@ def test_hierarchical_record(self):
9090

9191
self.assertItemsEqual(schema_from_record(record), schema)
9292

93+
def test_hierarchical_record_with_timestamps(self):
94+
record = {"global": "2001-01-01", "user": {"local": "2001-01-01"}}
95+
96+
schema_with_ts = [
97+
{"name": "global", "type": "timestamp", "mode": "nullable"},
98+
{"name": "user", "type": "record", "mode": "nullable",
99+
"fields": [{
100+
"name": "local",
101+
"type": "timestamp",
102+
"mode": "nullable"}]}]
103+
104+
schema_without_ts = [
105+
{"name": "global", "type": "string", "mode": "nullable"},
106+
{"name": "user", "type": "record", "mode": "nullable",
107+
"fields": [{
108+
"name": "local",
109+
"type": "string",
110+
"mode": "nullable"}]}]
111+
112+
self.assertItemsEqual(
113+
schema_from_record(record),
114+
schema_with_ts)
115+
116+
self.assertItemsEqual(
117+
schema_from_record(record, timestamp_parser=lambda x: False),
118+
schema_without_ts)
119+
93120
def test_repeated_field(self):
94121
record = {"ids": [1, 2, 3, 4, 5]}
95122
schema = [{"name": "ids", "type": "integer", "mode": "repeated"}]

0 commit comments

Comments
 (0)