Refine search
/** * Adjacency is defined by two Markers being infinitesimally close to each other. * This means they must share the same value and have adjacent Bounds. */ public boolean isAdjacent(Marker other) { checkTypeCompatibility(other); if (isUpperUnbounded() || isLowerUnbounded() || other.isUpperUnbounded() || other.isLowerUnbounded()) { return false; } if (type.compareTo(valueBlock.get(), 0, other.valueBlock.get(), 0) != 0) { return false; } return (bound == Bound.EXACTLY && other.bound != Bound.EXACTLY) || (bound != Bound.EXACTLY && other.bound == Bound.EXACTLY); }
public boolean isAll() { return low.isLowerUnbounded() && high.isUpperUnbounded(); }
private static boolean isBetween(Range range) { return !range.getLow().isLowerUnbounded() && range.getLow().getBound() == Marker.Bound.EXACTLY && !range.getHigh().isUpperUnbounded() && range.getHigh().getBound() == Marker.Bound.EXACTLY; }
public static PrestoThriftMarker fromMarker(Marker marker) { PrestoThriftBlock value = marker.getValueBlock().isPresent() ? fromBlock(marker.getValueBlock().get(), marker.getType()) : null; return new PrestoThriftMarker(value, fromBound(marker.getBound())); } }
if (domains.isPresent()) { Map<ColumnHandle, Domain> columnHandleDomainMap = domains.get(); for (Map.Entry<ColumnHandle, Domain> entry : columnHandleDomainMap.entrySet()) { if (entry.getKey() instanceof EthereumColumnHandle || ((EthereumColumnHandle) entry.getKey()).getName().equals("erc20_blockNumber"))) { entry.getValue().getValues().getRanges().getOrderedRanges().forEach(r -> { Marker low = r.getLow(); Marker high = r.getHigh(); builder.add(EthereumBlockRange.fromMarkers(low, high)); }); entry.getValue().getValues().getRanges().getOrderedRanges().stream() .filter(Range::isSingleValue).forEach(r -> { String blockHash = ((Slice) r.getSingleValue()).toStringUtf8(); try { long blockNumber = web3j.ethGetBlockByHash(blockHash, true).send().getBlock().getNumber().longValue(); Marker high = r.getHigh(); try { long startBlock = low.isLowerUnbounded() ? 1L : findBlockByTimestamp((Long) low.getValue(), -1L); long endBlock = high.isUpperUnbounded() ? -1L : findBlockByTimestamp((Long) high.getValue(), 1L); builder.add(new EthereumBlockRange(startBlock, endBlock));
for (TupleDomain.ColumnDomain<ColumnHandle> columnDomain : constraintSummary.getColumnDomains().get()) { int position = ((KuduColumnHandle) columnDomain.getColumn()).getOrdinalPosition(); ColumnSchema columnSchema = schema.getColumnByIndex(position); Ranges ranges = ((SortedRangeSet) valueSet).getRanges(); Range span = ranges.getSpan(); Marker low = span.getLow(); if (!low.isLowerUnbounded()) { KuduPredicate.ComparisonOp op = (low.getBound() == Marker.Bound.ABOVE) ? KuduPredicate.ComparisonOp.GREATER : KuduPredicate.ComparisonOp.GREATER_EQUAL; KuduPredicate predicate = createComparisonPredicate(columnSchema, op, low.getValue()); builder.addPredicate(predicate); Marker high = span.getHigh(); if (!high.isUpperUnbounded()) { KuduPredicate.ComparisonOp op = (low.getBound() == Marker.Bound.BELOW) ? KuduPredicate.ComparisonOp.LESS : KuduPredicate.ComparisonOp.LESS_EQUAL; KuduPredicate predicate = createComparisonPredicate(columnSchema, op, high.getValue()); builder.addPredicate(predicate);
private static OptionalInt extractUpperBound(TupleDomain<Symbol> tupleDomain, Symbol symbol) { if (tupleDomain.isNone()) { return OptionalInt.empty(); } Domain rowNumberDomain = tupleDomain.getDomains().get().get(symbol); if (rowNumberDomain == null) { return OptionalInt.empty(); } ValueSet values = rowNumberDomain.getValues(); if (values.isAll() || values.isNone() || values.getRanges().getRangeCount() <= 0) { return OptionalInt.empty(); } Range span = values.getRanges().getSpan(); if (span.getHigh().isUpperUnbounded()) { return OptionalInt.empty(); } verify(rowNumberDomain.getType().equals(BIGINT)); long upperBound = (Long) span.getHigh().getValue(); if (span.getHigh().getBound() == BELOW) { upperBound--; } if (upperBound > 0 && upperBound <= Integer.MAX_VALUE) { return OptionalInt.of(toIntExact(upperBound)); } return OptionalInt.empty(); }
@Test public void testUnbounded() { assertTrue(Marker.lowerUnbounded(BIGINT).isLowerUnbounded()); assertFalse(Marker.lowerUnbounded(BIGINT).isUpperUnbounded()); assertTrue(Marker.upperUnbounded(BIGINT).isUpperUnbounded()); assertFalse(Marker.upperUnbounded(BIGINT).isLowerUnbounded()); assertFalse(Marker.below(BIGINT, 1L).isLowerUnbounded()); assertFalse(Marker.below(BIGINT, 1L).isUpperUnbounded()); assertFalse(Marker.exactly(BIGINT, 1L).isLowerUnbounded()); assertFalse(Marker.exactly(BIGINT, 1L).isUpperUnbounded()); assertFalse(Marker.above(BIGINT, 1L).isLowerUnbounded()); assertFalse(Marker.above(BIGINT, 1L).isUpperUnbounded()); }
@Test public void testTypes() { assertEquals(Marker.lowerUnbounded(BIGINT).getType(), BIGINT); assertEquals(Marker.below(BIGINT, 1L).getType(), BIGINT); assertEquals(Marker.exactly(BIGINT, 1L).getType(), BIGINT); assertEquals(Marker.above(BIGINT, 1L).getType(), BIGINT); assertEquals(Marker.upperUnbounded(BIGINT).getType(), BIGINT); }
if (prestoRange.isAll()) { accumuloRange = new Range(); else if (prestoRange.isSingleValue()) { Text split = new Text(serializer.encode(prestoRange.getType(), prestoRange.getSingleValue())); accumuloRange = new Range(split); if (prestoRange.getLow().isLowerUnbounded()) { boolean inclusive = prestoRange.getHigh().getBound() == Bound.EXACTLY; Text split = new Text(serializer.encode(prestoRange.getType(), prestoRange.getHigh().getValue())); accumuloRange = new Range(null, false, split, inclusive); else if (prestoRange.getHigh().isUpperUnbounded()) { 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())); boolean endKeyInclusive = prestoRange.getHigh().getBound() == Bound.EXACTLY; Text endSplit = new Text(serializer.encode(prestoRange.getType(), prestoRange.getHigh().getValue())); accumuloRange = new Range(startSplit, startKeyInclusive, endSplit, endKeyInclusive);
@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(); }
public String toString(ConnectorSession session) { StringBuilder buffer = new StringBuilder(); if (isSingleValue()) { buffer.append('[').append(low.getPrintableValue(session)).append(']'); } else { buffer.append((low.getBound() == Marker.Bound.EXACTLY) ? '[' : '('); buffer.append(low.isLowerUnbounded() ? "<min>" : low.getPrintableValue(session)); buffer.append(", "); buffer.append(high.isUpperUnbounded() ? "<max>" : high.getPrintableValue(session)); buffer.append((high.getBound() == Marker.Bound.EXACTLY) ? ']' : ')'); } return buffer.toString(); } }
public static EthereumBlockRange fromMarkers(Marker low, Marker high) { long startBlock; long endBlock; if (low.isLowerUnbounded()) { startBlock = 1L; } else if (low.getBound() == Marker.Bound.EXACTLY) { startBlock = (long) low.getValue(); } else if (low.getBound() == Marker.Bound.ABOVE) { startBlock = (long) low.getValue() + 1L; } else { throw new IllegalArgumentException("Low bound cannot be BELOW"); } if (high.isUpperUnbounded()) { endBlock = -1L; } else if (high.getBound() == Marker.Bound.EXACTLY) { endBlock = (long) high.getValue(); } else if (high.getBound() == Marker.Bound.BELOW) { endBlock = (long) high.getValue() - 1L; } else { throw new IllegalArgumentException("High bound cannot be ABOVE"); } if (startBlock > endBlock && endBlock != -1L) { throw new IllegalArgumentException("Low bound is greater than high bound"); } return new EthereumBlockRange(startBlock, endBlock); }
public String toString(ConnectorSession session) { StringBuilder buffer = new StringBuilder("{"); buffer.append("type=").append(type); buffer.append(", value="); if (isLowerUnbounded()) { buffer.append("<min>"); } else if (isUpperUnbounded()) { buffer.append("<max>"); } else { buffer.append(getPrintableValue(session)); } buffer.append(", bound=").append(bound); buffer.append("}"); return buffer.toString(); } }
public Object getSingleValue() { if (!isSingleValue()) { throw new IllegalStateException("Range does not have just a single value"); } return low.getValue(); }
@JsonCreator public Range( @JsonProperty("low") Marker low, @JsonProperty("high") Marker high) { requireNonNull(low, "value is null"); requireNonNull(high, "value is null"); if (!low.getType().equals(high.getType())) { throw new IllegalArgumentException(String.format("Marker types do not match: %s vs %s", low.getType(), high.getType())); } if (low.getBound() == Marker.Bound.BELOW) { throw new IllegalArgumentException("low bound must be EXACTLY or ABOVE"); } if (high.getBound() == Marker.Bound.ABOVE) { throw new IllegalArgumentException("high bound must be EXACTLY or BELOW"); } if (low.compareTo(high) > 0) { throw new IllegalArgumentException("low must be less than or equal to high"); } this.low = low; this.high = high; }