liyafan82 commented on a change in pull request #2124:
URL: https://github.com/apache/calcite/pull/2124#discussion_r480647558
##########
File path: core/src/main/java/org/apache/calcite/util/RangeSets.java
##########
@@ -43,4 +49,384 @@ private RangeSets() {}
public static <C extends Comparable<C>> RangeSet<C> rangeSetAll() {
return (RangeSet) ALL;
}
+
+ /** Compares two range sets. */
+ public static <C extends Comparable<C>> int compare(RangeSet<C> s0,
+ RangeSet<C> s1) {
+ final Iterator<Range<C>> i0 = s0.asRanges().iterator();
+ final Iterator<Range<C>> i1 = s1.asRanges().iterator();
+ for (;;) {
+ final boolean h0 = i0.hasNext();
+ final boolean h1 = i1.hasNext();
+ if (!h0 || !h1) {
+ return Boolean.compare(h0, h1);
+ }
+ final Range<C> r0 = i0.next();
+ final Range<C> r1 = i1.next();
+ int c = compare(r0, r1);
+ if (c != 0) {
+ return c;
+ }
+ }
+ }
+
+ /** Compares two ranges. */
+ public static <C extends Comparable<C>> int compare(Range<C> r0,
+ Range<C> r1) {
+ int c = Boolean.compare(r0.hasLowerBound(), r1.hasLowerBound());
+ if (c != 0) {
+ return c;
+ }
+ if (r0.hasLowerBound()) {
+ c = r0.lowerEndpoint().compareTo(r1.lowerEndpoint());
Review comment:
Here we are making comparison without normalizing the bound type.
It still makes a total order, but it may not be compatible with the
"natural" order.
For example, integer range (5, 10) will be smaller than [6, 8) according to
this implementation. However, (5, 10) can be normalized to [6, 10), which is
greater than [6, 8) according to "natural" order.
This inconsistency could cause some practical problems?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]