Search in sources :

Example 36 with TupleDomain

use of com.facebook.presto.spi.predicate.TupleDomain in project presto by prestodb.

the class TestOrcBloomFilters method testMatches.

@Test
public // simulate query on a 2 columns where 1 is used as part of the where, with and without bloom filter
void testMatches() throws Exception {
    // stripe column
    Domain testingColumnHandleDomain = Domain.singleValue(BIGINT, 1234L);
    TupleDomain.ColumnDomain<String> column0 = new TupleDomain.ColumnDomain<>(COLUMN_0, testingColumnHandleDomain);
    // predicate consist of the bigint_0 = 1234
    TupleDomain<String> effectivePredicate = TupleDomain.fromColumnDomains(Optional.of(ImmutableList.of(column0)));
    TupleDomain<String> emptyEffectivePredicate = TupleDomain.all();
    // predicate column references
    List<ColumnReference<String>> columnReferences = ImmutableList.<ColumnReference<String>>builder().add(new ColumnReference<>(COLUMN_0, 0, BIGINT)).add(new ColumnReference<>(COLUMN_1, 1, BIGINT)).build();
    TupleDomainOrcPredicate<String> predicate = new TupleDomainOrcPredicate<>(effectivePredicate, columnReferences, true);
    TupleDomainOrcPredicate<String> emptyPredicate = new TupleDomainOrcPredicate<>(emptyEffectivePredicate, columnReferences, true);
    // assemble a matching and a non-matching bloom filter
    HiveBloomFilter hiveBloomFilter = new HiveBloomFilter(new BloomFilter(1000, 0.01));
    OrcProto.BloomFilter emptyOrcBloomFilter = toOrcBloomFilter(hiveBloomFilter);
    hiveBloomFilter.addLong(1234);
    OrcProto.BloomFilter orcBloomFilter = toOrcBloomFilter(hiveBloomFilter);
    Map<Integer, ColumnStatistics> matchingStatisticsByColumnIndex = ImmutableMap.of(0, new ColumnStatistics(null, null, new IntegerStatistics(10L, 2000L), null, null, null, null, toHiveBloomFilter(orcBloomFilter)));
    Map<Integer, ColumnStatistics> nonMatchingStatisticsByColumnIndex = ImmutableMap.of(0, new ColumnStatistics(null, null, new IntegerStatistics(10L, 2000L), null, null, null, null, toHiveBloomFilter(emptyOrcBloomFilter)));
    Map<Integer, ColumnStatistics> withoutBloomFilterStatisticsByColumnIndex = ImmutableMap.of(0, new ColumnStatistics(null, null, new IntegerStatistics(10L, 2000L), null, null, null, null, null));
    assertTrue(predicate.matches(1L, matchingStatisticsByColumnIndex));
    assertTrue(predicate.matches(1L, withoutBloomFilterStatisticsByColumnIndex));
    assertFalse(predicate.matches(1L, nonMatchingStatisticsByColumnIndex));
    assertTrue(emptyPredicate.matches(1L, matchingStatisticsByColumnIndex));
}
Also used : ColumnStatistics(com.facebook.presto.orc.metadata.ColumnStatistics) OrcProto(com.facebook.presto.orc.proto.OrcProto) HiveBloomFilter(com.facebook.presto.orc.metadata.HiveBloomFilter) BloomFilter(org.apache.hive.common.util.BloomFilter) TupleDomainOrcPredicate.checkInBloomFilter(com.facebook.presto.orc.TupleDomainOrcPredicate.checkInBloomFilter) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) HiveBloomFilter(com.facebook.presto.orc.metadata.HiveBloomFilter) TupleDomain(com.facebook.presto.spi.predicate.TupleDomain) Domain(com.facebook.presto.spi.predicate.Domain) ColumnReference(com.facebook.presto.orc.TupleDomainOrcPredicate.ColumnReference) IntegerStatistics(com.facebook.presto.orc.metadata.IntegerStatistics) Test(org.testng.annotations.Test)

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