René's URL Explorer Experiment


Title: Nested labeled expressions are omitted · Issue #39 · googleapis/python-bigquery-sqlalchemy · GitHub

Open Graph Title: Nested labeled expressions are omitted · Issue #39 · googleapis/python-bigquery-sqlalchemy

X Title: Nested labeled expressions are omitted · Issue #39 · googleapis/python-bigquery-sqlalchemy

Description: The pybigquery driver replaces nested labeled expression with the label instead of the actual expression. The result is an "Unrecognized name" error. Otherwise, when the expression label matches the inner column name, the expression will...

Open Graph Description: The pybigquery driver replaces nested labeled expression with the label instead of the actual expression. The result is an "Unrecognized name" error. Otherwise, when the expression label matches th...

X Description: The pybigquery driver replaces nested labeled expression with the label instead of the actual expression. The result is an "Unrecognized name" error. Otherwise, when the expression label ...

Opengraph URL: https://github.com/googleapis/python-bigquery-sqlalchemy/issues/39

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Nested labeled expressions are omitted","articleBody":"The pybigquery driver replaces nested labeled expression with the label instead of the actual expression. The result is an \"Unrecognized name\" error. Otherwise, when the expression label matches the inner column name, the expression will be silently omitted for a plain column reference.\r\n\r\nWhen the query is compiled and printed with `literal_binds`, the query looks correct (ie: the full expression is included), but for plain `print`, `compile`, and the actual execution, the expression is missing.\r\n\r\nIt seems like labeled expressions are only compiled one step past the first _inner_ label instead of recursively.\r\n\r\nTest case:\r\n\r\n```python\r\nfrom contextlib import contextmanager\r\n\r\nfrom sqlalchemy import MetaData, Table, case, create_engine, func, literal, select\r\n\r\nengine = create_engine(\"bigquery://\u003cyour connstr here\u003e\")\r\n# engine = create_engine(\"postgresql:/\u003cyour connstr here\u003e\")\r\n\r\n\r\n@contextmanager\r\ndef test_query():\r\n    engine.execute(\r\n        \"\"\"\r\n        create table test as (\r\n            select 1 as val\r\n            union all select 2\r\n            union all select 3\r\n        )\r\n    \"\"\"\r\n    )\r\n    val = Table(\"test\", MetaData(bind=engine), autoload=True).c.val\r\n    sum = func.sum\r\n    try:\r\n        yield select(\r\n            [\r\n                # References `inner` instead of `val`.\r\n                sum(sum(val.label(\"inner\")).label(\"outer\")).over(),\r\n                # Also references `inner` instead of `val`.\r\n                sum(case([[literal(True), val.label(\"inner\")]]).label(\"outer\")),\r\n                # Completely omits the case expression and references `middle`.\r\n                sum(\r\n                    sum(\r\n                        case([[literal(True), val.label(\"inner\")]]).label(\"middle\")\r\n                    ).label(\"outer\")\r\n                ).over(),\r\n            ]\r\n        )\r\n    finally:\r\n        engine.execute(\"drop table test\")\r\n\r\n\r\nwith test_query() as q:\r\n    print(\"Print:\")\r\n    print(q)\r\n\r\n    print(\"\\nCompile:\")\r\n    print(q.compile(engine))\r\n\r\n    print(\"\\nLiteral compile:\")\r\n    print(q.compile(engine, compile_kwargs={\"literal_binds\": True}))\r\n\r\n    print(\"\\nResult:\")\r\n    print(tuple(engine.execute(q)))\r\n```\r\n\r\nThe output from the Bigquery Engine is below - note that the query in the exception and all prints except the literal compile show the labels instead of inner expressions.\r\n\r\n```\r\nPrint:\r\nSELECT sum(sum(`inner`)) OVER () AS `anon_1`, sum(CASE WHEN %(param_1)s THEN `inner` END) AS `sum_1`, sum(sum(`middle`)) OVER () AS `anon_2`\r\nFROM `test`\r\n\r\nCompile:\r\nSELECT sum(sum(`inner`)) OVER () AS `anon_1`, sum(CASE WHEN %(param_1)s THEN `inner` END) AS `sum_1`, sum(sum(`middle`)) OVER () AS `anon_2`\r\nFROM `test`\r\n\r\nLiteral compile:\r\nSELECT sum(sum(`test`.`val`)) OVER () AS `anon_1`, sum(CASE WHEN true THEN `test`.`val` END) AS `sum_1`, sum(sum(CASE WHEN true THEN `test`.`val` END)) OVER () AS `anon_2`\r\nFROM `test`\r\n\r\nResult:\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.7/site-packages/google/cloud/bigquery/dbapi/cursor.py\", line 172, in execute\r\n    self._query_job.result()\r\n  File \"/usr/local/lib/python3.7/site-packages/google/cloud/bigquery/job.py\", line 2939, in result\r\n    super(QueryJob, self).result(timeout=timeout)\r\n  File \"/usr/local/lib/python3.7/site-packages/google/cloud/bigquery/job.py\", line 734, in result\r\n    return super(_AsyncJob, self).result(timeout=timeout)\r\n  File \"/usr/local/lib/python3.7/site-packages/google/api_core/future/polling.py\", line 127, in result\r\n    raise self._exception\r\ngoogle.api_core.exceptions.BadRequest: 400 Unrecognized name: `inner` at [1:16]\r\n\r\n(job ID: \u003comitted\u003e)\r\n\r\n                                                         -----Query Job SQL Follows-----                                                       \r\n\r\n    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |\r\n   1:SELECT sum(sum(`inner`)) OVER () AS `anon_1`, sum(CASE WHEN @`param_1` THEN `inner` END) AS `sum_1`, sum(sum(`middle`)) OVER () AS `anon_2`\r\n   2:FROM `test`\r\n    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n  File \"/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py\", line 1249, in _execute_context\r\n    cursor, statement, parameters, context\r\n  File \"/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py\", line 552, in do_execute\r\n    cursor.execute(statement, parameters)\r\n  File \"/usr/local/lib/python3.7/site-packages/google/cloud/bigquery/dbapi/cursor.py\", line 174, in execute\r\n    raise exceptions.DatabaseError(exc)\r\ngoogle.cloud.bigquery.dbapi.exceptions.DatabaseError: 400 Unrecognized name: `inner` at [1:16]\r\n\r\n(job ID: \u003comitted\u003e)\r\n\r\n                                                         -----Query Job SQL Follows-----                                                       \r\n\r\n    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |\r\n   1:SELECT sum(sum(`inner`)) OVER () AS `anon_1`, sum(CASE WHEN @`param_1` THEN `inner` END) AS `sum_1`, sum(sum(`middle`)) OVER () AS `anon_2`\r\n   2:FROM `test`\r\n    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n  File \"src/test.py\", line 54, in \u003cmodule\u003e\r\n    print(tuple(engine.execute(q)))\r\n  File \"/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py\", line 2179, in execute\r\n    return connection.execute(statement, *multiparams, **params)\r\n  File \"/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py\", line 988, in execute\r\n    return meth(self, multiparams, params)\r\n  File \"/usr/local/lib/python3.7/site-packages/sqlalchemy/sql/elements.py\", line 287, in _execute_on_connection\r\n    return connection._execute_clauseelement(self, multiparams, params)\r\n  File \"/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py\", line 1107, in _execute_clauseelement\r\n    distilled_params,\r\n  File \"/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py\", line 1253, in _execute_context\r\n    e, statement, parameters, cursor, context\r\n  File \"/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py\", line 1473, in _handle_dbapi_exception\r\n    util.raise_from_cause(sqlalchemy_exception, exc_info)\r\n  File \"/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py\", line 398, in raise_from_cause\r\n    reraise(type(exception), exception, tb=exc_tb, cause=cause)\r\n  File \"/usr/local/lib/python3.7/site-packages/sqlalchemy/util/compat.py\", line 152, in reraise\r\n    raise value.with_traceback(tb)\r\n  File \"/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/base.py\", line 1249, in _execute_context\r\n    cursor, statement, parameters, context\r\n  File \"/usr/local/lib/python3.7/site-packages/sqlalchemy/engine/default.py\", line 552, in do_execute\r\n    cursor.execute(statement, parameters)\r\n  File \"/usr/local/lib/python3.7/site-packages/google/cloud/bigquery/dbapi/cursor.py\", line 174, in execute\r\n    raise exceptions.DatabaseError(exc)\r\nsqlalchemy.exc.DatabaseError: (google.cloud.bigquery.dbapi.exceptions.DatabaseError) 400 Unrecognized name: `inner` at [1:16]\r\n\r\n(job ID: \u003comitted\u003e)\r\n\r\n                                                         -----Query Job SQL Follows-----                                                       \r\n\r\n    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |\r\n   1:SELECT sum(sum(`inner`)) OVER () AS `anon_1`, sum(CASE WHEN @`param_1` THEN `inner` END) AS `sum_1`, sum(sum(`middle`)) OVER () AS `anon_2`\r\n   2:FROM `test`\r\n    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |    .    |\r\n[SQL: SELECT sum(sum(`inner`)) OVER () AS `anon_1`, sum(CASE WHEN %(param_1)s THEN `inner` END) AS `sum_1`, sum(sum(`middle`)) OVER () AS `anon_2`\r\nFROM `test`]\r\n[parameters: {'param_1': True}]\r\n(Background on this error at: http://sqlalche.me/e/4xp6)\r\n```\r\n\r\nFor context (and correct behavior I think), when I change the engine to a Postgres database, the query looks correct and runs fine:\r\n\r\n```\r\nSELECT sum(sum(test.val)) OVER () AS anon_1, sum(CASE WHEN %(param_1)s THEN test.val END) AS sum_1, sum(sum(CASE WHEN %(param_2)s THEN test.val END)) OVER () AS anon_2\r\nFROM test\r\n\r\nCompile:\r\nSELECT sum(sum(test.val)) OVER () AS anon_1, sum(CASE WHEN %(param_1)s THEN test.val END) AS sum_1, sum(sum(CASE WHEN %(param_2)s THEN test.val END)) OVER () AS anon_2\r\nFROM test\r\n\r\nLiteral compile:\r\nSELECT sum(sum(test.val)) OVER () AS anon_1, sum(CASE WHEN true THEN test.val END) AS sum_1, sum(sum(CASE WHEN true THEN test.val END)) OVER () AS anon_2\r\nFROM test\r\n\r\nResult:\r\n((Decimal('6'), 6, Decimal('6')),)\r\n```","author":{"url":"https://github.com/JacobHayes","@type":"Person","name":"JacobHayes"},"datePublished":"2019-09-23T19:45:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/39/python-bigquery-sqlalchemy/issues/39"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:702318f5-2752-d9a7-904d-b6147f76ac77
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id87DC:3BD8F2:3A4D7F8:52DA1DE:6A4FACAD
html-safe-nonce6e5ac847ca03c10576f439a5a3f4e248cadd55be5c68be23422cdd87f4f5c80a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4N0RDOjNCRDhGMjozQTREN0Y4OjUyREExREU6NkE0RkFDQUQiLCJ2aXNpdG9yX2lkIjoiMjI4NzcxNTY1MDU1Mjk2NjMxNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacd6ba65a07a4aaea13acecb76d623391144aeccca7ae243749f740257dce7b760
hovercard-subject-tagissue:497291445
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/python-bigquery-sqlalchemy/39/issue_layout
twitter:imagehttps://opengraph.githubassets.com/3e657aaa96b668ce6b23d42e1582d67a1f1ff2a89d51515f3522ddf5ad094a86/googleapis/python-bigquery-sqlalchemy/issues/39
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/3e657aaa96b668ce6b23d42e1582d67a1f1ff2a89d51515f3522ddf5ad094a86/googleapis/python-bigquery-sqlalchemy/issues/39
og:image:altThe pybigquery driver replaces nested labeled expression with the label instead of the actual expression. The result is an "Unrecognized name" error. Otherwise, when the expression label matches th...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameJacobHayes
hostnamegithub.com
expected-hostnamegithub.com
Noneb92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9
turbo-cache-controlno-preview
go-importgithub.com/googleapis/python-bigquery-sqlalchemy git https://github.com/googleapis/python-bigquery-sqlalchemy.git
octolytics-dimension-user_id16785467
octolytics-dimension-user_logingoogleapis
octolytics-dimension-repository_id93616231
octolytics-dimension-repository_nwogoogleapis/python-bigquery-sqlalchemy
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id93616231
octolytics-dimension-repository_network_root_nwogoogleapis/python-bigquery-sqlalchemy
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release4b249b445842943ed31549e027f57a8ade9881ed
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/googleapis/python-bigquery-sqlalchemy/issues/39#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fpython-bigquery-sqlalchemy%2Fissues%2F39
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fpython-bigquery-sqlalchemy%2Fissues%2F39
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=googleapis%2Fpython-bigquery-sqlalchemy
Reloadhttps://github.com/googleapis/python-bigquery-sqlalchemy/issues/39
Reloadhttps://github.com/googleapis/python-bigquery-sqlalchemy/issues/39
Reloadhttps://github.com/googleapis/python-bigquery-sqlalchemy/issues/39
Please reload this pagehttps://github.com/googleapis/python-bigquery-sqlalchemy/issues/39
googleapis https://github.com/googleapis
python-bigquery-sqlalchemyhttps://github.com/googleapis/python-bigquery-sqlalchemy
Notifications https://github.com/login?return_to=%2Fgoogleapis%2Fpython-bigquery-sqlalchemy
Fork 140 https://github.com/login?return_to=%2Fgoogleapis%2Fpython-bigquery-sqlalchemy
Star 490 https://github.com/login?return_to=%2Fgoogleapis%2Fpython-bigquery-sqlalchemy
Code https://github.com/googleapis/python-bigquery-sqlalchemy
Issues 0 https://github.com/googleapis/python-bigquery-sqlalchemy/issues
Pull requests 1 https://github.com/googleapis/python-bigquery-sqlalchemy/pulls
Actions https://github.com/googleapis/python-bigquery-sqlalchemy/actions
Projects https://github.com/googleapis/python-bigquery-sqlalchemy/projects
Security and quality 0 https://github.com/googleapis/python-bigquery-sqlalchemy/security
Insights https://github.com/googleapis/python-bigquery-sqlalchemy/pulse
Code https://github.com/googleapis/python-bigquery-sqlalchemy
Issues https://github.com/googleapis/python-bigquery-sqlalchemy/issues
Pull requests https://github.com/googleapis/python-bigquery-sqlalchemy/pulls
Actions https://github.com/googleapis/python-bigquery-sqlalchemy/actions
Projects https://github.com/googleapis/python-bigquery-sqlalchemy/projects
Security and quality https://github.com/googleapis/python-bigquery-sqlalchemy/security
Insights https://github.com/googleapis/python-bigquery-sqlalchemy/pulse
#47https://github.com/googleapis/python-bigquery-sqlalchemy/pull/47
Nested labeled expressions are omittedhttps://github.com/googleapis/python-bigquery-sqlalchemy/issues/39#top
#47https://github.com/googleapis/python-bigquery-sqlalchemy/pull/47
type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.https://github.com/googleapis/python-bigquery-sqlalchemy/issues?q=state%3Aopen%20label%3A%22type%3A%20bug%22
https://github.com/JacobHayes
JacobHayeshttps://github.com/JacobHayes
on Sep 23, 2019https://github.com/googleapis/python-bigquery-sqlalchemy/issues/39#issue-497291445
type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.https://github.com/googleapis/python-bigquery-sqlalchemy/issues?q=state%3Aopen%20label%3A%22type%3A%20bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.