Skip to content

Commit

Permalink
fix: ORDER BY window definition should work on null
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Dec 6, 2023
1 parent 439339a commit 362435a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion datafusion/optimizer/src/analyzer/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,10 @@ fn coerce_window_frame(
let target_type = match window_frame.units {
WindowFrameUnits::Range => {
if let Some(col_type) = current_types.first() {
if col_type.is_numeric() || is_utf8_or_large_utf8(col_type) {
if col_type.is_numeric()
|| is_utf8_or_large_utf8(col_type)
|| matches!(col_type, DataType::Null)
{
col_type
} else if is_datetime(col_type) {
&DataType::Interval(IntervalUnit::MonthDayNano)
Expand Down
8 changes: 8 additions & 0 deletions datafusion/sqllogictest/test_files/window.slt
Original file line number Diff line number Diff line change
Expand Up @@ -3785,3 +3785,11 @@ select a,
----
1 1
2 1

query II
select a,
rank() over (order by null RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) rnk
from (select 1 a union select 2 a) q ORDER BY a
----
1 1
2 1

0 comments on commit 362435a

Please sign in to comment.