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 15:55:49 UTC

[GitHub] [arrow-datafusion] alamb opened a new pull request #1981: Remove some more unecessary cloning in sql_expr_to_logical_expr

alamb opened a new pull request #1981:
URL: https://github.com/apache/arrow-datafusion/pull/1981


   # Rationale
   Re https://github.com/apache/arrow-datafusion/issues/1469
   Follow on to https://github.com/apache/arrow-datafusion/pull/1945# from @doki23  ❤️ 
   
   # Changes
   Remove some more unnecessary `clone()` while building up `Exprs` from `SQLExpr`. 
   
   I wanted a small vanity project to make some actual code changes rather than filing ticket or reviewing more PRs lol -- see https://github.com/apache/arrow-datafusion/pull/1945#pullrequestreview-903442421
   
   I'll highlight the places below that this isn't just mechanical
   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
alamb commented on pull request #1981:
URL: https://github.com/apache/arrow-datafusion/pull/1981#issuecomment-1065938621


   Thanks @yjshen !


-- 
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



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

Posted by GitBox <gi...@apache.org>.
alamb commented on a change in pull request #1981:
URL: https://github.com/apache/arrow-datafusion/pull/1981#discussion_r823873888



##########
File path: datafusion/src/sql/planner.rs
##########
@@ -1209,7 +1208,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
     }
 
     /// Generate a relational expression from a SQL expression
-    pub fn sql_to_rex(&self, sql: &SQLExpr, schema: &DFSchema) -> Result<Expr> {
+    pub fn sql_to_rex(&self, sql: SQLExpr, schema: &DFSchema) -> Result<Expr> {

Review comment:
       This is the real change in this PR: take `sql` by ownership rather than reference

##########
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:
       I moved the error up here because it consumes the original `expr` to make a nice message.

##########
File path: datafusion/src/sql/planner.rs
##########
@@ -1246,34 +1245,37 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
 
     fn sql_fn_arg_to_logical_expr(
         &self,
-        sql: &FunctionArg,
+        sql: FunctionArg,
         schema: &DFSchema,
     ) -> Result<Expr> {
-        let arg: &FunctionArgExpr = match sql {
-            FunctionArg::Named { name: _, arg } => arg,
-            FunctionArg::Unnamed(arg) => arg,
-        };
-
-        match arg {
-            FunctionArgExpr::Expr(arg) => self.sql_expr_to_logical_expr(arg, schema),
-            FunctionArgExpr::Wildcard => Ok(Expr::Wildcard),
-            FunctionArgExpr::QualifiedWildcard(_) => {
-                Err(DataFusionError::NotImplemented(format!(
-                    "Unsupported qualified wildcard argument: {:?}",
-                    sql
-                )))
+        match sql {

Review comment:
       I had to expand out the 4 cases here to avoid cloning - it isn't as nice but I think it is still pretty straightforward




-- 
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



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

Posted by GitBox <gi...@apache.org>.
alamb commented on a change in pull request #1981:
URL: https://github.com/apache/arrow-datafusion/pull/1981#discussion_r823970010



##########
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:
       Thanks for the suggestion -- I actually tried this and found a challenge that `arg` is actually used in the match statements (to form a `Vec`). I could make a `mut vec` and push arg on the front afterwards, or do some iterator magic, but I felt in the end this was perhaps the easiest to understand formulation 🤔 
   
   ```rust
                           vec![arg, from_logic, for_logic]
   ```




-- 
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



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

Posted by GitBox <gi...@apache.org>.
doki23 commented on pull request #1981:
URL: https://github.com/apache/arrow-datafusion/pull/1981#issuecomment-1064628928


   👍🏻 


-- 
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



[GitHub] [arrow-datafusion] yjshen merged pull request #1981: Remove some more unecessary cloning in sql_expr_to_logical_expr

Posted by GitBox <gi...@apache.org>.
yjshen merged pull request #1981:
URL: https://github.com/apache/arrow-datafusion/pull/1981


   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
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



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

Posted by GitBox <gi...@apache.org>.
houqp commented on a change in pull request #1981:
URL: https://github.com/apache/arrow-datafusion/pull/1981#discussion_r824410581



##########
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:
       how about returning a result from the match statement? i.e. something like below:
   
   ```rust
               let args = match (substring_from, substring_for) {
                       (Some(from_expr), Some(for_expr)) => {
                           let from_logic =
                               self.sql_expr_to_logical_expr(*from_expr, schema)?;
                           let for_logic =
                               self.sql_expr_to_logical_expr(*for_expr, schema)?;
                           Ok(vec![arg, from_logic, for_logic])
                       }    
                       (None, None) => {
                               let orig_sql = SQLExpr::Substring {
                                   expr,
                                   substring_from: None,
                                   substring_for: None,
                               };
   
                               Err(DataFusionError::Plan(format!(
                                   "Substring without for/from is not valid {:?}",
                                   orig_sql
                               )))
                       }
               }?;
   ```




-- 
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