Search in sources :

Example 6 with TupleDomain

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);
}
Also used : TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 7 with TupleDomain

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);
}
Also used : TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 8 with TupleDomain

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;
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) Map(java.util.Map)

Example 9 with TupleDomain

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)))));
}
Also used : TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) Test(org.testng.annotations.Test)

Example 10 with TupleDomain

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;
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) Document(org.bson.Document) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) Map(java.util.Map) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

TupleDomain (com.facebook.presto.spi.predicate.TupleDomain)36 Domain (com.facebook.presto.spi.predicate.Domain)30 ImmutableList (com.google.common.collect.ImmutableList)22 ColumnHandle (com.facebook.presto.spi.ColumnHandle)18 Map (java.util.Map)18 List (java.util.List)15 Objects.requireNonNull (java.util.Objects.requireNonNull)15 ImmutableMap (com.google.common.collect.ImmutableMap)14 Optional (java.util.Optional)13 Collectors.toList (java.util.stream.Collectors.toList)13 Type (com.facebook.presto.spi.type.Type)12 ImmutableSet (com.google.common.collect.ImmutableSet)12 PrestoException (com.facebook.presto.spi.PrestoException)11 Range (com.facebook.presto.spi.predicate.Range)11 Set (java.util.Set)11 ConnectorSession (com.facebook.presto.spi.ConnectorSession)10 TypeManager (com.facebook.presto.spi.type.TypeManager)10 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)10 Test (org.testng.annotations.Test)10 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)9