Skip to content

Commit

Permalink
Make resulting order deterministic after projection
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafasrepo committed Feb 19, 2024
1 parent 1731eac commit 9002493
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions datafusion/physical-expr/src/equivalence/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
use crate::expressions::CastExpr;
use arrow_schema::SchemaRef;
use datafusion_common::{JoinSide, JoinType, Result};
use indexmap::IndexSet;
use indexmap::{IndexMap, IndexSet};
use itertools::Itertools;
use std::collections::{HashMap, HashSet};
use std::hash::{Hash, Hasher};
use std::sync::Arc;

Expand Down Expand Up @@ -543,7 +542,7 @@ impl EquivalenceProperties {
/// c ASC: Node {None, HashSet{a ASC}}
/// ```
fn construct_dependency_map(&self, mapping: &ProjectionMapping) -> DependencyMap {
let mut dependency_map = HashMap::new();
let mut dependency_map = IndexMap::new();
for ordering in self.normalized_oeq_class().iter() {
for (idx, sort_expr) in ordering.iter().enumerate() {
let target_sort_expr =
Expand All @@ -569,7 +568,7 @@ impl EquivalenceProperties {
.entry(sort_expr.clone())
.or_insert_with(|| DependencyNode {
target_sort_expr: target_sort_expr.clone(),
dependencies: HashSet::new(),
dependencies: IndexSet::new(),
})
.insert_dependency(dependency);
}
Expand Down Expand Up @@ -961,7 +960,7 @@ fn referred_dependencies(
source: &Arc<dyn PhysicalExpr>,
) -> Vec<Dependencies> {
// Associate `PhysicalExpr`s with `PhysicalSortExpr`s that contain them:
let mut expr_to_sort_exprs = HashMap::<ExprWrapper, Dependencies>::new();
let mut expr_to_sort_exprs = IndexMap::<ExprWrapper, Dependencies>::new();
for sort_expr in dependency_map
.keys()
.filter(|sort_expr| expr_refers(source, &sort_expr.expr))
Expand Down Expand Up @@ -1119,8 +1118,8 @@ impl DependencyNode {
}
}

type DependencyMap = HashMap<PhysicalSortExpr, DependencyNode>;
type Dependencies = HashSet<PhysicalSortExpr>;
type DependencyMap = IndexMap<PhysicalSortExpr, DependencyNode>;
type Dependencies = IndexSet<PhysicalSortExpr>;

/// This function recursively analyzes the dependencies of the given sort
/// expression within the given dependency map to construct lexicographical
Expand Down

0 comments on commit 9002493

Please sign in to comment.