public static Range greaterThan(Type type, Object low) { return new Range(Marker.above(type, low), Marker.upperUnbounded(type)); }
public static Range greaterThanOrEqual(Type type, Object low) { return new Range(Marker.exactly(type, low), Marker.upperUnbounded(type)); }
public static Range lessThan(Type type, Object high) { return new Range(Marker.lowerUnbounded(type), Marker.below(type, high)); }
public static Range all(Type type) { return new Range(Marker.lowerUnbounded(type), Marker.upperUnbounded(type)); }
public static Range lessThanOrEqual(Type type, Object high) { return new Range(Marker.lowerUnbounded(type), Marker.exactly(type, high)); }
public static Range equal(Type type, Object value) { return new Range(Marker.exactly(type, value), Marker.exactly(type, value)); }
@Setup(Level.Iteration) public void init() { ranges = new ArrayList<>(); int factor = 0; for (int i = 0; i < 10000; i++) { long from = ThreadLocalRandom.current().nextLong(100) + factor * 100; long to = ThreadLocalRandom.current().nextLong(100) + (factor + 1) * 100; factor++; ranges.add(new Range(Marker.above(BIGINT, from), Marker.below(BIGINT, to))); } } }
public static Range range(Type type, Object low, boolean lowInclusive, Object high, boolean highInclusive) { Marker lowMarker = lowInclusive ? Marker.exactly(type, low) : Marker.above(type, low); Marker highMarker = highInclusive ? Marker.exactly(type, high) : Marker.below(type, high); return new Range(lowMarker, highMarker); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testLowerUnboundedOnly() { new Range(Marker.lowerUnbounded(BIGINT), Marker.lowerUnbounded(BIGINT)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testLowerUnboundedOnly() { new Range(Marker.lowerUnbounded(BIGINT), Marker.lowerUnbounded(BIGINT)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testUpperUnboundedOnly() { new Range(Marker.upperUnbounded(BIGINT), Marker.upperUnbounded(BIGINT)); }
public Range intersect(Range other) { checkTypeCompatibility(other); if (!this.overlaps(other)) { throw new IllegalArgumentException("Cannot intersect non-overlapping ranges"); } Marker lowMarker = Marker.max(low, other.getLow()); Marker highMarker = Marker.min(high, other.getHigh()); return new Range(lowMarker, highMarker); }
@Setup(Level.Iteration) public void init() { ranges = new ArrayList<>(); int factor = 0; for (int i = 0; i < 10000; i++) { long from = ThreadLocalRandom.current().nextLong(100) + factor * 100; long to = ThreadLocalRandom.current().nextLong(100) + (factor + 1) * 100; factor++; ranges.add(new Range(Marker.above(BIGINT, from), Marker.below(BIGINT, to))); } } }
@Test(expectedExceptions = IllegalArgumentException.class) public void testUpperUnboundedOnly() { new Range(Marker.upperUnbounded(BIGINT), Marker.upperUnbounded(BIGINT)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testInvertedBounds() { new Range(Marker.exactly(BIGINT, 1L), Marker.exactly(BIGINT, 0L)); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testInvertedBounds() { new Range(Marker.exactly(BIGINT, 1L), Marker.exactly(BIGINT, 0L)); }
public Range span(Range other) { checkTypeCompatibility(other); Marker lowMarker = Marker.min(low, other.getLow()); Marker highMarker = Marker.max(high, other.getHigh()); return new Range(lowMarker, highMarker); }
@SuppressWarnings({"unchecked", "rawtypes"}) @Test(expectedExceptions = IllegalArgumentException.class) public void testMismatchedTypes() { // NEVER DO THIS new Range(Marker.exactly(BIGINT, 1L), Marker.exactly(VARCHAR, utf8Slice("a"))); }
@SuppressWarnings({"unchecked", "rawtypes"}) @Test(expectedExceptions = IllegalArgumentException.class) public void testMismatchedTypes() { // NEVER DO THIS new Range(Marker.exactly(BIGINT, 1L), Marker.exactly(VARCHAR, utf8Slice("a"))); }
@Override public SortedRangeSet complement() { Builder builder = new Builder(type); if (lowIndexedRanges.isEmpty()) { return builder.add(Range.all(type)).build(); } Iterator<Range> rangeIterator = lowIndexedRanges.values().iterator(); Range firstRange = rangeIterator.next(); if (!firstRange.getLow().isLowerUnbounded()) { builder.add(new Range(Marker.lowerUnbounded(type), firstRange.getLow().lesserAdjacent())); } Range previousRange = firstRange; while (rangeIterator.hasNext()) { Range currentRange = rangeIterator.next(); Marker lowMarker = previousRange.getHigh().greaterAdjacent(); Marker highMarker = currentRange.getLow().lesserAdjacent(); builder.add(new Range(lowMarker, highMarker)); previousRange = currentRange; } Range lastRange = previousRange; if (!lastRange.getHigh().isUpperUnbounded()) { builder.add(new Range(lastRange.getHigh().greaterAdjacent(), Marker.upperUnbounded(type))); } return builder.build(); }