google-cloud-python icon indicating copy to clipboard operation
google-cloud-python copied to clipboard

Support (non-legacy) SQL nested data types

Open dhermes opened this issue 10 years ago • 22 comments

STRUCT<t> and ARRAY<t> seem to be the types.

See #2342. h/t to @c0b for filing.


From #2585: Sample app that reproduces this

Stacktrace:

Traceback (most recent call last):
  File "simple_app.py", line 57, in <module>
    query_shakespeare()
  File "simple_app.py", line 47, in query_shakespeare
    page_token=page_token)
  File "lib/python2.7/site-packages/google/cloud/bigquery/query.py", line 401, in fetch_data
    rows_data = _rows_from_json(response.get('rows', ()), self.schema)
  File "lib/python2.7/site-packages/google/cloud/bigquery/_helpers.py", line 98, in _rows_from_json
    for item in cell['v']])
  File "lib/python2.7/site-packages/google/cloud/bigquery/_helpers.py", line 61, in _record_from_json
    for subfield, cell in zip(field.fields, value['f']):
KeyError: 'f'

Stepping into the debugger:

ipdb> value
{u'v': {u'f': [{u'v': u'hamlet'}, {u'v': u'5318'}]}}
ipdb> field.__dict__
{'field_type': u'RECORD', 'description': None, 'name': u'title', 'fields': [<google.cloud.bigquery.schema.SchemaField object at 0x7f4ba9227550>, <google.cloud.bigquery.schema.SchemaField object at 0x7f4ba9227690>], 'mode': u'REPEATED'}

(Added by @dhermes)

dhermes avatar Sep 19 '16 22:09 dhermes

@greghines Your error does not appear to be caused by the client library. Are you able to run the same query in the BigQuery UI?

tswast avatar Jan 12 '17 17:01 tswast

@tswast - thanks for the response. Yes the code does run in the BigQuery UI

greghines avatar Jan 12 '17 20:01 greghines