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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]