waynexia commented on code in PR #5932:
URL: https://github.com/apache/arrow-datafusion/pull/5932#discussion_r1162269728


##########
datafusion/optimizer/src/analyzer/type_coercion.rs:
##########
@@ -242,20 +242,19 @@ impl TreeNodeRewriter for TypeCoercionRewriter {
                 op,
                 ref right,
             }) => {
+                // this is a workaround for 
https://github.com/apache/arrow-datafusion/issues/3419
                 let left_type = left.get_type(&self.schema)?;
                 let right_type = right.get_type(&self.schema)?;
                 match (&left_type, &right_type) {
+                    // Handle some case about Interval.
                     (
                         DataType::Date32 | DataType::Date64 | 
DataType::Timestamp(_, _),
                         &DataType::Interval(_),
-                    )
-                    | (
+                    ) if matches!(op, Operator::Plus | Operator::Minus) => 
Ok(expr),
+                    (
                         &DataType::Interval(_),
                         DataType::Date32 | DataType::Date64 | 
DataType::Timestamp(_, _),
-                    ) => {
-                        // this is a workaround for 
https://github.com/apache/arrow-datafusion/issues/3419
-                        Ok(expr.clone())
-                    }
+                    ) if matches!(op, Operator::Plus) => Ok(expr),

Review Comment:
   👍 good catch



##########
datafusion/expr/src/type_coercion/binary.rs:
##########
@@ -276,18 +280,16 @@ fn handle_timestamp_minus(lhs: &DataType, rhs: &DataType) 
-> Result<Option<DataT
         | (
             DataType::Timestamp(TimeUnit::Millisecond, _),
             DataType::Timestamp(TimeUnit::Millisecond, _),
-        ) => Ok(Some(DataType::Interval(IntervalUnit::DayTime))),
+        ) => Some(DataType::Interval(IntervalUnit::DayTime)),
         (
             DataType::Timestamp(TimeUnit::Microsecond, _),
             DataType::Timestamp(TimeUnit::Microsecond, _),
         )
         | (
             DataType::Timestamp(TimeUnit::Nanosecond, _),
             DataType::Timestamp(TimeUnit::Nanosecond, _),
-        ) => Ok(Some(DataType::Interval(IntervalUnit::MonthDayNano))),
-        (_, _) => Err(DataFusionError::Plan(
-            "The timestamps have different types".to_string(),
-        )),
+        ) => Some(DataType::Interval(IntervalUnit::MonthDayNano)),
+        (_, _) => None,

Review Comment:
   To my understanding this is only "not supported yet", right? Or did I miss 
something as the function comment says this is an invalid case 



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