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


##########
datafusion/optimizer/src/type_coercion.rs:
##########
@@ -87,14 +89,51 @@ impl ExprRewriter for TypeCoercionRewriter {
 
     fn mutate(&mut self, expr: Expr) -> Result<Expr> {
         match expr {
-            Expr::BinaryExpr { left, op, right } => {
+            Expr::BinaryExpr {
+                ref left,
+                op,
+                ref 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)?;
-                Ok(Expr::BinaryExpr {
-                    left: Box::new(left.cast_to(&coerced_type, &self.schema)?),
-                    op,
-                    right: Box::new(right.cast_to(&coerced_type, 
&self.schema)?),
+                match (&left_type, &right_type) {
+                    (
+                        DataType::Date32 | DataType::Date64 | 
DataType::Timestamp(_, _),
+                        &DataType::Interval(_),
+                    ) => {
+                        // Arrow `can_cast_types` says we cannot cast an 
Interval to
+                        // Date32/Date64/Timestamp, which contradicts 
DataFusion's `coerce_types`
+                        Ok(expr.clone())
+                    }
+                    _ => {
+                        let coerced_type = coerce_types(&left_type, &op, 
&right_type)?;
+                        Ok(Expr::BinaryExpr {
+                            left: Box::new(
+                                left.clone().cast_to(&coerced_type, 
&self.schema)?,
+                            ),
+                            op,
+                            right: Box::new(
+                                right.clone().cast_to(&coerced_type, 
&self.schema)?,
+                            ),
+                        })
+                    }
+                }
+            }
+            Expr::Between {
+                expr,
+                negated,
+                low,
+                high,
+            } => {
+                let expr_type = expr.get_type(&self.schema)?;
+                let low_type = low.get_type(&self.schema)?;
+                let coerced_type = comparison_coercion(&expr_type, &low_type)
+                    .ok_or_else(|| DataFusionError::Internal("".to_string()))?;

Review Comment:
   oops .. forgot to go back and finish this. I have pushed a fix.



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