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

Update optimizer to avoid putting window functions in group by #1275

Merged
merged 1 commit into from
Jun 19, 2024

Conversation

courtneyholcomb
Copy link
Contributor

When using the WindowAggregationNode, you will end up with a subquery that our current SqlRewritingSubQueryReducer thinks can be collapsed into the outer query. However, this would put window functions in the group by clause, which triggers a SQL error. This PR updates the SqlRewritingSubQueryReducer logic to avoid reducing in that circumstance.

Copy link
Contributor

@tlento tlento left a comment

Choose a reason for hiding this comment

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

LGTM!

Comment on lines +295 to +304
group_by.column_alias in parent_column_aliases_with_window_functions
or (
group_by.expr.as_column_reference_expression
and group_by.expr.as_column_reference_expression.col_ref.column_name
in parent_column_aliases_with_window_functions
)
or (
group_by.expr.as_string_expression
and group_by.expr.as_string_expression.sql_expr in parent_column_aliases_with_window_functions
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Oof, why are there so many ways to reference a group by? Oh well. I think I'll blame BigQuery and Trino on general principles.

@courtneyholcomb courtneyholcomb force-pushed the court/window-agg-node branch from a0328b2 to 08fac01 Compare June 18, 2024 23:56
Base automatically changed from court/window-agg-node to main June 19, 2024 00:00
@courtneyholcomb courtneyholcomb force-pushed the court/optimize-window-node branch from 57e5464 to d04d6d3 Compare June 19, 2024 00:02
@courtneyholcomb courtneyholcomb enabled auto-merge (squash) June 19, 2024 00:02
@courtneyholcomb courtneyholcomb merged commit 8f715d9 into main Jun 19, 2024
15 checks passed
@courtneyholcomb courtneyholcomb deleted the court/optimize-window-node branch June 19, 2024 00:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants