Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
akurmustafa committed Jan 7, 2025
1 parent d2fe8a4 commit 16ef66c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions datafusion/physical-expr-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ datafusion-common = { workspace = true, default-features = true }
datafusion-expr-common = { workspace = true }
hashbrown = { workspace = true }
itertools = { workspace = true }
indexmap = { workspace = true }
15 changes: 12 additions & 3 deletions datafusion/physical-expr-common/src/sort_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ use arrow::datatypes::Schema;
use arrow::record_batch::RecordBatch;
use datafusion_common::Result;
use datafusion_expr_common::columnar_value::ColumnarValue;
use itertools::Itertools;
use itertools::{izip, Itertools};
use indexmap::IndexSet;

/// Represents Sort operation for a column in a RecordBatch
///
Expand Down Expand Up @@ -568,11 +569,19 @@ impl LexRequirement {
/// `vec![a Some(ASC)]`.
pub fn collapse(self) -> Self {
let mut output = Vec::<PhysicalSortRequirement>::new();
let mut exprs = IndexSet::new();
let mut reqs = vec![];
for item in self {
if !output.iter().any(|req| req.expr.eq(&item.expr)) {
output.push(item);
let PhysicalSortRequirement { expr, options: req } = item;
// new insertion
if exprs.insert(expr) {
reqs.push(req);
}
}
debug_assert_eq!(reqs.len(), exprs.len());
for (expr, req) in izip!(exprs, reqs) {
output.push(PhysicalSortRequirement::new(expr, req));
}
LexRequirement::new(output)
}
}
Expand Down

0 comments on commit 16ef66c

Please sign in to comment.