Title: Unable compare value from records array · Issue #233 · googleapis/python-bigquery-sqlalchemy · GitHub
Open Graph Title: Unable compare value from records array · Issue #233 · googleapis/python-bigquery-sqlalchemy
X Title: Unable compare value from records array · Issue #233 · googleapis/python-bigquery-sqlalchemy
Description: I need to create a join of 2 BQ tables where one of them has an id field that has to be compared with the record id in the repeated field (array of records) of another one. I'm struggling with SQLAlchemy implementation of the SQL query t...
Open Graph Description: I need to create a join of 2 BQ tables where one of them has an id field that has to be compared with the record id in the repeated field (array of records) of another one. I'm struggling with SQLA...
X Description: I need to create a join of 2 BQ tables where one of them has an id field that has to be compared with the record id in the repeated field (array of records) of another one. I'm struggling with ...
Opengraph URL: https://github.com/googleapis/python-bigquery-sqlalchemy/issues/233
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unable compare value from records array","articleBody":"I need to create a join of 2 BQ tables where one of them has an `id` field that has to be compared with the record id in the repeated field (array of records) of another one. I'm struggling with SQLAlchemy implementation of the SQL query that works fine. Tried to solve this problem in different ways, but nothing was successful, most relevant and similar to sql-like solution below. Probably, there are some troubles with sqlalchemy interpretation of SQL queries or result fetch either, aren't?\r\n\r\n#### Environment details\r\n\r\n - OS type and version: MacOS, 12.0 beta\r\n - Python version: 3.9.1\r\n - pip version: 21.1.2\r\n - `google-cloud-bigquery` version: 2.22.1\r\n\r\n#### Steps to reproduce\r\n\r\n 1. Create the BQ table `Mock` with fields:\r\n - name: `mock_id` | type: `STRING` | mode: `NULLABLE`\r\n \r\n 2. Create the BQ table `AnotherMock` with fields:\r\n - name: `objects` | type: `RECORD` | mode: `REPEATED`\r\n - name: `object_id` | type: `STRING` | mode: `NULLABLE`\r\n 3. Run code below (It gonna fail).\r\n 4. Run SQL below (it gonna success).\r\n\r\n#### SQL example\r\n```sql\r\nSELECT *\r\nFROM db.dataset.mock mock\r\nINNER JOIN (SELECT another_mock_objects FROM db.dataset.another_mock, UNNEST(objects) as another_mock_objects) another_mock\r\nON mock.mock_id = another_mock.another_mock_objects.object_id\r\n```\r\n\r\n\r\n#### Code example\r\n\r\n```python\r\n subquery = session.query(\r\n func.unnest(another_mock_model.c.objects).label('another_mock_objects')\r\n).subquery()\r\n\r\nsession.execute(\r\n select([]) \\\r\n .select_from(\r\n mock_model\r\n .join(\r\n another_mock_model,\r\n subquery.c.another_mock_objects.object_id == mock_model.c.mock_id,\r\n )\r\n )\r\n)\r\n```\r\n\r\n#### Stack trace\r\n`AttributeError: 'Comparator' object has no attribute 'object_id'`\r\n\r\n","author":{"url":"https://github.com/elsiniestra","@type":"Person","name":"elsiniestra"},"datePublished":"2021-07-29T20:18:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/233/python-bigquery-sqlalchemy/issues/233"}
| 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:84c77ecd-46f4-9eec-f480-b4e3a6349d5e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ED04:B97C3:3CCD109:54225B6:6A4F4ED8 |
| html-safe-nonce | 16d3d9ce4a869a92a153a6df963e1e4059ea145a161ece319dc0e4049045eaf3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRDA0OkI5N0MzOjNDQ0QxMDk6NTQyMjVCNjo2QTRGNEVEOCIsInZpc2l0b3JfaWQiOiIxNTU1OTkzNjI1Nzk1NDQ4NTM2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d28eb86bb912901bb5d568fd1397af0c169fe90080ee9bca81d75642b30f3f67 |
| hovercard-subject-tag | issue:956176210 |
| 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-sqlalchemy/233/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8d349cfef872ce1243b2ed2df344ee89d869c82db5cc23d62c1d871a23c909d3/googleapis/python-bigquery-sqlalchemy/issues/233 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8d349cfef872ce1243b2ed2df344ee89d869c82db5cc23d62c1d871a23c909d3/googleapis/python-bigquery-sqlalchemy/issues/233 |
| og:image:alt | I need to create a join of 2 BQ tables where one of them has an id field that has to be compared with the record id in the repeated field (array of records) of another one. I'm struggling with SQLA... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | elsiniestra |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-bigquery-sqlalchemy git https://github.com/googleapis/python-bigquery-sqlalchemy.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 93616231 |
| octolytics-dimension-repository_nwo | googleapis/python-bigquery-sqlalchemy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 93616231 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-bigquery-sqlalchemy |
| 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