Search in sources :

Example 6 with FilterFunction

use of com.facebook.presto.common.predicate.FilterFunction in project presto by prestodb.

the class TestFilterFunction method testFilter.

@Test
public void testFilter() {
    ConnectorSession session = new TestingConnectorSession(ImmutableList.of());
    FilterFunction filter = new FilterFunction(session.getSqlFunctionProperties(), true, new IsOddPredicate());
    Block numbers = makeNumbers(0, 1000);
    int[] allPositions = makePositions(0, 1000, 1);
    assertFilter(filter, numbers, allPositions, allPositions.length);
    Block dictionaryNumbers = new DictionaryBlock(numbers, allPositions);
    // Sparse coverage of the dictionary values
    int[] sparsePositions = makePositions(1, 300, 3);
    assertFilter(filter, dictionaryNumbers, sparsePositions, sparsePositions.length);
    // Full coverage of the dictionary values
    assertFilter(filter, dictionaryNumbers, allPositions, allPositions.length);
    // Test with a different DictionaryBlock over the same numbers. Results are reused. The DictionaryBlock covers the
    // values sparsely. TheDictionaryBlock itself is accessed sparsely.
    DictionaryBlock otherDictionary = new DictionaryBlock(numbers, makePositions(1, 332, 3));
    int[] otherDictionaryPositions = makePositions(0, 150, 2);
    assertFilter(filter, otherDictionary, otherDictionaryPositions, otherDictionaryPositions.length);
    // Repeat test on a DictionaryBlock over different content to make sure that cached results are not reused.
    assertFilter(filter, new DictionaryBlock(makeNumbers(1, 1001), allPositions), allPositions, allPositions.length);
}
Also used : FilterFunction(com.facebook.presto.common.predicate.FilterFunction) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) Block(com.facebook.presto.common.block.Block) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Test(org.testng.annotations.Test)

Aggregations

FilterFunction (com.facebook.presto.common.predicate.FilterFunction)6 Page (com.facebook.presto.common.Page)5 Block (com.facebook.presto.common.block.Block)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Maps (com.google.common.collect.Maps)4 Subfield (com.facebook.presto.common.Subfield)3 LongArrayBlock (com.facebook.presto.common.block.LongArrayBlock)3 SqlFunctionProperties (com.facebook.presto.common.function.SqlFunctionProperties)3 TupleDomainFilter (com.facebook.presto.common.predicate.TupleDomainFilter)3 Predicate (com.facebook.presto.common.relation.Predicate)3 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)3 Type (com.facebook.presto.common.type.Type)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3