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

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #6007: Open/Closed bounds for interval arithmetic

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