Skip to content

Apache DataFusion SQL Query Engine

[Minor], Bug Fix: Add empty ordering check at the source. (#7230)

Mustafa Akur43f182fcf01a
diff --git a/datafusion/core/src/datasource/physical_plan/mod.rs b/datafusion/core/src/datasource/physical_plan/mod.rs
index a9ca6fc90a..3e607d121a 100644
--- a/datafusion/core/src/datasource/physical_plan/mod.rs
+++ b/datafusion/core/src/datasource/physical_plan/mod.rs
@@ -959,7 +959,11 @@ fn get_projected_output_ordering(
// since rest of the orderings are violated
break;
}
- all_orderings.push(new_ordering);
+ // do not push empty entries
+ // otherwise we may have `Some(vec![])` at the output ordering.
+ if !new_ordering.is_empty() {
+ all_orderings.push(new_ordering);
+ }
}
all_orderings
}
diff --git a/datafusion/core/tests/sqllogictests/test_files/groupby.slt b/datafusion/core/tests/sqllogictests/test_files/groupby.slt
index 898abceefb..4490be50a2 100644
--- a/datafusion/core/tests/sqllogictests/test_files/groupby.slt
+++ b/datafusion/core/tests/sqllogictests/test_files/groupby.slt
@@ -3459,3 +3459,14 @@ AggregateExec: mode=Final, gby=[], aggr=[FIRST_VALUE(foo.x)]
--CoalescePartitionsExec
----AggregateExec: mode=Partial, gby=[], aggr=[FIRST_VALUE(foo.x)]
------MemoryExec: partitions=8, partition_sizes=[1, 0, 0, 0, 0, 0, 0, 0]
+
+
+query TT
+EXPLAIN SELECT c
+FROM multiple_ordered_table
+ORDER BY c ASC;
+----
+logical_plan
+Sort: multiple_ordered_table.c ASC NULLS LAST
+--TableScan: multiple_ordered_table projection=[c]
+physical_plan CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/window_2.csv]]}, projection=[c], output_ordering=[c@0 ASC NULLS LAST], has_header=true