use of io.trino.spi.predicate.ValueSet in project trino by trinodb.
the class PartitionFilterBuilder method addRanges.
public PartitionFilterBuilder addRanges(String columnName, Range range, Range... ranges) {
ValueSet values = ValueSet.ofRanges(range, ranges);
Domain domain = Domain.create(values, false);
domains.merge(columnName, domain, Domain::union);
return this;
}
use of io.trino.spi.predicate.ValueSet in project trino by trinodb.
the class KafkaFilterManager method filterValuesByDomain.
@VisibleForTesting
public static Set<Long> filterValuesByDomain(Domain domain, Set<Long> sourceValues) {
requireNonNull(sourceValues, "sourceValues is none");
if (domain.isSingleValue()) {
long singleValue = (long) domain.getSingleValue();
return sourceValues.stream().filter(sourceValue -> sourceValue == singleValue).collect(toImmutableSet());
} else {
ValueSet valueSet = domain.getValues();
if (valueSet instanceof SortedRangeSet) {
Ranges ranges = ((SortedRangeSet) valueSet).getRanges();
List<io.trino.spi.predicate.Range> rangeList = ranges.getOrderedRanges();
if (rangeList.stream().allMatch(io.trino.spi.predicate.Range::isSingleValue)) {
return rangeList.stream().map(range -> (Long) range.getSingleValue()).filter(sourceValues::contains).collect(toImmutableSet());
} else {
// still return values for range case like (_partition_id > 1)
io.trino.spi.predicate.Range span = ranges.getSpan();
long low = getLowIncludedValue(span).orElse(0L);
long high = getHighIncludedValue(span).orElse(Long.MAX_VALUE);
return sourceValues.stream().filter(item -> item >= low && item <= high).collect(toImmutableSet());
}
}
}
return sourceValues;
}
use of io.trino.spi.predicate.ValueSet in project trino by trinodb.
the class TestPrometheusSplit method testPredicatePushDownSetsUpperAndLowerBound.
@Test
public void testPredicatePushDownSetsUpperAndLowerBound() {
long predicateHighValue = 1568638171999L;
Range highRange = Range.equal(TIMESTAMP_COLUMN_TYPE, packDateTimeWithZone(predicateHighValue, UTC_KEY));
long predicateLowValue = 1568638171999L - 600000L;
Range lowRange = Range.equal(TIMESTAMP_COLUMN_TYPE, packDateTimeWithZone(predicateLowValue, UTC_KEY));
ValueSet valueSet = ValueSet.ofRanges(lowRange, highRange);
Domain testDomain = Domain.create(valueSet, false);
TupleDomain<ColumnHandle> testTupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(new PrometheusColumnHandle("timestamp", TIMESTAMP_COLUMN_TYPE, 2), testDomain));
PrometheusTableHandle prometheusTableHandle = new PrometheusTableHandle("schemaName", "tableName").withPredicate(testTupleDomain);
io.airlift.units.Duration maxQueryRangeDuration = new io.airlift.units.Duration(120, TimeUnit.SECONDS);
io.airlift.units.Duration queryChunkSizeDuration = new io.airlift.units.Duration(30, TimeUnit.SECONDS);
Instant now = ofEpochMilli(1568638171999L + 1200000L);
List<String> splitTimes = PrometheusSplitManager.generateTimesForSplits(now, maxQueryRangeDuration, queryChunkSizeDuration, prometheusTableHandle);
TemporalAmount expectedMaxQueryAsTime = java.time.Duration.ofMillis(new io.airlift.units.Duration(10, TimeUnit.MINUTES).toMillis() + ((splitTimes.size() - 1) * OFFSET_MILLIS));
String lastSplit = splitTimes.get(splitTimes.size() - 1);
Instant lastSplitAsTime = ofEpochMilli(longFromDecimalSecondString(lastSplit));
String earliestSplit = splitTimes.get(0);
Instant earliestSplitAsTime = ofEpochMilli(longFromDecimalSecondString(earliestSplit));
TemporalAmount queryChunkAsTime = java.time.Duration.ofMillis(queryChunkSizeDuration.toMillis());
java.time.Duration actualMaxDuration = Duration.between(earliestSplitAsTime.minus(queryChunkAsTime), lastSplitAsTime);
assertEquals(lastSplitAsTime.toEpochMilli(), 1568638171999L);
assertEquals(actualMaxDuration, expectedMaxQueryAsTime);
}
use of io.trino.spi.predicate.ValueSet in project trino by trinodb.
the class TestPrometheusSplit method testPredicatePushDownLowerBoundDirect.
@Test
public void testPredicatePushDownLowerBoundDirect() {
Range lowRange = Range.greaterThanOrEqual(TIMESTAMP_COLUMN_TYPE, packDateTimeWithZone(1570460709643L, UTC_KEY));
ValueSet valueSet = ValueSet.ofRanges(lowRange);
Domain testDomain = Domain.create(valueSet, false);
TupleDomain<ColumnHandle> testTupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(new PrometheusColumnHandle("timestamp", TIMESTAMP_COLUMN_TYPE, 2), testDomain));
PrometheusPredicateTimeInfo predicateTimes = PrometheusSplitManager.determinePredicateTimes(testTupleDomain).orElseThrow();
Instant expected = ofEpochMilli(1570460709643L);
assertEquals(predicateTimes.getPredicateLowerTimeBound().orElseThrow(), expected);
}
use of io.trino.spi.predicate.ValueSet in project trino by trinodb.
the class TestPrometheusSplit method testPredicatePushDownSetsLowerBoundOnly.
@Test(enabled = false)
public void testPredicatePushDownSetsLowerBoundOnly() {
long predicateLowValue = 1568638171999L - 600000L;
Range lowRange = Range.greaterThanOrEqual(TIMESTAMP_COLUMN_TYPE, packDateTimeWithZone(predicateLowValue, UTC_KEY));
ValueSet valueSet = ValueSet.ofRanges(lowRange);
Domain testDomain = Domain.create(valueSet, false);
TupleDomain<ColumnHandle> testTupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(new PrometheusColumnHandle("timestamp", TIMESTAMP_COLUMN_TYPE, 2), testDomain));
PrometheusTableHandle prometheusTableHandle = new PrometheusTableHandle("schemaName", "tableName").withPredicate(testTupleDomain);
io.airlift.units.Duration maxQueryRangeDuration = new io.airlift.units.Duration(120, TimeUnit.SECONDS);
io.airlift.units.Duration queryChunkSizeDuration = new io.airlift.units.Duration(30, TimeUnit.SECONDS);
Instant now = ofEpochMilli(1568638171999L);
TemporalAmount maxQueryAsTime = java.time.Duration.ofMillis(maxQueryRangeDuration.toMillis());
List<String> splitTimes = PrometheusSplitManager.generateTimesForSplits(now, maxQueryRangeDuration, queryChunkSizeDuration, prometheusTableHandle);
String earliestSplit = splitTimes.get(0);
Instant earliestSplitAsTime = ofEpochMilli(longFromDecimalSecondString(earliestSplit));
TemporalAmount queryChunkAsTime = java.time.Duration.ofMillis(queryChunkSizeDuration.toMillis());
Instant startOfQuery = earliestSplitAsTime.minus(queryChunkAsTime);
assertNotEquals(startOfQuery, now.minus(maxQueryAsTime).minus(java.time.Duration.ofMillis((splitTimes.size() - 1) * OFFSET_MILLIS)));
assertEquals(startOfQuery.toEpochMilli(), ofEpochMilli(predicateLowValue).toEpochMilli() - ((splitTimes.size() - 1) * OFFSET_MILLIS));
}
Aggregations