From 92318c808666695fb5c2f358083f1cb13158dca9 Mon Sep 17 00:00:00 2001 From: Peter Toth Date: Thu, 18 Apr 2024 15:27:32 +0200 Subject: [PATCH] Add default for `Expr` (#10127) --- datafusion/expr/src/expr.rs | 6 ++++++ datafusion/optimizer/src/unwrap_cast_in_comparison.rs | 8 +++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/datafusion/expr/src/expr.rs b/datafusion/expr/src/expr.rs index cffb58dadd8e..2a8fe4ca90a5 100644 --- a/datafusion/expr/src/expr.rs +++ b/datafusion/expr/src/expr.rs @@ -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, diff --git a/datafusion/optimizer/src/unwrap_cast_in_comparison.rs b/datafusion/optimizer/src/unwrap_cast_in_comparison.rs index bd14584fd5c1..1d80e235e7e9 100644 --- a/datafusion/optimizer/src/unwrap_cast_in_comparison.rs +++ b/datafusion/optimizer/src/unwrap_cast_in_comparison.rs @@ -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)) } ( @@ -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)) } @@ -262,7 +260,7 @@ impl TreeNodeRewriter for UnwrapCastExprRewriter { .collect::>>() 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)) }