Uh oh!
There was an error while loading. Please reload this page.
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 columnUh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
ozankabak
commented
Dec 6, 2023
Thank you @viirya for this. Do we know what ISO standard says about literals in window definitions? Is PG standard-conforming in this case? |
viirya
commented
Dec 6, 2023
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. |
comphead
commented
Dec 6, 2023
We might also handle nulls the same way we handle in |
viirya
commented
Dec 6, 2023
|
viirya
commented
Dec 6, 2023
#8402 has another issue, I think. This doesn't touch |
viirya
commented
Dec 6, 2023
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 <andrew@nerdnetworks.org> * Add code comment * Fix format --------- Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
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 BYclause 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 BYkeyword. 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 BYwindow 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 BYwindow definition is changed to literal instead of a column ordinal.