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

Fix visit_label override to handle nested labels #47

Merged
merged 4 commits into from
Nov 18, 2020

Conversation

JacobHayes
Copy link
Contributor

@JacobHayes JacobHayes commented Feb 10, 2020

Fixes #39 - passes the "test case" I posted there and a number of internal queries I've tested with. Will look into adding a formal test in the next few days.

Print:
SELECT 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`
FROM `test`

Compile:
SELECT 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`
FROM `test`

Literal compile:
SELECT 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`
FROM `test`

Result:
((6, 6, 6),)

I haven't noticed any regressions with expressions in the group by. That seems to be fully supported by BQ anyway, so I'm guessing the method I removed was just for nicer looking "group by" statements? I'll try to break this a bit more, but would love some other insight there.

@mxmzdlv
Copy link
Contributor

mxmzdlv commented Feb 20, 2020

Heya! This breaks tests test_custom_expression and test_compiled_query_literal_binds.

For example, this generated query:

SELECT TIMESTAMP_TRUNC(timestamp, DAY) AS `timestamp_label`, sum(`test_pybigquery.sample`.`integer`) AS `sum_1`
FROM `test_pybigquery.sample`
GROUP BY TIMESTAMP_TRUNC(timestamp, DAY)
ORDER BY sum(`test_pybigquery.sample`.`integer`)

Fails with SELECT list expression references column timestamp which is neither grouped nor aggregated at [1:24]

If we group by the label timestamp then it works, but also if we remove ORDER BY clause, e.g.:

SELECT TIMESTAMP_TRUNC(timestamp, DAY) AS `timestamp_label`, sum(`test_pybigquery.sample`.`integer`) AS `sum_1`
FROM `test_pybigquery.sample`
GROUP BY TIMESTAMP_TRUNC(timestamp, DAY)

Then it works too. A bit confusing.

@JacobHayes
Copy link
Contributor Author

Hey @mxmzdlv thanks for the patience on this one! Finally got around to digging in a little more and think I found a simple solution.

@JacobHayes JacobHayes changed the title Remove visit_label override to fix nested labels Fix visit_label override to handle nested labels Sep 26, 2020
Copy link
Collaborator

@tswast tswast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patience.

I've pushed a commit with the test cases from your issue and confirmed that they are fixed by this PR.

@tswast tswast merged commit 9f47d0b into googleapis:master Nov 18, 2020
@JacobHayes JacobHayes deleted the fix-nested-labels branch November 20, 2020 17:41
@JacobHayes JacobHayes restored the fix-nested-labels branch November 20, 2020 17:42
@JacobHayes JacobHayes deleted the fix-nested-labels branch June 27, 2024 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nested labeled expressions are omitted
3 participants