Skip to content

Commit

Permalink
fix fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
berkaysynnada committed Dec 17, 2024
1 parent 35bfdc4 commit 76f497e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
6 changes: 4 additions & 2 deletions datafusion/physical-expr/src/equivalence/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ pub struct ConstExpr {
/// struct docs for more details
across_partitions: bool,
/// The value of the constant expression
value: Option<ScalarValue>
value: Option<ScalarValue>,
}

impl PartialEq for ConstExpr {
fn eq(&self, other: &Self) -> bool {
self.across_partitions == other.across_partitions && self.expr.eq(&other.expr) && self.value == other.value
self.across_partitions == other.across_partitions
&& self.expr.eq(&other.expr)
&& self.value == other.value
}
}

Expand Down
47 changes: 25 additions & 22 deletions datafusion/physical-expr/src/equivalence/properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,28 +294,27 @@ impl EquivalenceProperties {
constants: impl IntoIterator<Item = ConstExpr>,
) -> Self {
let normalized_constants = constants
.into_iter()
.filter_map(|c| {
let across_partitions = c.across_partitions();
let value = c.value().cloned();
let expr = c.owned_expr();
let normalized_expr = self.eq_group.normalize_expr(expr);

if const_exprs_contains(&self.constants, &normalized_expr) {
return None;
}

let mut const_expr = ConstExpr::from(normalized_expr)
.with_across_partitions(across_partitions);
.into_iter()
.filter_map(|c| {
let across_partitions = c.across_partitions();
let value = c.value().cloned();
let expr = c.owned_expr();
let normalized_expr = self.eq_group.normalize_expr(expr);

if const_exprs_contains(&self.constants, &normalized_expr) {
return None;
}

let mut const_expr = ConstExpr::from(normalized_expr)
.with_across_partitions(across_partitions);

if let Some(value) = value {
const_expr = const_expr.with_value(value);
}
if let Some(value) = value {
const_expr = const_expr.with_value(value);
}

Some(const_expr)
})
.collect::<Vec<_>>();
Some(const_expr)
})
.collect::<Vec<_>>();

// Add all new normalized constants
self.constants.extend(normalized_constants);
Expand Down Expand Up @@ -1845,7 +1844,9 @@ fn calculate_union_binary(
let mut const_expr = ConstExpr::new(Arc::clone(lhs_const.expr()));

// If both sides have matching constant values, preserve the value and set across_partitions=true
if let (Some(lhs_val), Some(rhs_val)) = (lhs_const.value(), rhs_const.value()) {
if let (Some(lhs_val), Some(rhs_val)) =
(lhs_const.value(), rhs_const.value())
{
if lhs_val == rhs_val {
const_expr = const_expr
.with_across_partitions(true)
Expand Down Expand Up @@ -3678,12 +3679,14 @@ mod tests {
let literal_10 = ScalarValue::Int32(Some(10));

// Create first input with a=10
let const_expr1 = ConstExpr::new(Arc::clone(&col_a)).with_value(literal_10.clone());
let const_expr1 =
ConstExpr::new(Arc::clone(&col_a)).with_value(literal_10.clone());
let input1 = EquivalenceProperties::new(Arc::clone(&schema))
.with_constants(vec![const_expr1]);

// Create second input with a=10
let const_expr2 = ConstExpr::new(Arc::clone(&col_a)).with_value(literal_10.clone());
let const_expr2 =
ConstExpr::new(Arc::clone(&col_a)).with_value(literal_10.clone());
let input2 = EquivalenceProperties::new(Arc::clone(&schema))
.with_constants(vec![const_expr2]);

Expand Down

0 comments on commit 76f497e

Please sign in to comment.