Skip to content

Conversation

@viirya
Copy link
Member

@viirya viirya commented Dec 6, 2023

Which issue does this PR close?

Closes #.

Rationale for this change

We currently regularize RANGE window frame with UNBOUNDED/CURRENT ROW bounds with empty ORDER BY clause to ROWS frame with the UNBOUNDED bounds. This produces inconsistent result compared to Postgres where the case is treated as ORDER BY with constant sort key and unchanged window frame.

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added sql SQL Planner logical-expr Logical plan and expressions sqllogictest SQL Logic Tests (.slt) labels Dec 6, 2023
if (frame.start_bound.is_unbounded()
|| frame.start_bound == WindowFrameBound::CurrentRow)
&& (frame.end_bound == WindowFrameBound::CurrentRow
|| frame.end_bound.is_unbounded())
Copy link
Member Author

@viirya viirya Dec 7, 2023

Choose a reason for hiding this comment

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

RANGE frame with UNBOUNDED or CURRENT ROW PRECEDING/FOLLOWING without ORDER BY, all rows of the partitions become peers of the current row, i.e., the sort expression returns the same for all rows.

Copy link
Contributor

@mustafasrepo mustafasrepo 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 this PR @viirya. It is LGTM!.

@viirya
Copy link
Member Author

viirya commented Dec 8, 2023

Thank you @mustafasrepo

appletreeisyellow pushed a commit to appletreeisyellow/datafusion that referenced this pull request Dec 15, 2023
…e treated as constant sort (apache#8445)

* fix: RANGE frame for corner cases with empty ORDER BY clause should be treated as constant sort

* fix

* Make the test not flaky

* fix clippy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants