SortedRangeSet build() { Collections.sort(ranges, Comparator.comparing(Range::getLow)); NavigableMap<Marker, Range> result = new TreeMap<>(); Range current = null; for (Range next : ranges) { if (current == null) { current = next; continue; } if (current.overlaps(next) || current.getHigh().isAdjacent(next.getLow())) { current = current.span(next); } else { result.put(current.getLow(), current); current = next; } } if (current != null) { result.put(current.getLow(), current); } return new SortedRangeSet(type, result); } }
private FormattedDomain parseDomain(Domain domain) { ImmutableSet.Builder<FormattedRange> formattedRanges = ImmutableSet.builder(); Type type = domain.getType(); domain.getValues().getValuesProcessor().consume( ranges -> formattedRanges.addAll( ranges.getOrderedRanges().stream() .map(range -> new FormattedRange(formatMarker(range.getLow()), formatMarker(range.getHigh()))) .collect(toImmutableSet())), discreteValues -> formattedRanges.addAll( discreteValues.getValues().stream() .map(value -> getVarcharValue(type, value)) .map(value -> new FormattedMarker(Optional.of(value), EXACTLY)) .map(marker -> new FormattedRange(marker, marker)) .collect(toImmutableSet())), allOrNone -> { throw new IllegalStateException("Unreachable AllOrNone consumer"); }); return new FormattedDomain(domain.isNullAllowed(), formattedRanges.build()); }
public static PrestoThriftRange fromRange(Range range) { return new PrestoThriftRange(fromMarker(range.getLow()), fromMarker(range.getHigh())); } }
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); }
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); }
return new BetweenPredicate(reference, literalEncoder.toExpression(range.getLow().getValue(), type), literalEncoder.toExpression(range.getHigh().getValue(), type)); if (!range.getLow().isLowerUnbounded()) { switch (range.getLow().getBound()) { case ABOVE: rangeConjuncts.add(new ComparisonExpression(GREATER_THAN, reference, literalEncoder.toExpression(range.getLow().getValue(), type))); break; case EXACTLY: rangeConjuncts.add(new ComparisonExpression(GREATER_THAN_OR_EQUAL, reference, literalEncoder.toExpression(range.getLow().getValue(), type))); break; throw new IllegalStateException("Low Marker should never use BELOW bound: " + range); default: throw new AssertionError("Unhandled bound: " + range.getLow().getBound());
@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(); }
if (prestoRange.getLow().isLowerUnbounded()) { boolean inclusive = prestoRange.getLow().getBound() == Bound.EXACTLY; Text split = new Text(serializer.encode(prestoRange.getType(), prestoRange.getLow().getValue())); accumuloRange = new Range(split, inclusive, null, false); boolean startKeyInclusive = prestoRange.getLow().getBound() == Bound.EXACTLY; Text startSplit = new Text(serializer.encode(prestoRange.getType(), prestoRange.getLow().getValue()));
checkState(!range.isAll(), "Invalid range for column: " + columnName); if (range.isSingleValue()) { valuesToInclude.add(range.getLow().getValue()); if (!range.getLow().isLowerUnbounded()) { switch (range.getLow().getBound()) { case ABOVE: rangeQueryBuilder.must(new RangeQueryBuilder(columnName).gt(getValue(type, range.getLow().getValue()))); break; case EXACTLY: rangeQueryBuilder.must(new RangeQueryBuilder(columnName).gte(getValue(type, range.getLow().getValue()))); break; case BELOW: throw new IllegalArgumentException("Low marker should never use BELOW bound"); default: throw new AssertionError("Unhandled bound: " + range.getLow().getBound());
@Test public void testGreaterThanRange() { Range range = Range.greaterThan(BIGINT, 1L); assertEquals(range.getLow(), Marker.above(BIGINT, 1L)); assertEquals(range.getHigh(), Marker.upperUnbounded(BIGINT)); assertFalse(range.isSingleValue()); assertFalse(range.isAll()); assertEquals(range.getType(), BIGINT); assertFalse(range.includes(Marker.lowerUnbounded(BIGINT))); assertFalse(range.includes(Marker.exactly(BIGINT, 1L))); assertTrue(range.includes(Marker.exactly(BIGINT, 2L))); assertTrue(range.includes(Marker.upperUnbounded(BIGINT))); }
@Test public void testLessThanRange() { Range range = Range.lessThan(BIGINT, 1L); assertEquals(range.getLow(), Marker.lowerUnbounded(BIGINT)); assertEquals(range.getHigh(), Marker.below(BIGINT, 1L)); assertFalse(range.isSingleValue()); assertFalse(range.isAll()); assertEquals(range.getType(), BIGINT); assertTrue(range.includes(Marker.lowerUnbounded(BIGINT))); assertFalse(range.includes(Marker.exactly(BIGINT, 1L))); assertTrue(range.includes(Marker.exactly(BIGINT, 0L))); assertFalse(range.includes(Marker.upperUnbounded(BIGINT))); }
@Test public void testAllRange() { Range range = Range.all(BIGINT); assertEquals(range.getLow(), Marker.lowerUnbounded(BIGINT)); assertEquals(range.getHigh(), Marker.upperUnbounded(BIGINT)); assertFalse(range.isSingleValue()); assertTrue(range.isAll()); assertEquals(range.getType(), BIGINT); assertTrue(range.includes(Marker.lowerUnbounded(BIGINT))); assertTrue(range.includes(Marker.below(BIGINT, 1L))); assertTrue(range.includes(Marker.exactly(BIGINT, 1L))); assertTrue(range.includes(Marker.above(BIGINT, 1L))); assertTrue(range.includes(Marker.upperUnbounded(BIGINT))); }
@Test public void testGreaterThanOrEqualRange() { Range range = Range.greaterThanOrEqual(BIGINT, 1L); assertEquals(range.getLow(), Marker.exactly(BIGINT, 1L)); assertEquals(range.getHigh(), Marker.upperUnbounded(BIGINT)); assertFalse(range.isSingleValue()); assertFalse(range.isAll()); assertEquals(range.getType(), BIGINT); assertFalse(range.includes(Marker.lowerUnbounded(BIGINT))); assertFalse(range.includes(Marker.exactly(BIGINT, 0L))); assertTrue(range.includes(Marker.exactly(BIGINT, 1L))); assertTrue(range.includes(Marker.exactly(BIGINT, 2L))); assertTrue(range.includes(Marker.upperUnbounded(BIGINT))); }
@Test public void testEqualRange() { Range range = Range.equal(BIGINT, 1L); assertEquals(range.getLow(), Marker.exactly(BIGINT, 1L)); assertEquals(range.getHigh(), Marker.exactly(BIGINT, 1L)); assertTrue(range.isSingleValue()); assertFalse(range.isAll()); assertEquals(range.getType(), BIGINT); assertFalse(range.includes(Marker.lowerUnbounded(BIGINT))); assertFalse(range.includes(Marker.exactly(BIGINT, 0L))); assertTrue(range.includes(Marker.exactly(BIGINT, 1L))); assertFalse(range.includes(Marker.exactly(BIGINT, 2L))); assertFalse(range.includes(Marker.upperUnbounded(BIGINT))); }
@Test public void testLessThanOrEqualRange() { Range range = Range.lessThanOrEqual(BIGINT, 1L); assertEquals(range.getLow(), Marker.lowerUnbounded(BIGINT)); assertEquals(range.getHigh(), Marker.exactly(BIGINT, 1L)); assertFalse(range.isSingleValue()); assertFalse(range.isAll()); assertEquals(range.getType(), BIGINT); assertTrue(range.includes(Marker.lowerUnbounded(BIGINT))); assertFalse(range.includes(Marker.exactly(BIGINT, 2L))); assertTrue(range.includes(Marker.exactly(BIGINT, 1L))); assertTrue(range.includes(Marker.exactly(BIGINT, 0L))); assertFalse(range.includes(Marker.upperUnbounded(BIGINT))); }
@Test public void testRange() { Range range = Range.range(BIGINT, 0L, false, 2L, true); assertEquals(range.getLow(), Marker.above(BIGINT, 0L)); assertEquals(range.getHigh(), Marker.exactly(BIGINT, 2L)); assertFalse(range.isSingleValue()); assertFalse(range.isAll()); assertEquals(range.getType(), BIGINT); assertFalse(range.includes(Marker.lowerUnbounded(BIGINT))); assertFalse(range.includes(Marker.exactly(BIGINT, 0L))); assertTrue(range.includes(Marker.exactly(BIGINT, 1L))); assertTrue(range.includes(Marker.exactly(BIGINT, 2L))); assertFalse(range.includes(Marker.exactly(BIGINT, 3L))); assertFalse(range.includes(Marker.upperUnbounded(BIGINT))); }