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/05/01 09:27:27 UTC

[GitHub] [arrow-datafusion] jackwener opened a new pull request, #6177: fix: type coercion ignore Date - Interval

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

   # 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.
   -->
   
   Closes #6176.
   
   # 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?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   # 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] jackwener commented on a diff in pull request #6177: fix: type coercion ignore prevent `Interval - Date`

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


##########
datafusion/expr/src/type_coercion/binary.rs:
##########
@@ -147,16 +150,16 @@ pub fn coerce_types(
         | Operator::IsNotDistinctFrom => comparison_coercion(lhs_type, rhs_type),
         // interval - timestamp is an erroneous case, cannot coerce a type
         Operator::Plus | Operator::Minus
-            if (is_date(lhs_type)
-                || is_date(rhs_type)
-                || is_timestamp(lhs_type)
-                || is_timestamp(rhs_type)
+            if is_datetime(lhs_type)
+                || is_datetime(rhs_type)
                 || is_interval(lhs_type)
-                || is_interval(rhs_type))
-                && (!is_interval(lhs_type)
-                    || !is_timestamp(rhs_type)

Review Comment:
   We must match this condition (interval - date) because it will continue match if we don't match it.
   
   So we should match them, and add judge check.



-- 
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 #6177: fix: type coercion ignore prevent `Interval - Date`

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

   > The thing is, this seems to work fine on main πŸ˜•
   
   I have misunderstand original code, it's used for prevent wrong sql.
   When sql is 
   ```
   select interval '1 month' - '2023-05-01'::timestamp;
   
   select interval '1 month' - '2023-05-01'::date;
   ```
   
   so these code just forgot to prevent  `Interval - Date`


-- 
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 #6177: fix: type coercion ignore Date - Interval

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

   I find more problem, make this PR draft


-- 
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 pull request #6177: fix: type coercion ignore prevent `Interval - Date`

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

   hmm, the tests seems to be failing now


-- 
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 #6177: fix: type coercion ignore prevent `Interval - Date`

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

   > hmm, the tests seems to be failing now
   
   Forgot modify a `!=` into `==`.
   Have fixed it.


-- 
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 #6177: fix: type coercion ignore prevent `Interval - Date`

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


##########
datafusion/core/tests/sqllogictests/test_files/type_coercion.slt:
##########
@@ -29,3 +29,25 @@ query B
 select 's' is not distinct from arrow_cast('s', 'LargeUtf8');
 ----
 true
+
+# date - interval
+query D
+select '2023-05-01'::date - interval '1 month';
+----
+2023-04-01
+
+# timestamp - interval
+query P
+SELECT '2023-05-01 12:30:00'::timestamp - interval '1 month';
+----
+2023-04-01T12:30:00
+
+# TODO: https://github.com/apache/arrow-datafusion/issues/6180
+# interval - date
+query error DataFusion error: This feature is not implemented: Unsupported interval argument\. Expected string literal, got: BinaryOp \{ left: Value\(SingleQuotedString\("1 month"\)\), op: Minus, right: Cast \{ expr: Value\(SingleQuotedString\("2023\-05\-01"\)\), data_type: Date \} \}
+select interval '1 month' - '2023-05-01'::date;
+
+# TODO: https://github.com/apache/arrow-datafusion/issues/6180

Review Comment:
   πŸ‘ 



-- 
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 merged pull request #6177: fix: type coercion ignore prevent `Interval - Date`

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


-- 
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 #6177: fix: type coercion ignore Date - Interval

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


##########
datafusion/core/tests/sqllogictests/test_files/type_coercion.slt:
##########
@@ -29,3 +29,21 @@ query B
 select 's' is not distinct from arrow_cast('s', 'LargeUtf8');
 ----
 true
+
+# date - interval
+query D
+select  '2023-05-01'::date - interval '1 month';
+----
+2023-04-01
+
+# date - interval

Review Comment:
   I copied twiceπŸ₯²



-- 
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 #6177: fix: type coercion ignore prevent `Interval - Date`

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


##########
datafusion/expr/src/type_coercion/binary.rs:
##########
@@ -147,16 +150,16 @@ pub fn coerce_types(
         | Operator::IsNotDistinctFrom => comparison_coercion(lhs_type, rhs_type),
         // interval - timestamp is an erroneous case, cannot coerce a type
         Operator::Plus | Operator::Minus
-            if (is_date(lhs_type)
-                || is_date(rhs_type)
-                || is_timestamp(lhs_type)
-                || is_timestamp(rhs_type)
+            if is_datetime(lhs_type)
+                || is_datetime(rhs_type)
                 || is_interval(lhs_type)
-                || is_interval(rhs_type))
-                && (!is_interval(lhs_type)
-                    || !is_timestamp(rhs_type)

Review Comment:
   We can't match this condition (interval - date) because it will continue match.
   
   So we should match them, and add judge check.



-- 
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 #6177: fix: type coercion ignore Date - Interval

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


##########
datafusion/expr/src/type_coercion/binary.rs:
##########
@@ -147,14 +150,12 @@ pub fn coerce_types(
         | Operator::IsNotDistinctFrom => comparison_coercion(lhs_type, rhs_type),
         // interval - timestamp is an erroneous case, cannot coerce a type
         Operator::Plus | Operator::Minus
-            if (is_date(lhs_type)
-                || is_date(rhs_type)
-                || is_timestamp(lhs_type)
-                || is_timestamp(rhs_type)
+            if (is_datetime(lhs_type)
+                || is_datetime(rhs_type)
                 || is_interval(lhs_type)
                 || is_interval(rhs_type))
                 && (!is_interval(lhs_type)
-                    || !is_timestamp(rhs_type)

Review Comment:
   Here don't consider `DateType`



-- 
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 #6177: fix: type coercion ignore Date - Interval

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


##########
datafusion/core/tests/sqllogictests/test_files/type_coercion.slt:
##########
@@ -29,3 +29,21 @@ query B
 select 's' is not distinct from arrow_cast('s', 'LargeUtf8');
 ----
 true
+
+# date - interval
+query D
+select  '2023-05-01'::date - interval '1 month';
+----
+2023-04-01
+
+# date - interval

Review Comment:
   this seems identical to the test above it (maybe it was supposed to be `date + interval`?)



-- 
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 pull request #6177: fix: type coercion ignore Date - Interval

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

   > Your case forgot interval.
   
   
   The thing is, this seems to work fine on main πŸ˜• 
   
   ```
   DataFusion CLI v23.0.0
   ❯ select  '2023-05-01'::date - interval '1 month';
   +----------------------------------------------------------------------------+
   | Utf8("2023-05-01") - IntervalMonthDayNano("79228162514264337593543950336") |
   +----------------------------------------------------------------------------+
   | 2023-04-01                                                                 |
   +----------------------------------------------------------------------------+
   1 row in set. Query took 0.002 seconds.
   ```


-- 
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 #6177: fix: type coercion ignore Date - Interval

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

   @alamb thanks you.
   
   Your case forgot `interval`.
   
   I have test it.
   ```sql
   ❯ select  '2023-05-01'::date - interval '1 month';
   +----------------------------------------------------------------------------+
   | Utf8("2023-05-01") - IntervalMonthDayNano("79228162514264337593543950336") |
   +----------------------------------------------------------------------------+
   | 2023-04-01                                                                 |
   +----------------------------------------------------------------------------+
   ```


-- 
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 #6177: fix: type coercion ignore prevent `Interval - Date`

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


##########
datafusion/expr/src/type_coercion/binary.rs:
##########
@@ -147,16 +150,16 @@ pub fn coerce_types(
         | Operator::IsNotDistinctFrom => comparison_coercion(lhs_type, rhs_type),
         // interval - timestamp is an erroneous case, cannot coerce a type
         Operator::Plus | Operator::Minus
-            if (is_date(lhs_type)
-                || is_date(rhs_type)
-                || is_timestamp(lhs_type)
-                || is_timestamp(rhs_type)
+            if is_datetime(lhs_type)
+                || is_datetime(rhs_type)
                 || is_interval(lhs_type)
-                || is_interval(rhs_type))
-                && (!is_interval(lhs_type)
-                    || !is_timestamp(rhs_type)

Review Comment:
   We must match this condition (interval - date) because it will continue match if we don't match it.
   
   So we should match them, and add a checker in handler.



-- 
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 #6177: fix: type coercion ignore prevent `Interval - Date`

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


##########
datafusion/expr/src/type_coercion/binary.rs:
##########
@@ -147,16 +150,16 @@ pub fn coerce_types(
         | Operator::IsNotDistinctFrom => comparison_coercion(lhs_type, rhs_type),
         // interval - timestamp is an erroneous case, cannot coerce a type
         Operator::Plus | Operator::Minus
-            if (is_date(lhs_type)
-                || is_date(rhs_type)
-                || is_timestamp(lhs_type)
-                || is_timestamp(rhs_type)
+            if is_datetime(lhs_type)
+                || is_datetime(rhs_type)
                 || is_interval(lhs_type)
-                || is_interval(rhs_type))
-                && (!is_interval(lhs_type)
-                    || !is_timestamp(rhs_type)
-                    || *op != Operator::Minus) =>
+                || is_interval(rhs_type) =>
         {
+            if is_interval(lhs_type) && is_datetime(rhs_type) && *op == Operator::Minus {
+                return Err(DataFusionError::Plan(

Review Comment:
   πŸ‘ 



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