yjshen commented on code in PR #5929:
URL: https://github.com/apache/arrow-datafusion/pull/5929#discussion_r1161833875


##########
datafusion/optimizer/src/analyzer/type_coercion.rs:
##########
@@ -999,8 +1000,56 @@ mod test {
         let expected =
             "Projection: CAST(a AS Decimal128(24, 4)) IN ([CAST(Int32(1) AS 
Decimal128(24, 4)), CAST(Int8(4) AS Decimal128(24, 4)), CAST(Int64(8) AS 
Decimal128(24, 4))]) AS a IN (Map { iter: Iter([Int32(1), Int8(4), Int64(8)]) 
})\
              \n  EmptyRelation";
-        assert_analyzed_plan_eq(Arc::new(TypeCoercion::new()), &plan, 
expected)?;
-        Ok(())
+        assert_analyzed_plan_eq(Arc::new(TypeCoercion::new()), &plan, expected)
+    }
+
+    #[test]
+    fn between_case() -> Result<()> {
+        let expr = Expr::Between(Between::new(
+            Box::new(col("a")),
+            false,
+            Box::new(Expr::Literal(Utf8(Some("2002-05-08".to_string())))),
+            // (cast('2002-05-08' as date) + interval '1 months')
+            Box::new(Expr::BinaryExpr(BinaryExpr {
+                left: Box::new(Expr::Cast(Cast {
+                    expr: 
Box::new(Expr::Literal(Utf8(Some("2002-05-08".to_string())))),
+                    data_type: DataType::Date32,
+                })),
+                op: Operator::Plus,
+                right: 
Box::new(Expr::Literal(ScalarValue::IntervalYearMonth(Some(1)))),
+            })),
+        ));
+        let empty = empty_with_type(DataType::Utf8);
+        let plan = LogicalPlan::Filter(Filter::try_new(expr, empty)?);
+        let expected =
+            "Filter: a BETWEEN Utf8(\"2002-05-08\") AND 
CAST(CAST(Utf8(\"2002-05-08\") AS Date32) + IntervalYearMonth(\"1\") AS Utf8)\

Review Comment:
   I suppose we could put the desired coercion as expected. But ignore this 
test case for now and link the issue trying to fix it?
   
   BTW, I checked the temporal coercion rule in Spark and found its default 
coerce to datetime types after its 3.0 version, but left a legacy conf to make 
string vs date to coerce to string type. I agree with you that we should always 
compare using date types.



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