Title: Support arrays of record/structs as query parameters · Issue #463 · googleapis/python-bigquery · GitHub
Open Graph Title: Support arrays of record/structs as query parameters · Issue #463 · googleapis/python-bigquery
X Title: Support arrays of record/structs as query parameters · Issue #463 · googleapis/python-bigquery
Description: Thanks for stopping by to let us know something could be better! PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response. Is y...
Open Graph Description: Thanks for stopping by to let us know something could be better! PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. ...
X Description: Thanks for stopping by to let us know something could be better! PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. ...
Opengraph URL: https://github.com/googleapis/python-bigquery/issues/463
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support arrays of record/structs as query parameters","articleBody":"Thanks for stopping by to let us know something could be better!\r\n\r\n**PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response.\r\n\r\n **Is your feature request related to a problem? Please describe.**\r\n Setting nested repeated fields via the python-bigquery API works (despite not being documented by [ArrayQueryParameter](https://googleapis.dev/python/bigquery/latest/generated/google.cloud.bigquery.query.ArrayQueryParameter.html#google.cloud.bigquery.query.ArrayQueryParameter)).\r\n[ArrayQueryParamter.to_api_repr](https://googleapis.dev/python/bigquery/latest/_modules/google/cloud/bigquery/query.html#ArrayQueryParameter.to_api_repr) has code to handle \"RECORD\" or \"STRUCT\" but doesn't check if the array is empty and so throw exceptions.\r\n \r\n **Describe the solution you'd like**\r\nI'd a way to define the schema for the array of records so that it doesn't matter that it's empty - I can still use the BQ python client. There appears to be solutions for typed languages https://github.com/googleapis/google-cloud-java/issues/2678 as well as dynamic languages https://github.com/googleapis/google-cloud-ruby/pull/4269 and losely typed languages https://github.com/googleapis/nodejs-bigquery/issues/400.\r\n\r\n **Describe alternatives you've considered**\r\nOur current solution involves naming each individual field in the repeated struct (eg fieldA_0, fieldB_0, fieldA_1,...)\r\nand sending over MANY query parameters. As there's a limit to the number of named parameters the API allows, this is far from perfect and makes our code significantly harder to read and understand.\r\n\r\n **Additional context**\r\n```python\r\nfrom google.cloud import bigquery\r\nclient = bigquery.Client()\r\n\r\ndef query(params):\r\n sql = \"SELECT * FROM UNNEST(@params) as param\"\r\n query_parameter = bigquery.ArrayQueryParameter(\r\n \"params\",\r\n \"RECORD\",\r\n [\r\n bigquery.StructQueryParameter.positional(\r\n bigquery.ScalarQueryParameter(\"key\", \"STRING\", key),\r\n bigquery.ScalarQueryParameter(\"value\", \"STRING\", value),\r\n )\r\n for key, value in (params.items())\r\n ],\r\n )\r\n for row in client.query(sql, job_config=bigquery.QueryJobConfig(query_parameters=[query_parameter])):\r\n print(dict(row))\r\n\r\nquery({\"one\": \"a\", \"two\": \"b\"}) # works\r\nquery({}) # IndexError: list index out of range\r\n``` ","author":{"url":"https://github.com/michellen-hf","@type":"Person","name":"michellen-hf"},"datePublished":"2021-01-08T05:41:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/463/python-bigquery/issues/463"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:984a1a7c-fcad-4074-831f-33d67e3e86cd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 870A:36E597:2A4206E:3A70C01:6A4F59C7 |
| html-safe-nonce | e9889ae89ffeb11c1419e3fd79cec5a7880af44944372c55d61db441801b90a8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzBBOjM2RTU5NzoyQTQyMDZFOjNBNzBDMDE6NkE0RjU5QzciLCJ2aXNpdG9yX2lkIjoiNDY1MzM5MTg2NjM0NzA4NDIzMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | feff6ddbc258859efd4f034ce8dde61ae4e065b1e98b56205e604a642a4bbcc9 |
| hovercard-subject-tag | issue:781861669 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/python-bigquery/463/issue_layout |
| twitter:image | https://opengraph.githubassets.com/867b2e9bbf7f6cb94fccd48cbef7222ada4fb68b60a74578e51a58a16cd5424d/googleapis/python-bigquery/issues/463 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/867b2e9bbf7f6cb94fccd48cbef7222ada4fb68b60a74578e51a58a16cd5424d/googleapis/python-bigquery/issues/463 |
| og:image:alt | Thanks for stopping by to let us know something could be better! PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | michellen-hf |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-bigquery git https://github.com/googleapis/python-bigquery.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 226992475 |
| octolytics-dimension-repository_nwo | googleapis/python-bigquery |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 226992475 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-bigquery |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width