You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "jackwener (via GitHub)" <gi...@apache.org> on 2023/04/09 09:44:58 UTC

[GitHub] [arrow-datafusion] jackwener opened a new pull request, #5929: test: add Between UT for type_coercion

jackwener opened a new pull request, #5929:
URL: https://github.com/apache/arrow-datafusion/pull/5929

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Related #5928 
   
   # Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are these changes tested?
   
   add UT.
   
   # Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #5929: test: add Between UT for type_coercion

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5929:
URL: https://github.com/apache/arrow-datafusion/pull/5929#discussion_r1163244818


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

Review Comment:
   Follow on https://github.com/apache/arrow-datafusion/pull/5967#



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb merged pull request #5929: test: add Between UT for type_coercion

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #5929:
URL: https://github.com/apache/arrow-datafusion/pull/5929


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] jackwener commented on a diff in pull request #5929: test: add Between UT for type_coercion

Posted by "jackwener (via GitHub)" <gi...@apache.org>.
jackwener commented on code in PR #5929:
URL: https://github.com/apache/arrow-datafusion/pull/5929#discussion_r1161822104


##########
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 think It isn't valid. Current many problem exist in `TypeCoercion`, I'm fixing them one by one.
   BTW, I think I need to research and think about it systematically, not just patching case by 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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] jackwener commented on pull request #5929: test: add Between UT for type_coercion

Posted by "jackwener (via GitHub)" <gi...@apache.org>.
jackwener commented on PR #5929:
URL: https://github.com/apache/arrow-datafusion/pull/5929#issuecomment-1501089779

   We can do some improvement for Type coercion. 
   I have some draft for them. I need some time to think and polish them


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] yjshen commented on a diff in pull request #5929: test: add Between UT for type_coercion

Posted by "yjshen (via GitHub)" <gi...@apache.org>.
yjshen commented on code in PR #5929:
URL: https://github.com/apache/arrow-datafusion/pull/5929#discussion_r1161812483


##########
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:
   Dumb Question: while I was reading temporal coercion rules in https://github.com/apache/arrow-datafusion/blob/main/datafusion/expr/src/type_coercion/binary.rs#L688, I found UTF8 vs Date comparison always yields Date type. Why are we expecting upper bounds to be cast as UTF8?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #5929: test: add Between UT for type_coercion

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5929:
URL: https://github.com/apache/arrow-datafusion/pull/5929#discussion_r1163234285


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

Review Comment:
   It is unfortunate it takes this much code to create a `between` -- I will make a follow on PR to reduce the boiler plate needed



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] yjshen commented on a diff in pull request #5929: test: add Between UT for type_coercion

Posted by "yjshen (via GitHub)" <gi...@apache.org>.
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org