Skip to content

Commit

Permalink
Add default for Expr (apache#10127)
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-toth authored Apr 18, 2024
1 parent ff0b845 commit 92318c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 6 additions & 0 deletions datafusion/expr/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ pub enum Expr {
Unnest(Unnest),
}

impl Default for Expr {
fn default() -> Self {
Expr::Literal(ScalarValue::Null)
}
}

#[derive(Clone, PartialEq, Eq, Hash, Debug)]
pub struct Unnest {
pub expr: Box<Expr>,
Expand Down
8 changes: 3 additions & 5 deletions datafusion/optimizer/src/unwrap_cast_in_comparison.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ impl TreeNodeRewriter for UnwrapCastExprRewriter {
};
**left = lit(value);
// unwrap the cast/try_cast for the right expr
**right =
mem::replace(right_expr, Expr::Literal(ScalarValue::Null));
**right = mem::take(right_expr);
Ok(Transformed::yes(expr))
}
(
Expand All @@ -203,8 +202,7 @@ impl TreeNodeRewriter for UnwrapCastExprRewriter {
return Ok(Transformed::no(expr));
};
// unwrap the cast/try_cast for the left expr
**left =
mem::replace(left_expr, Expr::Literal(ScalarValue::Null));
**left = mem::take(left_expr);
**right = lit(value);
Ok(Transformed::yes(expr))
}
Expand Down Expand Up @@ -262,7 +260,7 @@ impl TreeNodeRewriter for UnwrapCastExprRewriter {
.collect::<Result<Vec<_>>>() else {
return Ok(Transformed::no(expr))
};
**left = mem::replace(left_expr, Expr::Literal(ScalarValue::Null));
**left = mem::take(left_expr);
*list = right_exprs;
Ok(Transformed::yes(expr))
}
Expand Down

0 comments on commit 92318c8

Please sign in to comment.