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

[GitHub] [arrow-datafusion] berkaysynnada opened a new pull request, #6007: Open/Closed bounds for interval arithmetic

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

   # 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 #5909.
   
   # 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.  
   -->
   
   Currently, we cannot differentiate `x > y` and `x >= y` while propagating comparison in [constraint propagator/solver](https://github.com/apache/arrow-datafusion/blob/main/datafusion/physical-expr/src/intervals/cp_solver.rs). Also `apply_operator` function that calculates the interval of the target node cannot work with `Operator::GtEq` and `Operator::LtEq`.
   
   # 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.
   -->
   
   The `Interval` struct is modified to store bound variants. Arithmetic ops such as `lt` and `gt` are updated. `lt_eq` and `gt_eq` is added. 
   
   # 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)?
   -->
   
   Yes, both the interval arithmetic and symmetric hash join tests are extended.
   
   # 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 pull request #6007: Open/Closed bounds for interval arithmetic

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

   Thanks -- this is looking very nice 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] alamb commented on a diff in pull request #6007: Open/Closed bounds for interval arithmetic

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


##########
datafusion/physical-expr/src/intervals/interval_aritmetic.rs:
##########
@@ -324,25 +507,24 @@ mod tests {
                 Some(999),
                 Some(1000),
             ),
-            (None, Some(1000), Some(1000), None, Some(1000), Some(1000)), // singleton
             (None, None, None, None, None, None),
         ];
 
         for case in possible_cases {
             assert_eq!(
-                Interval {
-                    lower: ScalarValue::Int64(case.0),
-                    upper: ScalarValue::Int64(case.1)
-                }
-                .intersect(&Interval {
-                    lower: ScalarValue::Int64(case.2),
-                    upper: ScalarValue::Int64(case.3)
-                })?
+                Interval::new(
+                    IntervalBound::new(ScalarValue::Int64(case.0), true),
+                    IntervalBound::new(ScalarValue::Int64(case.1), true),
+                )
+                .intersect(&Interval::new(
+                    IntervalBound::new(ScalarValue::Int64(case.2), true),
+                    IntervalBound::new(ScalarValue::Int64(case.3), true)
+                ))?
                 .unwrap(),
-                Interval {
-                    lower: ScalarValue::Int64(case.4),
-                    upper: ScalarValue::Int64(case.5)
-                }
+                Interval::new(
+                    IntervalBound::new(ScalarValue::Int64(case.4), true),
+                    IntervalBound::new(ScalarValue::Int64(case.5), true),
+                )

Review Comment:
   I can't help thinking while reading this PR that all this repetition obscures somewhat the intent of the test. I wonder if there is some way to write this code like
   
   ```
               assert_eq!(
                   Interval::new(
                     IntervalBound::open(case.0), IntervalBound::open(case.1)
                   )
                   .intersect(&Interval::new(
                     IntervalBound::open(case.2), IntervalBound::open(case.3))
                    )?
                   .unwrap(),
                   Interval::new(
                       IntervalBound::open(case.4),
                       IntervalBound::open(case.5 ),
                   )
   ```
   
   Or maybe even
   
   
   ```
               assert_eq!(
                   Interval::both_open(case.0, case.1)
                   .intersect(&Interval::both_open(case.2, case.3)))?
                   Interval::both_open(case.4, case.5 ),
              )
   ```
   
   Even if you just made a helper for tests, I think reducing the boilder plate would significantly improve the readability of these tests



-- 
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] ozankabak commented on pull request #6007: Open/Closed bounds for interval arithmetic

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

   This is a part of the effort to make the interval library general enough to cover all use cases in the codebase, so that we can unify the impls, as was agreed on with @alamb 


-- 
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] mustafasrepo merged pull request #6007: Open/Closed bounds for interval arithmetic

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


-- 
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] ozankabak commented on a diff in pull request #6007: Open/Closed bounds for interval arithmetic

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


##########
datafusion/physical-expr/src/intervals/interval_aritmetic.rs:
##########
@@ -324,25 +507,24 @@ mod tests {
                 Some(999),
                 Some(1000),
             ),
-            (None, Some(1000), Some(1000), None, Some(1000), Some(1000)), // singleton
             (None, None, None, None, None, None),
         ];
 
         for case in possible_cases {
             assert_eq!(
-                Interval {
-                    lower: ScalarValue::Int64(case.0),
-                    upper: ScalarValue::Int64(case.1)
-                }
-                .intersect(&Interval {
-                    lower: ScalarValue::Int64(case.2),
-                    upper: ScalarValue::Int64(case.3)
-                })?
+                Interval::new(
+                    IntervalBound::new(ScalarValue::Int64(case.0), true),
+                    IntervalBound::new(ScalarValue::Int64(case.1), true),
+                )
+                .intersect(&Interval::new(
+                    IntervalBound::new(ScalarValue::Int64(case.2), true),
+                    IntervalBound::new(ScalarValue::Int64(case.3), true)
+                ))?
                 .unwrap(),
-                Interval {
-                    lower: ScalarValue::Int64(case.4),
-                    upper: ScalarValue::Int64(case.5)
-                }
+                Interval::new(
+                    IntervalBound::new(ScalarValue::Int64(case.4), true),
+                    IntervalBound::new(ScalarValue::Int64(case.5), true),
+                )

Review Comment:
   ```rust
   assert_eq!(
     Interval::both_open(case.0, case.1)
     .intersect(&Interval::both_open(case.2, case.3)))?
     Interval::both_open(case.4, case.5 ),
   )
   ```
   
   I like this idea, let's add convenience functions `open_open`, `open_closed`, `closed_open` and `closed_closed` and use when appropriate (e.g. in tests).



-- 
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] ozankabak commented on pull request #6007: Open/Closed bounds for interval arithmetic

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

   > I suggest leaving the PR open for another day to gather community comments but otherwise I think it is good to merge when you are ready
   
   Will do, thank you @alamb 


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