-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bigquery: please support non-legacy-sql nested data type, and preserve order in json #2342
Comments
@c0b Could you share a snippet using our library indicating what is broken? |
like in googleapis/google-cloud-node#1593, this issue is not about what is broken, but how can you do better? if you call python |
Can you point out places we are calling |
I'm not sure, I haven't looked at the code details in this repo where did it call |
Can you give an example of output from this repo with the problem? We never use |
above code full path is |
|
@c0b the |
So would you tell me where is the code repo for gcloud SDK code? should be maintained by Google and this ticket can be re-routed? have a little test of this library, might be even worse, it raised exception with the new standard SQL with nested fields: In this case I have correct credentials / project setup in environement vars, it runs no problem with bq tool or with nodejs api, in ticket googleapis/google-cloud-node#1593 has the detailed API responses In [1]: from gcloud import bigquery
In [2]: client = bigquery.Client()
In [37]: query = client.run_sync_query('SELECT 1'); query.use_legacy_sql = False; query.run(); query.rows
Out[37]: [(1,)]
In [38]: query = client.run_sync_query('SELECT ARRAY[STRUCT("zx83" AS id, 1 AS a, 2 AS b), ("f8f7", 4, 7)] d'); query.use_legacy_sql = Fal
...: se; query.run(); query.rows
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-38-fda2dc8184d1> in <module>()
----> 1 query = client.run_sync_query('SELECT ARRAY[STRUCT("zx83" AS id, 1 AS a, 2 AS b), ("f8f7", 4, 7)] d'); query.use_legacy_sql = False; query.run(); query.rows
/home/ubuntu/.local/lib/python2.7/site-packages/gcloud/bigquery/query.pyc in rows(self)
202 :returns: fields describing the schema (None until set by the server).
203 """
--> 204 return _rows_from_json(self._properties.get('rows', ()), self.schema)
205
206 @property
/home/ubuntu/.local/lib/python2.7/site-packages/gcloud/bigquery/_helpers.pyc in _rows_from_json(rows, schema)
86 if field.mode == 'REPEATED':
87 row_data.append([converter(item, field)
---> 88 for item in cell['v']])
89 else:
90 row_data.append(converter(cell['v'], field))
/home/ubuntu/.local/lib/python2.7/site-packages/gcloud/bigquery/_helpers.pyc in _record_from_json(value, field)
52 if _not_null(value, field):
53 record = {}
---> 54 for subfield, cell in zip(field.fields, value['f']):
55 converter = _CELLDATA_FROM_JSON[subfield.field_type]
56 if field.mode == 'REPEATED':
KeyError: 'f' wonder is that correct way to call with new standard SQL? |
I don't know myself. Perhaps @jgeewax or @jonparrott can chime in?
Support for the "Standard SQL" data types is slowly being added: #2265, #2347. The |
The Cloud SDK is not currently open-source. |
Then please file your internal ticket on my behalf; I assume most of you guys are Google employees know where to re-route to. that closed source code doesn't have any transparency I don't know where can I complain to. |
@c0b the cloud SDK has a public issue tracker here: https://code.google.com/p/google-cloud-sdk/issues/list There's also a built-in command |
report in googleapis/google-cloud-node#1593 (comment) from a nodejs app, but since my app can also be written in Python I have a test of Python BigQuery API as well, it seems have a same problem:
the problems:
json.loads
convert a JSON object to python dict which uses key's internal hash code somewhat unpredictable order, way to fix is to load withOrderedDict
, and drop sort_keys parameter when callingjson.dumps
json.dumps(..., separators=(',', ': '))
many tools written in Python suffered the same problem, like what I commented in the popular httpie tool: httpie/cli#427 (comment)
HOW to Fix 2 & 3
Expected output:
The text was updated successfully, but these errors were encountered: