Skip to content

Commit b216fb5

Browse files
committed
Test nested record fields
1 parent 94d8210 commit b216fb5

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

scripts/sample_one_row.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"integer":"588","timestamp":"1381404436","string":"W 52 St & 11 Ave","float":"40.76727216","boolean":"false","date":"2013-10-10","datetime":"2013-10-10T11:27:16","time":"11:27:16","bytes":"7w==","record":{"name": "John Doe","age":"100"},"array":[1,2,3]}
1+
{"integer":"588","timestamp":"1381404436","string":"W 52 St & 11 Ave","float":"40.76727216","boolean":"false","date":"2013-10-10","datetime":"2013-10-10T11:27:16","time":"11:27:16","bytes":"7w==","record":{"name": "John Doe","age":"100"},"nested_record":{"record":{"name": "John Doe 2","age":"200"}},"array":[1,2,3]}

scripts/schema.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@
6060
}
6161
]
6262
},
63+
{
64+
"mode": "NULLABLE",
65+
"name": "nested_record",
66+
"type": "RECORD",
67+
"fields": [
68+
{
69+
"mode": "NULLABLE",
70+
"name": "record",
71+
"type": "RECORD",
72+
"fields": [
73+
{
74+
"mode": "NULLABLE",
75+
"name": "name",
76+
"type": "STRING"
77+
},
78+
{
79+
"mode": "NULLABLE",
80+
"name": "age",
81+
"type": "INTEGER"
82+
}
83+
]
84+
}
85+
]
86+
},
6387
{
6488
"mode": "REPEATED",
6589
"name": "array",

test/test_sqlalchemy_bigquery.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@
2525
b'\xef',
2626
'John Doe',
2727
100,
28-
{
29-
'name': 'John Doe',
30-
'age': 100,
31-
},
28+
'John Doe 2',
29+
200,
3230
[1, 2, 3],
3331
]
3432

@@ -46,6 +44,12 @@
4644
'name': 'John Doe',
4745
'age': 100,
4846
},
47+
{
48+
'record': {
49+
'name': 'John Doe 2',
50+
'age': 200,
51+
}
52+
},
4953
[1, 2, 3],
5054
]
5155

@@ -73,7 +77,8 @@
7377
{'name': 'bytes', 'type': types.BINARY(), 'nullable': True, 'default': None},
7478
{'name': 'record.name', 'type': types.String(), 'nullable': True, 'default': None},
7579
{'name': 'record.age', 'type': types.Integer(), 'nullable': True, 'default': None},
76-
{'name': 'record', 'type': types.JSON(), 'nullable': True, 'default': None},
80+
{'name': 'nested_record.record.name', 'type': types.String(), 'nullable': True, 'default': None},
81+
{'name': 'nested_record.record.age', 'type': types.Integer(), 'nullable': True, 'default': None},
7782
{'name': 'array', 'type': types.ARRAY(types.Integer()), 'nullable': True, 'default': None},
7883
]
7984

@@ -128,7 +133,8 @@ def query(table):
128133

129134

130135
def test_reflect_select(engine, table):
131-
assert len(table.c) == 13
136+
assert len(table.c) == 14
137+
132138
assert isinstance(table.c.integer, Column)
133139
assert isinstance(table.c.integer.type, types.Integer)
134140
assert isinstance(table.c.timestamp.type, types.TIMESTAMP)
@@ -139,7 +145,10 @@ def test_reflect_select(engine, table):
139145
assert isinstance(table.c.datetime.type, types.DATETIME)
140146
assert isinstance(table.c.time.type, types.TIME)
141147
assert isinstance(table.c.bytes.type, types.BINARY)
142-
assert isinstance(table.c.record.type, types.JSON)
148+
assert isinstance(table.c['record.age'].type, types.Integer)
149+
assert isinstance(table.c['record.name'].type, types.String)
150+
assert isinstance(table.c['nested_record.record.age'].type, types.Integer)
151+
assert isinstance(table.c['nested_record.record.name'].type, types.String)
143152
assert isinstance(table.c.array.type, types.ARRAY)
144153

145154
rows = table.select().execute().fetchall()

0 commit comments

Comments
 (0)