Skip to content

Commit 5a4ef63

Browse files
committed
fix: have orderings include constants which are heterogenius across partitions
1 parent dffeaac commit 5a4ef63

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

datafusion/physical-expr/src/equivalence/class.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,10 @@ pub fn const_exprs_contains(
211211
const_exprs: &[ConstExpr],
212212
expr: &Arc<dyn PhysicalExpr>,
213213
) -> bool {
214-
const_exprs
215-
.iter()
216-
.any(|const_expr| const_expr.expr.eq(expr))
214+
const_exprs.iter().any(|const_expr| {
215+
const_expr.expr.eq(expr)
216+
&& const_expr.across_partitions() != AcrossPartitions::Heterogeneous
217+
})
217218
}
218219

219220
/// An `EquivalenceClass` is a set of [`Arc<dyn PhysicalExpr>`]s that are known

datafusion/physical-expr/src/equivalence/properties.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ impl EquivalenceProperties {
438438
let filtered_exprs = LexOrdering::new(
439439
sort_exprs
440440
.into_iter()
441-
.filter(|expr| !self.is_expr_constant(&expr.expr))
441+
.filter(|expr| !self.is_expr_constant_across_partitions(&expr.expr))
442442
.collect(),
443443
);
444444

datafusion/physical-optimizer/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn add_sort_above<T: Clone + Default>(
4545
!node
4646
.plan
4747
.equivalence_properties()
48-
.is_expr_constant(&sort_expr.expr)
48+
.is_expr_constant_across_partitions(&sort_expr.expr)
4949
});
5050
let mut new_sort = SortExec::new(sort_expr, Arc::clone(&node.plan)).with_fetch(fetch);
5151
if node.plan.output_partitioning().partition_count() > 1 {

0 commit comments

Comments
 (0)