Closed sgryjp closed 8 months ago
Would love to know the cause of this! I'm getting the same error when using ROLLUP
inside the groupby clause:
Example code:
import sqlalchemy as sa
from sqlalchemy_bigquery import BigQueryDialect
query = (
sa.select(sql_projections)
.select_from(model_expression)
.where(sa.and_(*filter_expressions))
.group_by(func.rollup(*groupby_expressions)) // <-- relevant rollup expression
.having(sa.and_(*having_expressions))
)
query_str = str(
query.compile(dialect=BigQueryDialect())
)
Output Query:
SELECT timestamp_trunc(`created_date`, YEAR) AS `created_date`,
`agency` AS `agency`,
`city` AS `city`,
count(*) AS `row_count`,
FROM `quickstart.nyc_311`
GROUP BY `rollup_1` // <-- error here, this should be ROLLUP(1, 2, ..) as it is in other dialects
I've been working around it by using sa.text
but would appreciate some insight into why this is happening.
Working on implementing group by, rollup and cube clauses as part of another customer issue, which should include a fix for this
@sgryjp @liutmelody This fix is now a part of branch development-build-1.11.0.dev3. I will be setting up a prerelease soon on PyPI as well for this development release, the reason being that this branch is based off our SQLAlchemy 1.4-2.0+ migration work. Please try it out and let me know if it solves your problem, if it doesn't feel free to reopen this issue.
@kiraksi Hi, thank you for fixing this issue! I confirmed that the problem was fixed by your commit 5cfc28089baa6106cf30f9efb268231792da9251.
I also confirmed that the branch development-build-v1.11.0.dev3
does reproduce the problem. It seems that the commit bd38a5e14145ca77ec462e7cf4e9a989f2eb1fb3 somehow gets the bug back again. Could you check if there is anything suspicious? Thank you in advance.
@sgryjp This is odd, the previous commit you mentioned was a fix that introduced other issues, I created a new fix that is now on development-build-v1.11.0.dev3, I even confirmed the fix by adding various test cases. Can you confirm again whether development-build-v1.11.0.dev3 does not fix your issue with the new commits there? This may actually be an issue with the labeling from the within_group_by=True value passed in to group by for timestamp_trunc. Please let me know, otherwise its a quick fix to add TIMESTAMP_TRUNC to the list of exclusions for that label.
@kiraksi Thank you for response!
I confirmed that neither of tag v1.11.0.dev3
nor HEAD of the branch development-build-v1.11.0.dev3
does not fix my issue. Running the "code example" in the first comment results the same as below:
Environment details
sqlalchemy-bigquery
version: 1.6.1Steps to reproduce
timestamp_trunc(`some_column`, hour)
Code example
Below is an example script to reproduce the symptom. Please refer to the first comment block in the file for detail.
Stack trace
N/A (no exception will be raised unless you send it to BigQuery)