use of com.facebook.presto.spi.predicate.TupleDomain in project presto by prestodb.
the class TupleDomainParquetPredicate method matches.
@Override
public boolean matches(long numberOfRows, Map<Integer, Statistics<?>> statisticsByColumnIndex) {
if (numberOfRows == 0) {
return false;
}
ImmutableMap.Builder<C, Domain> domains = ImmutableMap.builder();
for (ColumnReference<C> columnReference : columnReferences) {
Statistics<?> statistics = statisticsByColumnIndex.get(columnReference.getOrdinal());
Domain domain;
if (statistics == null || statistics.isEmpty()) {
// no stats for column
domain = Domain.all(columnReference.getType());
} else {
domain = getDomain(columnReference.getType(), numberOfRows, statistics);
}
domains.put(columnReference.getColumn(), domain);
}
TupleDomain<C> stripeDomain = TupleDomain.withColumnDomains(domains.build());
return effectivePredicate.overlaps(stripeDomain);
}
use of com.facebook.presto.spi.predicate.TupleDomain in project presto by prestodb.
the class TupleDomainParquetPredicate method matches.
@Override
public boolean matches(Map<Integer, ParquetDictionaryDescriptor> dictionariesByColumnIndex) {
ImmutableMap.Builder<C, Domain> domains = ImmutableMap.builder();
for (ColumnReference<C> columnReference : columnReferences) {
ParquetDictionaryDescriptor dictionaryDescriptor = dictionariesByColumnIndex.get(columnReference.getOrdinal());
Domain domain = getDomain(columnReference.getType(), dictionaryDescriptor);
if (domain != null) {
domains.put(columnReference.getColumn(), domain);
}
}
TupleDomain<C> stripeDomain = TupleDomain.withColumnDomains(domains.build());
return effectivePredicate.overlaps(stripeDomain);
}
use of com.facebook.presto.spi.predicate.TupleDomain in project presto by prestodb.
the class TableScanMatcher method domainMatches.
private boolean domainMatches(TableScanNode tableScanNode, Session session, Metadata metadata) {
if (!expectedConstraint.isPresent()) {
return true;
}
TupleDomain<ColumnHandle> actualConstraint = tableScanNode.getCurrentConstraint();
if (expectedConstraint.isPresent() && !actualConstraint.getDomains().isPresent()) {
return false;
}
Map<String, ColumnHandle> columnHandles = metadata.getColumnHandles(session, tableScanNode.getTable());
for (Map.Entry<String, Domain> expectedColumnConstraint : expectedConstraint.get().entrySet()) {
if (!columnHandles.containsKey(expectedColumnConstraint.getKey())) {
return false;
}
ColumnHandle columnHandle = columnHandles.get(expectedColumnConstraint.getKey());
if (!actualConstraint.getDomains().get().containsKey(columnHandle)) {
return false;
}
if (!expectedColumnConstraint.getValue().contains(actualConstraint.getDomains().get().get(columnHandle))) {
return false;
}
}
return true;
}
use of com.facebook.presto.spi.predicate.TupleDomain in project presto by prestodb.
the class TestDomainTranslator method testInOptimization.
@Test
public void testInOptimization() throws Exception {
Domain testDomain = Domain.create(ValueSet.all(BIGINT).subtract(ValueSet.ofRanges(Range.equal(BIGINT, 1L), Range.equal(BIGINT, 2L), Range.equal(BIGINT, 3L))), false);
TupleDomain<Symbol> tupleDomain = withColumnDomains(ImmutableMap.<Symbol, Domain>builder().put(C_BIGINT, testDomain).build());
assertEquals(toPredicate(tupleDomain), not(in(C_BIGINT, ImmutableList.of(1L, 2L, 3L))));
testDomain = Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 4L)).intersect(ValueSet.all(BIGINT).subtract(ValueSet.ofRanges(Range.equal(BIGINT, 1L), Range.equal(BIGINT, 2L), Range.equal(BIGINT, 3L)))), false);
tupleDomain = withColumnDomains(ImmutableMap.<Symbol, Domain>builder().put(C_BIGINT, testDomain).build());
assertEquals(toPredicate(tupleDomain), and(lessThan(C_BIGINT, bigintLiteral(4L)), not(in(C_BIGINT, ImmutableList.of(1L, 2L, 3L)))));
testDomain = Domain.create(ValueSet.ofRanges(Range.range(BIGINT, 1L, true, 3L, true), Range.range(BIGINT, 5L, true, 7L, true), Range.range(BIGINT, 9L, true, 11L, true)), false);
tupleDomain = withColumnDomains(ImmutableMap.<Symbol, Domain>builder().put(C_BIGINT, testDomain).build());
assertEquals(toPredicate(tupleDomain), or(between(C_BIGINT, bigintLiteral(1L), bigintLiteral(3L)), (between(C_BIGINT, bigintLiteral(5L), bigintLiteral(7L))), (between(C_BIGINT, bigintLiteral(9L), bigintLiteral(11L)))));
testDomain = Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 4L)).intersect(ValueSet.all(BIGINT).subtract(ValueSet.ofRanges(Range.equal(BIGINT, 1L), Range.equal(BIGINT, 2L), Range.equal(BIGINT, 3L)))).union(ValueSet.ofRanges(Range.range(BIGINT, 7L, true, 9L, true))), false);
tupleDomain = withColumnDomains(ImmutableMap.<Symbol, Domain>builder().put(C_BIGINT, testDomain).build());
assertEquals(toPredicate(tupleDomain), or(and(lessThan(C_BIGINT, bigintLiteral(4L)), not(in(C_BIGINT, ImmutableList.of(1L, 2L, 3L)))), between(C_BIGINT, bigintLiteral(7L), bigintLiteral(9L))));
testDomain = Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 4L)).intersect(ValueSet.all(BIGINT).subtract(ValueSet.ofRanges(Range.equal(BIGINT, 1L), Range.equal(BIGINT, 2L), Range.equal(BIGINT, 3L)))).union(ValueSet.ofRanges(Range.range(BIGINT, 7L, false, 9L, false), Range.range(BIGINT, 11L, false, 13L, false))), false);
tupleDomain = withColumnDomains(ImmutableMap.<Symbol, Domain>builder().put(C_BIGINT, testDomain).build());
assertEquals(toPredicate(tupleDomain), or(and(lessThan(C_BIGINT, bigintLiteral(4L)), not(in(C_BIGINT, ImmutableList.of(1L, 2L, 3L)))), and(greaterThan(C_BIGINT, bigintLiteral(7L)), lessThan(C_BIGINT, bigintLiteral(9L))), and(greaterThan(C_BIGINT, bigintLiteral(11L)), lessThan(C_BIGINT, bigintLiteral(13L)))));
}
use of com.facebook.presto.spi.predicate.TupleDomain in project presto by prestodb.
the class MongoSession method buildQuery.
@VisibleForTesting
static Document buildQuery(TupleDomain<ColumnHandle> tupleDomain) {
Document query = new Document();
if (tupleDomain.getDomains().isPresent()) {
for (Map.Entry<ColumnHandle, Domain> entry : tupleDomain.getDomains().get().entrySet()) {
MongoColumnHandle column = (MongoColumnHandle) entry.getKey();
query.putAll(buildPredicate(column, entry.getValue()));
}
}
return query;
}
Aggregations