Skip to content

Conversation

chenkovsky
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

in LogicalPlan::Filter unparsing,
if there's a window expr, it should be converted to quailify.

What changes are included in this PR?

If window expr is found, convert filter to quailify.

Are these changes tested?

UT

Are there any user-facing changes?

No

@github-actions github-actions bot added the sql SQL Planner label Sep 1, 2025
Comment on lines 2557 to 2559
assert_snapshot!(
sql,
@r#"SELECT "test"."k", "test"."v", rank() OVER (PARTITION BY "test"."k" ORDER BY "test"."v" ASC NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) FROM "test" QUALIFY (rank() OVER (PARTITION BY "test"."k" ORDER BY "test"."v" ASC NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) = 1)"#
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @chenkovsky, this now generates valid Datafusion SQL.
Unfortunately, the QUALIFY keyword is not available in PostgreSQL, as well as other systems (https://modern-sql.com/caniuse/qualify), meaning the output does not work there.

@chenkovsky chenkovsky marked this pull request as draft September 3, 2025 09:28
@chenkovsky chenkovsky marked this pull request as ready for review September 6, 2025 04:44
Copy link
Contributor

@nuno-faria nuno-faria left a comment

Choose a reason for hiding this comment

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

Thanks @chenkovsky, LGTM. I leave below just a minor note.

Comment on lines 276 to +279
impl Dialect for PostgreSqlDialect {
fn supports_qualify(&self) -> bool {
false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Like PostgreSQL, MySQL and SQLite also do not support the Qualify keyword, so they should also have supports_qualify returning false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sql SQL Planner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unparsing of Window functions is generating incorrect queries
2 participants