Skip to content

Commit

Permalink
fix set
Browse files Browse the repository at this point in the history
Signed-off-by: Jay Zhan <[email protected]>
  • Loading branch information
jayzhan211 committed Jan 11, 2025
1 parent 4b7281e commit 9aae4c4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
3 changes: 3 additions & 0 deletions datafusion/physical-expr-common/src/physical_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ use datafusion_expr_common::columnar_value::ColumnarValue;
use datafusion_expr_common::interval_arithmetic::Interval;
use datafusion_expr_common::sort_properties::ExprProperties;

/// Shared [`PhysicalExpr`].
pub type PhysicalExprRef = Arc<dyn PhysicalExpr>;

/// [`PhysicalExpr`]s represent expressions such as `A + 1` or `CAST(c1 AS int)`.
///
/// `PhysicalExpr` knows its type, nullability and can be evaluated directly on
Expand Down
30 changes: 11 additions & 19 deletions datafusion/physical-expr/src/physical_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@

use std::sync::Arc;

use datafusion_common::HashMap;
pub(crate) use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
pub use datafusion_physical_expr_common::physical_expr::PhysicalExprRef;
use itertools::izip;

/// Shared [`PhysicalExpr`].
pub type PhysicalExprRef = Arc<dyn PhysicalExpr>;

/// This function is similar to the `contains` method of `Vec`. It finds
/// whether `expr` is among `physical_exprs`.
pub fn physical_exprs_contains(
Expand All @@ -48,31 +47,24 @@ pub fn physical_exprs_bag_equal(
lhs: &[Arc<dyn PhysicalExpr>],
rhs: &[Arc<dyn PhysicalExpr>],
) -> bool {
// TODO: Once we can use `HashMap`s with `Arc<dyn PhysicalExpr>`, this
// function should use a `HashMap` to reduce computational complexity.
if lhs.len() == rhs.len() {
let mut rhs_vec = rhs.to_vec();
for expr in lhs {
if let Some(idx) = rhs_vec.iter().position(|e| expr.eq(e)) {
rhs_vec.swap_remove(idx);
} else {
return false;
}
}
true
} else {
false
let mut multi_set_lhs: HashMap<_, usize> = HashMap::new();
let mut multi_set_rhs: HashMap<_, usize> = HashMap::new();
for expr in lhs {
*multi_set_lhs.entry(expr).or_insert(0) += 1;
}
for expr in rhs {
*multi_set_rhs.entry(expr).or_insert(0) += 1;
}
multi_set_lhs == multi_set_rhs
}

#[cfg(test)]
mod tests {
use std::sync::Arc;
use super::*;

use crate::expressions::{Column, Literal};
use crate::physical_expr::{
physical_exprs_bag_equal, physical_exprs_contains, physical_exprs_equal,
PhysicalExpr,
};

use datafusion_common::ScalarValue;
Expand Down

0 comments on commit 9aae4c4

Please sign in to comment.