Skip to content
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

Grouping by struct member broken in 1.11 #1117

Open
bnaul opened this issue Sep 20, 2024 · 2 comments
Open

Grouping by struct member broken in 1.11 #1117

bnaul opened this issue Sep 20, 2024 · 2 comments
Assignees
Labels
api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API.

Comments

@bnaul
Copy link
Contributor

bnaul commented Sep 20, 2024

The following worked in 1.10 but raises an exception in 1.11:

from sqlalchemy import create_engine, Table, Integer, MetaData, Column, select, func
from sqlalchemy_bigquery import STRUCT

engine = create_engine(f"bigquery:///tmp", echo=True)
metadata = MetaData()
table = Table(
    "table",
    metadata,
    Column("id", Integer, primary_key=True),
    Column("nested", STRUCT(x=Integer))
)

query = (
    select(
        table.c.nested.x.label("x"),
    )
    .group_by(
        "x"
    )
)
print(query.compile(engine))

->

UnsupportedCompilationError: Compiler <sqlalchemy.sql.compiler.StrSQLCompiler object at 0x102f35f00> can't render element of type <function struct_getitem_op at 0x30532a9e0> (Background on this error at: https://sqlalche.me/e/14/l7de)

I traced the issue back to this line: https://github.com/googleapis/python-bigquery-sqlalchemy/pull/1053/files#diff-efe1987a73ae5b54aa817dc8c70541025df89d9d08601c8ab33fa84ad8c09de7R344

Removing this check or catching the exception resolves the issue. Perhaps a safer way to do this check would be to see if it's a function and then check its name? Not totally sure but I'm sure you will know @tswast 🙂

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API. label Sep 20, 2024
bnaul added a commit to replicahq/pybigquery that referenced this issue Sep 20, 2024
@tswast
Copy link
Collaborator

tswast commented Sep 23, 2024

My memory is a bit fuzzy on why we added that line. Presumably there was some test that was failing without it. @chalmerlowe Do you remember?

@chalmerlowe
Copy link
Collaborator

I will take a look tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/python-bigquery-sqlalchemy API.
Projects
None yet
Development

No branches or pull requests

4 participants