-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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: Literal in ORDER BY
window definition should not be an ordinal referring to relation column
#8419
Conversation
ORDER BY
window definition should not be an ordinal referring to relation column
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @viirya -- this looks great to me. 🙏
I had some suggestions on comments to add, but I don't think they are necessary to merge this PR.
Thank you @viirya for this. Do we know what ISO standard says about literals in window definitions? Is PG standard-conforming in this case? |
Hmm, I can only find SQL-92 (https://datacadamia.com/_media/data/type/relation/sql/sql1992.txt) which defines In SQL-99 (http://web.cecs.pdx.edu/~len/sql1999.pdf), the same I can only confirm that Spark also treats literals as constants in ORDER BY window definition:
|
This PR can potentially close #8403 UPD:
Now it fails, before the fix it worked but gave a wrong answer |
Yea, currently you cannot have only window function without the column that has been "window", as I already added a few tests there showing the issue. I plan to address them one by one. |
We might also handle nulls the same way we handle
in |
|
#8402 has another issue, I think. This doesn't touch |
Thanks @alamb @ozankabak @comphead |
… referring to relation column (apache#8419) * fix: RANGE frame can be regularized to ROWS frame only if empty ORDER BY clause * Fix flaky test * Update test comment * Add code comment * Update * fix: Literal in window definition should not refer to relation column * Remove unused import * Update datafusion/sql/src/expr/function.rs Co-authored-by: Andrew Lamb <[email protected]> * Add code comment * Fix format --------- Co-authored-by: Andrew Lamb <[email protected]>
Which issue does this PR close?
Closes #.
Rationale for this change
This continues to fix one bug found in #8410. In particular, currently a literal value in
ORDER BY
clause of window definition will be treated as an ordinal reference to a column in the relation which I think is the behavior of sort expressions inORDER BY
keyword. However for window definition, Postgres simply treats a literal value as literal:What changes are included in this PR?
Making a literal value in
ORDER BY
window definition as literal, instead of a column ordinal.Are these changes tested?
Modified test in
sqllogictest
.Are there any user-facing changes?
Literal in
ORDER BY
window definition is changed to literal instead of a column ordinal.