alamb commented on code in PR #3101:
URL: https://github.com/apache/arrow-datafusion/pull/3101#discussion_r966414469


##########
datafusion/sql/src/planner.rs:
##########
@@ -1939,30 +1939,31 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             }
 
             SQLExpr::Like { negated, expr, pattern, escape_char } => {
-                match escape_char {
-                    Some(_) => {
-                        // to support this we will need to introduce 
`Expr::Like` instead
-                        // of treating it like a binary expression
-                        Err(DataFusionError::NotImplemented("LIKE with ESCAPE 
is not yet supported".to_string()))
-                    },
-                    _ => {
-                        Ok(Expr::BinaryExpr {
-                            left: 
Box::new(self.sql_expr_to_logical_expr(*expr, schema, ctes)?),
-                            op: if negated { Operator::NotLike } else { 
Operator::Like },
-                            right: 
Box::new(self.sql_expr_to_logical_expr(*pattern, schema, ctes)?),
-                        })
-                    }
-                }
+                Ok(Expr::Like {
+                    negated,
+                    expr: Box::new(self.sql_expr_to_logical_expr(*expr, 
schema, ctes)?),

Review Comment:
   ❤️ 



##########
datafusion/optimizer/src/type_coercion.rs:
##########
@@ -86,29 +87,45 @@ impl ExprRewriter for TypeCoercionRewriter {
     }
 
     fn mutate(&mut self, expr: Expr) -> Result<Expr> {
-        match expr {
+        match &expr {
             Expr::BinaryExpr { left, op, right } => {
                 let left_type = left.get_type(&self.schema)?;
                 let right_type = right.get_type(&self.schema)?;
-                let coerced_type = coerce_types(&left_type, &op, &right_type)?;
+                let coerced_type = coerce_types(&left_type, op, &right_type)?;
                 Ok(Expr::BinaryExpr {
-                    left: Box::new(left.cast_to(&coerced_type, &self.schema)?),
-                    op,
-                    right: Box::new(right.cast_to(&coerced_type, 
&self.schema)?),
+                    left: Box::new(
+                        left.as_ref().clone().cast_to(&coerced_type, 
&self.schema)?,
+                    ),
+                    op: *op,
+                    right: Box::new(
+                        right
+                            .as_ref()
+                            .clone()
+                            .cast_to(&coerced_type, &self.schema)?,
+                    ),
                 })
             }
+            Expr::Like { pattern, .. }
+            | Expr::ILike { pattern, .. }
+            | Expr::SimilarTo { pattern, .. } => match 
pattern.get_type(&self.schema)? {

Review Comment:
   This seems like the wrong place to be type checking the argument to 
`Expr::Like`, etc. as the argument types to other exprs are checked so why 
would we treat `Expr::Like` differently?
   
   I would expect that to be done in the SQL planner perhaps? or in the 
physical_expr conversion? 



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

Reply via email to