Skip to content

Commit 41863dd

Browse files
authored
fix set (#14081)
Signed-off-by: Jay Zhan <jayzhan211@gmail.com>
1 parent 54a5d3f commit 41863dd

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

datafusion/physical-expr-common/src/physical_expr.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ use datafusion_expr_common::columnar_value::ColumnarValue;
3131
use datafusion_expr_common::interval_arithmetic::Interval;
3232
use datafusion_expr_common::sort_properties::ExprProperties;
3333

34+
/// Shared [`PhysicalExpr`].
35+
pub type PhysicalExprRef = Arc<dyn PhysicalExpr>;
36+
3437
/// [`PhysicalExpr`]s represent expressions such as `A + 1` or `CAST(c1 AS int)`.
3538
///
3639
/// `PhysicalExpr` knows its type, nullability and can be evaluated directly on

datafusion/physical-expr/src/physical_expr.rs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717

1818
use std::sync::Arc;
1919

20+
use datafusion_common::HashMap;
2021
pub(crate) use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
22+
pub use datafusion_physical_expr_common::physical_expr::PhysicalExprRef;
2123
use itertools::izip;
2224

23-
/// Shared [`PhysicalExpr`].
24-
pub type PhysicalExprRef = Arc<dyn PhysicalExpr>;
25-
2625
/// This function is similar to the `contains` method of `Vec`. It finds
2726
/// whether `expr` is among `physical_exprs`.
2827
pub fn physical_exprs_contains(
@@ -48,31 +47,24 @@ pub fn physical_exprs_bag_equal(
4847
lhs: &[Arc<dyn PhysicalExpr>],
4948
rhs: &[Arc<dyn PhysicalExpr>],
5049
) -> bool {
51-
// TODO: Once we can use `HashMap`s with `Arc<dyn PhysicalExpr>`, this
52-
// function should use a `HashMap` to reduce computational complexity.
53-
if lhs.len() == rhs.len() {
54-
let mut rhs_vec = rhs.to_vec();
55-
for expr in lhs {
56-
if let Some(idx) = rhs_vec.iter().position(|e| expr.eq(e)) {
57-
rhs_vec.swap_remove(idx);
58-
} else {
59-
return false;
60-
}
61-
}
62-
true
63-
} else {
64-
false
50+
let mut multi_set_lhs: HashMap<_, usize> = HashMap::new();
51+
let mut multi_set_rhs: HashMap<_, usize> = HashMap::new();
52+
for expr in lhs {
53+
*multi_set_lhs.entry(expr).or_insert(0) += 1;
54+
}
55+
for expr in rhs {
56+
*multi_set_rhs.entry(expr).or_insert(0) += 1;
6557
}
58+
multi_set_lhs == multi_set_rhs
6659
}
6760

6861
#[cfg(test)]
6962
mod tests {
70-
use std::sync::Arc;
63+
use super::*;
7164

7265
use crate::expressions::{Column, Literal};
7366
use crate::physical_expr::{
7467
physical_exprs_bag_equal, physical_exprs_contains, physical_exprs_equal,
75-
PhysicalExpr,
7668
};
7769

7870
use datafusion_common::ScalarValue;

0 commit comments

Comments
 (0)