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


##########
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:
   We can't check the type of the `pattern` expression until we have a schema 
to resolve against (it could be a reference to a column or any other type of 
expression).
   
   My goal was to do the validation in the logical plan for the benefit of 
other engines building on DataFusion that don't use the physical plan.
   
   



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