Skip to content

Commit d92a1d8

Browse files
committed
fix: Make input_sorted_by_group_key tolerate unrelated single value columns outside the group key prefix
1 parent c29478e commit d92a1d8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

datafusion/src/physical_plan/planner.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1716,16 +1716,21 @@ fn input_sorted_by_group_key(
17161716
}
17171717
sort_to_group[sort_key_pos] = group_i;
17181718
}
1719-
for i in 0..sort_key.len() {
1720-
if hints.single_value_columns.contains(&sort_key[i]) {
1721-
sort_key_hit[i] = true;
1719+
1720+
// At this point all elements of the group key mapped into some column of the sort key. This
1721+
// checks the group key is mapped into a prefix of the sort key, except that it's okay if it
1722+
// skips over single value columns.
1723+
let mut pref_len: usize = 0;
1724+
for (i, hit) in sort_key_hit.iter().enumerate() {
1725+
if !hit && !hints.single_value_columns.contains(&sort_key[i]) {
1726+
break;
17221727
}
1728+
pref_len += 1;
17231729
}
17241730

1725-
// At this point all elements of the group key mapped into some column of the sort key.
1726-
// This checks the group key is mapped into a prefix of the sort key.
1727-
let pref_len = sort_key_hit.iter().take_while(|present| **present).count();
17281731
if sort_key_hit[pref_len..].iter().any(|present| *present) {
1732+
// The group key did not hit a contiguous prefix of the sort key (ignoring single value
1733+
// columns); return false.
17291734
return false;
17301735
}
17311736

0 commit comments

Comments
 (0)