Title: Unnest Function In BigQuery SQLAlchemy Plugin Joins Twice When Selecting Other Columns in CTE or Subquery · Issue #368 · googleapis/python-bigquery-sqlalchemy · GitHub
Open Graph Title: Unnest Function In BigQuery SQLAlchemy Plugin Joins Twice When Selecting Other Columns in CTE or Subquery · Issue #368 · googleapis/python-bigquery-sqlalchemy
X Title: Unnest Function In BigQuery SQLAlchemy Plugin Joins Twice When Selecting Other Columns in CTE or Subquery · Issue #368 · googleapis/python-bigquery-sqlalchemy
Description: From a customer support request: Issue summary: This issue is closely related to Unnest function in BigQuery SQLAlchemy plugin joins twice when selecting other columns googleapis/python-bigquery-sqlalchemy#353. After the previous issue w...
Open Graph Description: From a customer support request: Issue summary: This issue is closely related to Unnest function in BigQuery SQLAlchemy plugin joins twice when selecting other columns googleapis/python-bigquery-sq...
X Description: From a customer support request: Issue summary: This issue is closely related to Unnest function in BigQuery SQLAlchemy plugin joins twice when selecting other columns googleapis/python-bigquery-sq...
Opengraph URL: https://github.com/googleapis/python-bigquery-sqlalchemy/issues/368
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unnest Function In BigQuery SQLAlchemy Plugin Joins Twice When Selecting Other Columns in CTE or Subquery ","articleBody":"From a customer support request:\r\n\r\n**Issue summary**: This issue is closely related to [Unnest function in BigQuery SQLAlchemy plugin joins twice when selecting other columns googleapis/python-bigquery-sqlalchemy#353](https://github.com/googleapis/python-bigquery-sqlalchemy/issues/353). After the previous issue was resolved, queries using the UNNEST function that are not in Common Table Expressions (CTE) or subqueries work as expected. See the following minimal example:\r\n\r\n```\r\nfrom sqlalchemy import create_engine, MetaData, select, func as F, Table, Column, Integer, ARRAY\r\n\r\nmetadata = MetaData()\r\ntable = Table(\r\n \"table1\",\r\n metadata,\r\n Column(\"foo\", Integer),\r\n Column(\"bars\", ARRAY(Integer))\r\n)\r\n\r\nengine = create_engine(\"bigquery://\", future=True)\r\nq = select(table.c.foo, F.unnest(table.c.bars).column_valued(\"bar\"))\r\nprint(q.compile(engine))\r\n```\r\n\r\nThis outputs the following, which is expected:\r\n```\r\nSELECT `table1`.`foo`, `bar` \r\nFROM `table1`, unnest(`table1`.`bars`) AS `bar`\r\n```\r\n\r\nHowever, if we use the table as a subquery or CTE, the issue manifests again. The following code (continuing from above):\r\n\r\n```\r\nq = q.cte(\"cte\")\r\nq = select(*q.columns)\r\nprint(q.compile(engine))\r\n```\r\n\r\nProduces the next output:\r\n\r\n```\r\nWITH `cte` AS \r\n(SELECT `table1`.`foo` AS `foo`, `bar` \r\nFROM `table1`, `table1` `table1_1`, unnest(`table1_1`.`bars`) AS `bar`)\r\n SELECT `cte`.`foo`, `cte`.`bar` \r\nFROM `cte`\r\n```\r\nNote that `table1` is duplicated in the `FROM` clause again.\r\n\r\n**Expected behavior**: It is expected to generate the following query instead (note the different FROM clause):\r\n```\r\nWITH `cte` AS \r\n(SELECT `table1`.`foo`, `bar` \r\nFROM `table1`, unnest(`table1`.`bars`) AS `bar`)\r\n SELECT `cte`.`foo`, `cte`.`bar` \r\nFROM `cte`\r\n```","author":{"url":"https://github.com/mgtcardenas","@type":"Person","name":"mgtcardenas"},"datePublished":"2021-10-28T15:54:05.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/368/python-bigquery-sqlalchemy/issues/368"}
| 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:84e38a15-553d-a086-a641-6c89c35d4581 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 91C8:9E060:673F2F:93F28C:6A4E3782 |
| html-safe-nonce | 28cb3a680abf86f022a2f7469ae9829245797905d88f0b11117d43de0bd57e53 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MUM4OjlFMDYwOjY3M0YyRjo5M0YyOEM6NkE0RTM3ODIiLCJ2aXNpdG9yX2lkIjoiMzIwNDc5MjQ2OTM0NzUxNDI0MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | d93fb25cc345afd32dee0f41ff3c91421df39b1ede1c9e8c62388e6bebc77efe |
| hovercard-subject-tag | issue:1038678887 |
| 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/368/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0f095d9055f0ee62b8e4b963622adc1695d4acbec810c0cc4fc9b474e9623e5e/googleapis/python-bigquery-sqlalchemy/issues/368 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0f095d9055f0ee62b8e4b963622adc1695d4acbec810c0cc4fc9b474e9623e5e/googleapis/python-bigquery-sqlalchemy/issues/368 |
| og:image:alt | From a customer support request: Issue summary: This issue is closely related to Unnest function in BigQuery SQLAlchemy plugin joins twice when selecting other columns googleapis/python-bigquery-sq... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mgtcardenas |
| hostname | github.com |
| expected-hostname | github.com |
| None | 030096ee0db095447bfe77409d33bfac127ca7128299c58deef27c52eaa1b1f0 |
| 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 | 42a6d378d7587a44c93aca255096cd66b7c8eb2d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width