You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/03/10 16:45:25 UTC

[GitHub] [arrow-datafusion] Dandandan commented on a change in pull request #1981: Remove some more unecessary cloning in sql_expr_to_logical_expr

Dandandan commented on a change in pull request #1981:
URL: https://github.com/apache/arrow-datafusion/pull/1981#discussion_r823931931



##########
File path: datafusion/src/sql/planner.rs
##########
@@ -1495,121 +1493,134 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             }
 
             SQLExpr::Cast {
-                ref expr,
-                ref data_type,
+                expr,
+                data_type,
             } => Ok(Expr::Cast {
-                expr: Box::new(self.sql_expr_to_logical_expr(expr, schema)?),
-                data_type: convert_data_type(data_type)?,
+                expr: Box::new(self.sql_expr_to_logical_expr(*expr, schema)?),
+                data_type: convert_data_type(&data_type)?,
             }),
 
             SQLExpr::TryCast {
-                ref expr,
-                ref data_type,
+                expr,
+                data_type,
             } => Ok(Expr::TryCast {
-                expr: Box::new(self.sql_expr_to_logical_expr(expr, schema)?),
-                data_type: convert_data_type(data_type)?,
+                expr: Box::new(self.sql_expr_to_logical_expr(*expr, schema)?),
+                data_type: convert_data_type(&data_type)?,
             }),
 
             SQLExpr::TypedString {
                 ref data_type,
                 ref value,
             } => Ok(Expr::Cast {
                 expr: Box::new(lit(&**value)),
-                data_type: convert_data_type(data_type)?,
+                data_type: convert_data_type(&data_type)?,
             }),
 
-            SQLExpr::IsNull(ref expr) => Ok(Expr::IsNull(Box::new(
-                self.sql_expr_to_logical_expr(expr, schema)?,
+            SQLExpr::IsNull(expr) => Ok(Expr::IsNull(Box::new(
+                self.sql_expr_to_logical_expr(*expr, schema)?,
             ))),
 
-            SQLExpr::IsNotNull(ref expr) => Ok(Expr::IsNotNull(Box::new(
-                self.sql_expr_to_logical_expr(expr, schema)?,
+            SQLExpr::IsNotNull(expr) => Ok(Expr::IsNotNull(Box::new(
+                self.sql_expr_to_logical_expr(*expr, schema)?,
             ))),
 
             SQLExpr::IsDistinctFrom(left, right) => Ok(Expr::BinaryExpr {
-                left: Box::new(self.sql_expr_to_logical_expr(left, schema)?),
+                left: Box::new(self.sql_expr_to_logical_expr(*left, schema)?),
                 op: Operator::IsDistinctFrom,
-                right: Box::new(self.sql_expr_to_logical_expr(right, schema)?),
+                right: Box::new(self.sql_expr_to_logical_expr(*right, schema)?),
             }),
 
             SQLExpr::IsNotDistinctFrom(left, right) => Ok(Expr::BinaryExpr {
-                left: Box::new(self.sql_expr_to_logical_expr(left, schema)?),
+                left: Box::new(self.sql_expr_to_logical_expr(*left, schema)?),
                 op: Operator::IsNotDistinctFrom,
-                right: Box::new(self.sql_expr_to_logical_expr(right, schema)?),
+                right: Box::new(self.sql_expr_to_logical_expr(*right, schema)?),
             }),
 
-            SQLExpr::UnaryOp { ref op, ref expr } => {
-                self.parse_sql_unary_op(op, expr, schema)
+            SQLExpr::UnaryOp { op, expr } => {
+                self.parse_sql_unary_op(op, *expr, schema)
             }
 
             SQLExpr::Between {
-                ref expr,
-                ref negated,
-                ref low,
-                ref high,
+                expr,
+                negated,
+                low,
+                high,
             } => Ok(Expr::Between {
-                expr: Box::new(self.sql_expr_to_logical_expr(expr, schema)?),
-                negated: *negated,
-                low: Box::new(self.sql_expr_to_logical_expr(low, schema)?),
-                high: Box::new(self.sql_expr_to_logical_expr(high, schema)?),
+                expr: Box::new(self.sql_expr_to_logical_expr(*expr, schema)?),
+                negated,
+                low: Box::new(self.sql_expr_to_logical_expr(*low, schema)?),
+                high: Box::new(self.sql_expr_to_logical_expr(*high, schema)?),
             }),
 
             SQLExpr::InList {
-                ref expr,
-                ref list,
-                ref negated,
+                expr,
+                list,
+                negated,
             } => {
                 let list_expr = list
-                    .iter()
+                    .into_iter()
                     .map(|e| self.sql_expr_to_logical_expr(e, schema))
                     .collect::<Result<Vec<_>>>()?;
 
                 Ok(Expr::InList {
-                    expr: Box::new(self.sql_expr_to_logical_expr(expr, schema)?),
+                    expr: Box::new(self.sql_expr_to_logical_expr(*expr, schema)?),
                     list: list_expr,
-                    negated: *negated,
+                    negated,
                 })
             }
 
             SQLExpr::BinaryOp {
-                ref left,
-                ref op,
-                ref right,
-            } => self.parse_sql_binary_op(left, op, right, schema),
+                left,
+                op,
+                right,
+            } => self.parse_sql_binary_op(*left, op, *right, schema),
 
             #[cfg(feature = "unicode_expressions")]
             SQLExpr::Substring {
                 expr,
                 substring_from,
                 substring_for,
             } => {
-                let arg = self.sql_expr_to_logical_expr(expr, schema)?;
+                if substring_from.is_none() && substring_for.is_none() {

Review comment:
       If we want to make it cleaner (avoiding `unreachable` which I think is not very nice).
   
   1. match on substring to create args based on from_logic, for_logic 
   2. error on None/None
   3. Push creation of `arg` to after match to produce `args`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org