Search in sources :

Example 6 with TupleDomainFilter

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

the class TestSelectiveOrcReader method testHiddenConstantColumns.

@Test
public void testHiddenConstantColumns() throws Exception {
    Type type = BIGINT;
    List<Type> types = ImmutableList.of(type);
    List<List<?>> values = ImmutableList.of(ImmutableList.of(1L, 2L));
    TempFile tempFile = new TempFile();
    writeOrcColumnsPresto(tempFile.getFile(), DWRF, ZSTD, Optional.empty(), types, values, new OrcWriterStats());
    // Hidden columns like partition columns use negative indices (-13).
    int hiddenColumnIndex = -13;
    Map<Integer, Type> includedColumns = ImmutableMap.of(hiddenColumnIndex, VARCHAR, 0, BIGINT);
    List<Integer> outputColumns = ImmutableList.of(hiddenColumnIndex, 0);
    Slice constantSlice = Slices.utf8Slice("partition_value");
    Map<Integer, Object> constantValues = ImmutableMap.of(hiddenColumnIndex, constantSlice);
    OrcAggregatedMemoryContext systemMemoryUsage = new TestingHiveOrcAggregatedMemoryContext();
    TupleDomainFilter filter = BigintRange.of(1, 1, false);
    Map<Subfield, TupleDomainFilter> subFieldFilter = toSubfieldFilter(filter);
    OrcReaderSettings readerSettings = OrcTester.OrcReaderSettings.builder().setColumnFilters(ImmutableMap.of(0, subFieldFilter)).build();
    try (OrcSelectiveRecordReader recordReader = createCustomOrcSelectiveRecordReader(tempFile.getFile(), DWRF.getOrcEncoding(), OrcPredicate.TRUE, types, 1, readerSettings.getColumnFilters(), readerSettings.getFilterFunctions(), readerSettings.getFilterFunctionInputMapping(), readerSettings.getRequiredSubfields(), constantValues, ImmutableMap.of(), includedColumns, outputColumns, false, systemMemoryUsage, false)) {
        Page page = recordReader.getNextPage();
        assertEquals(page.getPositionCount(), 1);
        Block partitionValueBlock = page.getBlock(0);
        int length = partitionValueBlock.getSliceLength(0);
        Slice varcharSlice = partitionValueBlock.getSlice(0, 0, length);
        assertEquals(varcharSlice, constantSlice);
        Block bigintBlock = page.getBlock(1);
        assertEquals(bigintBlock.getLong(0), 1);
        assertNull(recordReader.getNextPage());
    }
}
Also used : OrcTester.createCustomOrcSelectiveRecordReader(com.facebook.presto.orc.OrcTester.createCustomOrcSelectiveRecordReader) OrcReaderSettings(com.facebook.presto.orc.OrcTester.OrcReaderSettings) Page(com.facebook.presto.common.Page) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) BigInteger(java.math.BigInteger) CharType.createCharType(com.facebook.presto.common.type.CharType.createCharType) OrcTester.mapType(com.facebook.presto.orc.OrcTester.mapType) DecimalType(com.facebook.presto.common.type.DecimalType) CharType(com.facebook.presto.common.type.CharType) Type(com.facebook.presto.common.type.Type) OrcTester.arrayType(com.facebook.presto.orc.OrcTester.arrayType) OrcTester.rowType(com.facebook.presto.orc.OrcTester.rowType) Slice(io.airlift.slice.Slice) Block(com.facebook.presto.common.block.Block) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) Subfield(com.facebook.presto.common.Subfield) Test(org.testng.annotations.Test)

Example 7 with TupleDomainFilter

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

the class TestMapFlatSelectiveStreamReader method runTest.

private <K, V> void runTest(String testOrcFileName, Type keyType, Type valueType, ExpectedValuesBuilder<K, V> expectedValuesBuilder) throws Exception {
    List<Map<K, V>> expectedValues = expectedValuesBuilder.build();
    Type mapType = mapType(keyType, valueType);
    OrcPredicate orcPredicate = createOrcPredicate(0, mapType, expectedValues, OrcTester.Format.DWRF, true);
    runTest(testOrcFileName, mapType, expectedValues, orcPredicate, Optional.empty(), ImmutableList.of());
    runTest(testOrcFileName, mapType, expectedValues.stream().filter(Objects::isNull).collect(toList()), orcPredicate, Optional.of(IS_NULL), ImmutableList.of());
    runTest(testOrcFileName, mapType, expectedValues.stream().filter(Objects::nonNull).collect(toList()), orcPredicate, Optional.of(IS_NOT_NULL), ImmutableList.of());
    if (keyType != VARBINARY) {
        // read only some keys
        List<K> keys = expectedValues.stream().filter(Objects::nonNull).flatMap(v -> v.keySet().stream()).distinct().collect(toImmutableList());
        if (!keys.isEmpty()) {
            List<K> requiredKeys = ImmutableList.of(keys.get(0));
            runTest(testOrcFileName, mapType, pruneMaps(expectedValues, requiredKeys), orcPredicate, Optional.empty(), toSubfields(keyType, requiredKeys));
            List<Integer> keyIndices = ImmutableList.of(1, 3, 7, 11);
            requiredKeys = keyIndices.stream().filter(k -> k < keys.size()).map(keys::get).collect(toList());
            runTest(testOrcFileName, mapType, pruneMaps(expectedValues, requiredKeys), orcPredicate, Optional.empty(), toSubfields(keyType, requiredKeys));
        }
    }
    // read only some rows
    List<Integer> ids = IntStream.range(0, expectedValues.size()).map(i -> i % 10).boxed().collect(toImmutableList());
    ImmutableList<Type> types = ImmutableList.of(mapType, INTEGER);
    Map<Integer, Map<Subfield, TupleDomainFilter>> filters = ImmutableMap.of(1, ImmutableMap.of(new Subfield("c"), toBigintValues(new long[] { 1, 5, 6 }, true)));
    assertFileContentsPresto(types, new File(getResource(testOrcFileName).getFile()), filterRows(types, ImmutableList.of(expectedValues, ids), filters), OrcEncoding.DWRF, OrcPredicate.TRUE, Optional.of(filters), ImmutableList.of(), ImmutableMap.of(), ImmutableMap.of());
    TestingFilterFunction filterFunction = new TestingFilterFunction(mapType);
    assertFileContentsPresto(types, new File(getResource(testOrcFileName).getFile()), filterFunction.filterRows(ImmutableList.of(expectedValues, ids)), OrcEncoding.DWRF, OrcPredicate.TRUE, Optional.empty(), ImmutableList.of(filterFunction), ImmutableMap.of(0, 0), ImmutableMap.of());
}
Also used : ALL(com.facebook.presto.orc.TestMapFlatSelectiveStreamReader.ExpectedValuesBuilder.Frequency.ALL) Page(com.facebook.presto.common.Page) NONE(com.facebook.presto.orc.TestMapFlatSelectiveStreamReader.ExpectedValuesBuilder.Frequency.NONE) Test(org.testng.annotations.Test) FUNCTION_AND_TYPE_MANAGER(com.facebook.presto.testing.TestingEnvironment.FUNCTION_AND_TYPE_MANAGER) ALL_EXCEPT_FIRST(com.facebook.presto.orc.TestMapFlatSelectiveStreamReader.ExpectedValuesBuilder.Frequency.ALL_EXCEPT_FIRST) Map(java.util.Map) Predicate(com.facebook.presto.common.relation.Predicate) ImmutableMap(com.google.common.collect.ImmutableMap) OrcTester.mapType(com.facebook.presto.orc.OrcTester.mapType) SqlFunctionProperties(com.facebook.presto.common.function.SqlFunctionProperties) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) OrcTester.assertFileContentsPresto(com.facebook.presto.orc.OrcTester.assertFileContentsPresto) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) Resources.getResource(com.google.common.io.Resources.getResource) List(java.util.List) SqlTimestamp(com.facebook.presto.common.type.SqlTimestamp) IS_NOT_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NOT_NULL) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) Optional(java.util.Optional) IS_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NULL) IntStream(java.util.stream.IntStream) StandardTypes(com.facebook.presto.common.type.StandardTypes) TypeSignatureParameter(com.facebook.presto.common.type.TypeSignatureParameter) BooleanType(com.facebook.presto.common.type.BooleanType) TINYINT(com.facebook.presto.common.type.TinyintType.TINYINT) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) HashMap(java.util.HashMap) Function(java.util.function.Function) REAL(com.facebook.presto.common.type.RealType.REAL) ArrayList(java.util.ArrayList) IntegerType(com.facebook.presto.common.type.IntegerType) Subfield(com.facebook.presto.common.Subfield) ImmutableList(com.google.common.collect.ImmutableList) FilterFunction(com.facebook.presto.common.predicate.FilterFunction) SqlVarbinary(com.facebook.presto.common.type.SqlVarbinary) SOME(com.facebook.presto.orc.TestMapFlatSelectiveStreamReader.ExpectedValuesBuilder.Frequency.SOME) Type(com.facebook.presto.common.type.Type) NamedTypeSignature(com.facebook.presto.common.type.NamedTypeSignature) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) OrcTester.arrayType(com.facebook.presto.orc.OrcTester.arrayType) OrcTester.filterRows(com.facebook.presto.orc.OrcTester.filterRows) Session(com.facebook.presto.Session) TupleDomainFilterUtils.toBigintValues(com.facebook.presto.common.predicate.TupleDomainFilterUtils.toBigintValues) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) VARBINARY(com.facebook.presto.common.type.VarbinaryType.VARBINARY) Maps(com.google.common.collect.Maps) File(java.io.File) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) TimeZoneKey(com.facebook.presto.common.type.TimeZoneKey) Collectors.toList(java.util.stream.Collectors.toList) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) TestingOrcPredicate.createOrcPredicate(com.facebook.presto.orc.TestingOrcPredicate.createOrcPredicate) RowFieldName(com.facebook.presto.common.type.RowFieldName) Block(com.facebook.presto.common.block.Block) Collections(java.util.Collections) DoubleType(com.facebook.presto.common.type.DoubleType) OrcTester.mapType(com.facebook.presto.orc.OrcTester.mapType) BooleanType(com.facebook.presto.common.type.BooleanType) IntegerType(com.facebook.presto.common.type.IntegerType) Type(com.facebook.presto.common.type.Type) OrcTester.arrayType(com.facebook.presto.orc.OrcTester.arrayType) DoubleType(com.facebook.presto.common.type.DoubleType) Objects(java.util.Objects) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) File(java.io.File) TestingOrcPredicate.createOrcPredicate(com.facebook.presto.orc.TestingOrcPredicate.createOrcPredicate) Subfield(com.facebook.presto.common.Subfield)

Example 8 with TupleDomainFilter

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

the class TestMapFlatSelectiveStreamReader method runTest.

private <K, V> void runTest(String testOrcFileName, Type mapType, List<Map<K, V>> expectedValues, OrcPredicate orcPredicate, Optional<TupleDomainFilter> filter, List<Subfield> subfields) throws Exception {
    List<Type> types = ImmutableList.of(mapType);
    Optional<Map<Integer, Map<Subfield, TupleDomainFilter>>> filters = filter.map(f -> ImmutableMap.of(new Subfield("c"), f)).map(f -> ImmutableMap.of(0, f));
    assertFileContentsPresto(types, new File(getResource(testOrcFileName).getFile()), filters.map(f -> filterRows(types, ImmutableList.of(expectedValues), f)).orElse(ImmutableList.of(expectedValues)), OrcEncoding.DWRF, orcPredicate, filters, ImmutableList.of(), ImmutableMap.of(), ImmutableMap.of(0, subfields));
}
Also used : ALL(com.facebook.presto.orc.TestMapFlatSelectiveStreamReader.ExpectedValuesBuilder.Frequency.ALL) Page(com.facebook.presto.common.Page) NONE(com.facebook.presto.orc.TestMapFlatSelectiveStreamReader.ExpectedValuesBuilder.Frequency.NONE) Test(org.testng.annotations.Test) FUNCTION_AND_TYPE_MANAGER(com.facebook.presto.testing.TestingEnvironment.FUNCTION_AND_TYPE_MANAGER) ALL_EXCEPT_FIRST(com.facebook.presto.orc.TestMapFlatSelectiveStreamReader.ExpectedValuesBuilder.Frequency.ALL_EXCEPT_FIRST) Map(java.util.Map) Predicate(com.facebook.presto.common.relation.Predicate) ImmutableMap(com.google.common.collect.ImmutableMap) OrcTester.mapType(com.facebook.presto.orc.OrcTester.mapType) SqlFunctionProperties(com.facebook.presto.common.function.SqlFunctionProperties) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) OrcTester.assertFileContentsPresto(com.facebook.presto.orc.OrcTester.assertFileContentsPresto) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) Resources.getResource(com.google.common.io.Resources.getResource) List(java.util.List) SqlTimestamp(com.facebook.presto.common.type.SqlTimestamp) IS_NOT_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NOT_NULL) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) Optional(java.util.Optional) IS_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NULL) IntStream(java.util.stream.IntStream) StandardTypes(com.facebook.presto.common.type.StandardTypes) TypeSignatureParameter(com.facebook.presto.common.type.TypeSignatureParameter) BooleanType(com.facebook.presto.common.type.BooleanType) TINYINT(com.facebook.presto.common.type.TinyintType.TINYINT) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) HashMap(java.util.HashMap) Function(java.util.function.Function) REAL(com.facebook.presto.common.type.RealType.REAL) ArrayList(java.util.ArrayList) IntegerType(com.facebook.presto.common.type.IntegerType) Subfield(com.facebook.presto.common.Subfield) ImmutableList(com.google.common.collect.ImmutableList) FilterFunction(com.facebook.presto.common.predicate.FilterFunction) SqlVarbinary(com.facebook.presto.common.type.SqlVarbinary) SOME(com.facebook.presto.orc.TestMapFlatSelectiveStreamReader.ExpectedValuesBuilder.Frequency.SOME) Type(com.facebook.presto.common.type.Type) NamedTypeSignature(com.facebook.presto.common.type.NamedTypeSignature) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) OrcTester.arrayType(com.facebook.presto.orc.OrcTester.arrayType) OrcTester.filterRows(com.facebook.presto.orc.OrcTester.filterRows) Session(com.facebook.presto.Session) TupleDomainFilterUtils.toBigintValues(com.facebook.presto.common.predicate.TupleDomainFilterUtils.toBigintValues) TestingSession.testSessionBuilder(com.facebook.presto.testing.TestingSession.testSessionBuilder) VARBINARY(com.facebook.presto.common.type.VarbinaryType.VARBINARY) Maps(com.google.common.collect.Maps) File(java.io.File) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) TimeZoneKey(com.facebook.presto.common.type.TimeZoneKey) Collectors.toList(java.util.stream.Collectors.toList) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) TestingOrcPredicate.createOrcPredicate(com.facebook.presto.orc.TestingOrcPredicate.createOrcPredicate) RowFieldName(com.facebook.presto.common.type.RowFieldName) Block(com.facebook.presto.common.block.Block) Collections(java.util.Collections) DoubleType(com.facebook.presto.common.type.DoubleType) OrcTester.mapType(com.facebook.presto.orc.OrcTester.mapType) BooleanType(com.facebook.presto.common.type.BooleanType) IntegerType(com.facebook.presto.common.type.IntegerType) Type(com.facebook.presto.common.type.Type) OrcTester.arrayType(com.facebook.presto.orc.OrcTester.arrayType) DoubleType(com.facebook.presto.common.type.DoubleType) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) File(java.io.File) Subfield(com.facebook.presto.common.Subfield) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter)

Example 9 with TupleDomainFilter

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

the class OrcSelectiveRecordReader method createStreamReaders.

private static SelectiveStreamReader[] createStreamReaders(OrcDataSource orcDataSource, List<OrcType> types, DateTimeZone hiveStorageTimeZone, OrcRecordReaderOptions options, boolean legacyMapSubscript, Map<Integer, Type> includedColumns, List<Integer> outputColumns, Map<Integer, Map<Subfield, TupleDomainFilter>> filters, List<FilterFunction> filterFunctions, Map<Integer, Integer> filterFunctionInputMapping, Map<Integer, List<Subfield>> requiredSubfields, OrcAggregatedMemoryContext systemMemoryContext) {
    List<StreamDescriptor> streamDescriptors = createStreamDescriptor("", "", 0, types, orcDataSource).getNestedStreams();
    requireNonNull(filterFunctions, "filterFunctions is null");
    requireNonNull(filterFunctionInputMapping, "filterFunctionInputMapping is null");
    Set<Integer> filterFunctionInputColumns = filterFunctions.stream().flatMapToInt(function -> Arrays.stream(function.getInputChannels())).boxed().map(filterFunctionInputMapping::get).collect(toImmutableSet());
    OrcType rowType = types.get(0);
    SelectiveStreamReader[] streamReaders = new SelectiveStreamReader[rowType.getFieldCount()];
    for (int columnId = 0; columnId < rowType.getFieldCount(); columnId++) {
        if (includedColumns.containsKey(columnId)) {
            StreamDescriptor streamDescriptor = streamDescriptors.get(columnId);
            boolean outputRequired = outputColumns.contains(columnId) || filterFunctionInputColumns.contains(columnId);
            streamReaders[columnId] = createStreamReader(streamDescriptor, Optional.ofNullable(filters.get(columnId)).orElse(ImmutableMap.of()), outputRequired ? Optional.of(includedColumns.get(columnId)) : Optional.empty(), Optional.ofNullable(requiredSubfields.get(columnId)).orElse(ImmutableList.of()), hiveStorageTimeZone, options, legacyMapSubscript, systemMemoryContext);
        }
    }
    return streamReaders;
}
Also used : Page(com.facebook.presto.common.Page) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Predicates.not(com.google.common.base.Predicates.not) Map(java.util.Map) StripeInformation(com.facebook.presto.orc.metadata.StripeInformation) Varchars.isVarcharType(com.facebook.presto.common.type.Varchars.isVarcharType) RuntimeStats(com.facebook.presto.common.RuntimeStats) BlockLease(com.facebook.presto.common.block.BlockLease) BigintValuesUsingHashTable(com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingHashTable) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Math.min(java.lang.Math.min) ColumnStatistics(com.facebook.presto.orc.metadata.statistics.ColumnStatistics) UncheckedIOException(java.io.UncheckedIOException) Objects(java.util.Objects) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ClassLayout(org.openjdk.jol.info.ClassLayout) SizeOf.sizeOf(io.airlift.slice.SizeOf.sizeOf) LazyBlockLoader(com.facebook.presto.common.block.LazyBlockLoader) SelectiveStreamReader(com.facebook.presto.orc.reader.SelectiveStreamReader) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) SelectiveStreamReaders.createStreamReader(com.facebook.presto.orc.reader.SelectiveStreamReaders.createStreamReader) Optional(java.util.Optional) Math.max(java.lang.Math.max) LazyBlock(com.facebook.presto.common.block.LazyBlock) IntStream(java.util.stream.IntStream) Iterables(com.google.common.collect.Iterables) DecimalType(com.facebook.presto.common.type.DecimalType) Slice(io.airlift.slice.Slice) TINYINT(com.facebook.presto.common.type.TinyintType.TINYINT) HashMap(java.util.HashMap) TIMESTAMP(com.facebook.presto.common.type.TimestampType.TIMESTAMP) Function(java.util.function.Function) DATE(com.facebook.presto.common.type.DateType.DATE) REAL(com.facebook.presto.common.type.RealType.REAL) ArrayList(java.util.ArrayList) Subfield(com.facebook.presto.common.Subfield) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) FilterFunction(com.facebook.presto.common.predicate.FilterFunction) Objects.requireNonNull(java.util.Objects.requireNonNull) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) CharType(com.facebook.presto.common.type.CharType) OrcType(com.facebook.presto.orc.metadata.OrcType) Type(com.facebook.presto.common.type.Type) Nullable(javax.annotation.Nullable) MAX_BATCH_SIZE(com.facebook.presto.orc.OrcReader.MAX_BATCH_SIZE) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) BigintMultiRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintMultiRange) StripeStatistics(com.facebook.presto.orc.metadata.statistics.StripeStatistics) PostScript(com.facebook.presto.orc.metadata.PostScript) LongArrayBlock(com.facebook.presto.common.block.LongArrayBlock) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) Ints(com.google.common.primitives.Ints) BigintValuesUsingBitmask(com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingBitmask) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) Block(com.facebook.presto.common.block.Block) Comparator(java.util.Comparator) MetadataReader(com.facebook.presto.orc.metadata.MetadataReader) OrcType(com.facebook.presto.orc.metadata.OrcType) SelectiveStreamReader(com.facebook.presto.orc.reader.SelectiveStreamReader)

Example 10 with TupleDomainFilter

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

the class OrcSelectiveRecordReader method scoreFilter.

private static int scoreFilter(Map<Subfield, TupleDomainFilter> filters) {
    checkArgument(!filters.isEmpty());
    if (filters.size() > 1) {
        // Complex type column. Complex types are expensive!
        return 1000;
    }
    Map.Entry<Subfield, TupleDomainFilter> filterEntry = Iterables.getOnlyElement(filters.entrySet());
    if (!filterEntry.getKey().getPath().isEmpty()) {
        // Complex type column. Complex types are expensive!
        return 1000;
    }
    TupleDomainFilter filter = filterEntry.getValue();
    if (filter instanceof BigintRange) {
        if (((BigintRange) filter).isSingleValue()) {
            // Integer equality. Generally cheap.
            return 10;
        }
        return 50;
    }
    if (filter instanceof BigintValuesUsingHashTable || filter instanceof BigintValuesUsingBitmask || filter instanceof BigintMultiRange) {
        return 50;
    }
    return 100;
}
Also used : BigintValuesUsingHashTable(com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingHashTable) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) BigintMultiRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintMultiRange) BigintValuesUsingBitmask(com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingBitmask) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) HashMap(java.util.HashMap) Subfield(com.facebook.presto.common.Subfield) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter)

Aggregations

TupleDomainFilter (com.facebook.presto.common.predicate.TupleDomainFilter)23 Subfield (com.facebook.presto.common.Subfield)20 ImmutableMap (com.google.common.collect.ImmutableMap)12 Map (java.util.Map)12 ImmutableList (com.google.common.collect.ImmutableList)11 Test (org.testng.annotations.Test)11 Type (com.facebook.presto.common.type.Type)9 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)9 Optional (java.util.Optional)9 List (java.util.List)8 Block (com.facebook.presto.common.block.Block)7 HashMap (java.util.HashMap)7 Objects (java.util.Objects)7 Page (com.facebook.presto.common.Page)6 BigintRange (com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange)6 CharType (com.facebook.presto.common.type.CharType)6 DecimalType (com.facebook.presto.common.type.DecimalType)6 ArrayList (java.util.ArrayList)6 Arrays (java.util.Arrays)6 PositionalFilter (com.facebook.presto.common.predicate.TupleDomainFilter.PositionalFilter)5