-
Notifications
You must be signed in to change notification settings - Fork 322
Closed
Labels
api: bigqueryIssues related to the googleapis/python-bigquery API.Issues related to the googleapis/python-bigquery API.dbapitype: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.
Description
Allow passing struct data to queries if explicit type information is provided in the placeholder.
For example, given a table created with:
create table mydb.mytable (person struct<name string, children array<struct<name string, bdate date>>>)
You can insert data with:
insert into mydb.mytable (person) values (%(v:struct<name string, children array<struct<name string, bdate date>>>)s)
passing a value like:
dict(name='par',
children=[
dict(name='ch1', bdate=datetime.date(2021, 1, 1)),
dict(name='ch2', bdate=datetime.date(2021, 1, 2)),
])
We have to pass the type explicitly because struct data are dictionaries and may not preserve ordering reliably.
Even though, dictionaries are now ordered, the ordering is likely to be fragile.
>>> d = dict()
>>> d['a'] = 1
>>> d['b'] = 2
>>> d
{'a': 1, 'b': 2}
>>> del d['a']
>>> d['a'] = 4
>>> d
{'b': 2, 'a': 4}
¯_(ツ)_/¯
Metadata
Metadata
Assignees
Labels
api: bigqueryIssues related to the googleapis/python-bigquery API.Issues related to the googleapis/python-bigquery API.dbapitype: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.‘Nice-to-have’ improvement, new feature or different behavior or design.