Search in sources :

Example 1 with TupleDomainFilter

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

the class StructSelectiveStreamReader method getTopLevelFilter.

private static Optional<TupleDomainFilter> getTopLevelFilter(Map<Subfield, TupleDomainFilter> filters) {
    Map<Subfield, TupleDomainFilter> topLevelFilters = Maps.filterEntries(filters, entry -> entry.getKey().getPath().isEmpty());
    if (topLevelFilters.isEmpty()) {
        return Optional.empty();
    }
    checkArgument(topLevelFilters.size() == 1, "ROW column may have at most one top-level range filter");
    TupleDomainFilter filter = Iterables.getOnlyElement(topLevelFilters.values());
    checkArgument(filter == IS_NULL || filter == IS_NOT_NULL, "Top-level range filter on ROW column must be IS NULL or IS NOT NULL");
    return Optional.of(filter);
}
Also used : Subfield(com.facebook.presto.common.Subfield) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter)

Example 2 with TupleDomainFilter

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

the class StructSelectiveStreamReader method checkMissingFieldFilters.

private boolean checkMissingFieldFilters(Collection<StreamDescriptor> nestedStreams, Map<Subfield, TupleDomainFilter> filters) {
    if (filters.isEmpty()) {
        return true;
    }
    Set<String> presentFieldNames = nestedStreams.stream().map(StreamDescriptor::getFieldName).map(name -> name.toLowerCase(Locale.ENGLISH)).collect(toImmutableSet());
    for (Map.Entry<Subfield, TupleDomainFilter> entry : filters.entrySet()) {
        Subfield subfield = entry.getKey();
        if (subfield.getPath().isEmpty()) {
            continue;
        }
        String fieldName = ((Subfield.NestedField) subfield.getPath().get(0)).getName();
        if (presentFieldNames.contains(fieldName)) {
            continue;
        }
        // Check out the filter. If filter allows nulls, then all rows pass, otherwise, no row passes.
        TupleDomainFilter filter = entry.getValue();
        checkArgument(filter.isDeterministic(), "Non-deterministic range filters are not supported yet");
        if (!filter.testNull()) {
            return false;
        }
    }
    return true;
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) RunLengthEncodedBlock(com.facebook.presto.common.block.RunLengthEncodedBlock) BooleanInputStream(com.facebook.presto.orc.stream.BooleanInputStream) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Locale(java.util.Locale) Map(java.util.Map) BlockLease(com.facebook.presto.common.block.BlockLease) ImmutableMap(com.google.common.collect.ImmutableMap) InputStreamSource(com.facebook.presto.orc.stream.InputStreamSource) Collection(java.util.Collection) Set(java.util.Set) SelectiveStreamReaders.initializeOutputPositions(com.facebook.presto.orc.reader.SelectiveStreamReaders.initializeOutputPositions) OrcRecordReaderOptions(com.facebook.presto.orc.OrcRecordReaderOptions) Preconditions.checkState(com.google.common.base.Preconditions.checkState) 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) IS_NOT_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NOT_NULL) InputStreamSources(com.facebook.presto.orc.stream.InputStreamSources) Optional(java.util.Optional) IS_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NULL) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) StreamDescriptor(com.facebook.presto.orc.StreamDescriptor) Iterables(com.google.common.collect.Iterables) Field(com.facebook.presto.common.type.RowType.Field) RowBlock(com.facebook.presto.common.block.RowBlock) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PRESENT(com.facebook.presto.orc.metadata.Stream.StreamKind.PRESENT) OrcLocalMemoryContext(com.facebook.presto.orc.OrcLocalMemoryContext) Subfield(com.facebook.presto.common.Subfield) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Type(com.facebook.presto.common.type.Type) Stripe(com.facebook.presto.orc.Stripe) Nullable(javax.annotation.Nullable) MissingInputStreamSource.missingStreamSource(com.facebook.presto.orc.stream.MissingInputStreamSource.missingStreamSource) OrcAggregatedMemoryContext(com.facebook.presto.orc.OrcAggregatedMemoryContext) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) ClosingBlockLease(com.facebook.presto.common.block.ClosingBlockLease) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) Arrays.ensureCapacity(com.facebook.presto.common.array.Arrays.ensureCapacity) Block(com.facebook.presto.common.block.Block) RowType(com.facebook.presto.common.type.RowType) StreamDescriptor(com.facebook.presto.orc.StreamDescriptor) 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)

Example 3 with TupleDomainFilter

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

the class OrcTester method testRow.

private static boolean testRow(List<Type> types, List<List<?>> values, int row, Map<Integer, Map<Subfield, TupleDomainFilter>> columnFilters) {
    for (int column = 0; column < types.size(); column++) {
        Map<Subfield, TupleDomainFilter> filters = columnFilters.get(column);
        if (filters == null) {
            continue;
        }
        Type type = types.get(column);
        Object value = values.get(column).get(row);
        for (Map.Entry<Subfield, TupleDomainFilter> entry : filters.entrySet()) {
            if (!testSubfieldValue(type, value, entry.getKey(), entry.getValue())) {
                return false;
            }
        }
    }
    return true;
}
Also used : DecimalType(com.facebook.presto.common.type.DecimalType) ArrayType(com.facebook.presto.common.type.ArrayType) CharType(com.facebook.presto.common.type.CharType) RowType(com.facebook.presto.common.type.RowType) VarcharType(com.facebook.presto.common.type.VarcharType) VarbinaryType(com.facebook.presto.common.type.VarbinaryType) MapType(com.facebook.presto.common.type.MapType) Type(com.facebook.presto.common.type.Type) OrcLazyObject(com.facebook.hive.orc.lazy.OrcLazyObject) Map(java.util.Map) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Subfield(com.facebook.presto.common.Subfield) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter)

Example 4 with TupleDomainFilter

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

the class OrcTester method assertFileContentsPresto.

private static void assertFileContentsPresto(List<Type> types, TempFile tempFile, List<List<?>> expectedValues, boolean skipFirstBatch, boolean skipStripe, OrcEncoding orcEncoding, Format format, boolean isHiveWriter, boolean useSelectiveOrcReader, List<OrcReaderSettings> settings, Map<Integer, Slice> intermediateEncryptionKeys) throws IOException {
    OrcPredicate orcPredicate = createOrcPredicate(types, expectedValues, format, isHiveWriter);
    Map<Integer, Type> includedColumns = IntStream.range(0, types.size()).boxed().collect(toImmutableMap(Function.identity(), types::get));
    List<Integer> outputColumns = IntStream.range(0, types.size()).boxed().collect(toImmutableList());
    if (useSelectiveOrcReader) {
        assertFileContentsPresto(types, tempFile.getFile(), expectedValues, orcEncoding, orcPredicate, Optional.empty(), ImmutableList.of(), ImmutableMap.of(), ImmutableMap.of(), intermediateEncryptionKeys, includedColumns, outputColumns);
        for (OrcReaderSettings entry : settings) {
            assertTrue(entry.getFilterFunctions().isEmpty(), "Filter functions are not supported yet");
            assertTrue(entry.getFilterFunctionInputMapping().isEmpty(), "Filter functions are not supported yet");
            Map<Integer, Map<Subfield, TupleDomainFilter>> columnFilters = entry.getColumnFilters();
            List<List<?>> prunedAndFilteredRows = pruneValues(types, filterRows(types, expectedValues, columnFilters), entry.getRequiredSubfields());
            Optional<TupleDomainFilterOrderChecker> orderChecker = Optional.empty();
            List<Integer> expectedFilterOrder = entry.getExpectedFilterOrder();
            if (!expectedFilterOrder.isEmpty()) {
                orderChecker = Optional.of(new TupleDomainFilterOrderChecker(expectedFilterOrder));
            }
            Optional<Map<Integer, Map<Subfield, TupleDomainFilter>>> transformedFilters = Optional.of(orderChecker.map(checker -> addOrderTracking(columnFilters, checker)).orElse(columnFilters));
            assertFileContentsPresto(types, tempFile.getFile(), prunedAndFilteredRows, orcEncoding, orcPredicate, transformedFilters, entry.getFilterFunctions(), entry.getFilterFunctionInputMapping(), entry.getRequiredSubfields());
            orderChecker.ifPresent(TupleDomainFilterOrderChecker::assertOrder);
        }
        return;
    }
    try (OrcBatchRecordReader recordReader = createCustomOrcRecordReader(tempFile, orcEncoding, orcPredicate, types, MAX_BATCH_SIZE, new StorageOrcFileTailSource(), new StorageStripeMetadataSource(), false, intermediateEncryptionKeys, false)) {
        assertEquals(recordReader.getReaderPosition(), 0);
        assertEquals(recordReader.getFilePosition(), 0);
        boolean isFirst = true;
        int rowsProcessed = 0;
        for (int batchSize = toIntExact(recordReader.nextBatch()); batchSize >= 0; batchSize = toIntExact(recordReader.nextBatch())) {
            if (skipStripe && rowsProcessed < 10000) {
            // skip recordReader.readBlock
            } else if (skipFirstBatch && isFirst) {
                // skip recordReader.readBlock
                isFirst = false;
            } else {
                for (int i = 0; i < types.size(); i++) {
                    Type type = types.get(i);
                    Block block = recordReader.readBlock(i);
                    assertEquals(block.getPositionCount(), batchSize);
                    checkNullValues(type, block);
                    assertBlockEquals(type, block, expectedValues.get(i), rowsProcessed);
                }
            }
            assertEquals(recordReader.getReaderPosition(), rowsProcessed);
            assertEquals(recordReader.getFilePosition(), rowsProcessed);
            rowsProcessed += batchSize;
        }
        assertEquals(rowsProcessed, expectedValues.get(0).size());
        assertEquals(recordReader.getReaderPosition(), rowsProcessed);
        assertEquals(recordReader.getFilePosition(), rowsProcessed);
    }
}
Also used : StorageOrcFileTailSource(com.facebook.presto.orc.cache.StorageOrcFileTailSource) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) BigInteger(java.math.BigInteger) DecimalType(com.facebook.presto.common.type.DecimalType) ArrayType(com.facebook.presto.common.type.ArrayType) CharType(com.facebook.presto.common.type.CharType) RowType(com.facebook.presto.common.type.RowType) VarcharType(com.facebook.presto.common.type.VarcharType) VarbinaryType(com.facebook.presto.common.type.VarbinaryType) MapType(com.facebook.presto.common.type.MapType) Type(com.facebook.presto.common.type.Type) Block(com.facebook.presto.common.block.Block) Arrays.asList(java.util.Arrays.asList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) Map(java.util.Map) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) TestingOrcPredicate.createOrcPredicate(com.facebook.presto.orc.TestingOrcPredicate.createOrcPredicate) Subfield(com.facebook.presto.common.Subfield)

Example 5 with TupleDomainFilter

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

the class TestPositionalFilter method test.

@Test
public void test() {
    PositionalFilter filter = new PositionalFilter();
    // a[1] = '1' and a[3] = '3' The test data is converted to byte[]'s and the comparison is done using testLength()
    // followed by testBytes() so as to cover the double use of the position when testLength succeeeds and testBytes
    // fails.
    TupleDomainFilter[] filters = new TupleDomainFilter[] { equals(1), null, equals(3), null, equals(1), null, equals(3), null, equals(1), null, equals(3), null, null, equals(1), null, equals(3), null, null, null, equals(1), null, equals(3), null, null, null, null };
    long[] numbers = new long[] { // pass
    1, // pass
    2, // pass
    3, // pass
    4, // fail
    0, // fail
    2, // fail
    3, // fail
    4, // fail testLength()
    1, // fail testLength()
    2, // fail testLength()
    0, // fail testLength()
    4, // fail testLength()
    55, // pass
    1, // pass
    0, // pass
    3, // pass
    0, // pass
    5, // pass
    6, // fail testBytes()
    1, // fail testBytes()
    1, // fail testBytes()
    2, // fail testBytes()
    2, // fail testBytes()
    3, // fail testBytes()
    3, // fail testBytes()
    4 };
    // Convert the values to byte[][].
    byte[][] values = Arrays.stream(numbers).mapToObj(n -> toBytes(Long.valueOf(n).toString())).toArray(byte[][]::new);
    boolean[] expectedResults = new boolean[] { true, true, true, true, false, true, true, false, true, true, true, true, true, true, true, true, false };
    int[] offsets = new int[] { 0, 4, 8, 13, 19, 26 };
    filter.setFilters(filters, offsets);
    int valuesIndex = 0;
    for (int i = 0; i < expectedResults.length; i++) {
        boolean result = filter.testLength(values[valuesIndex].length) && filter.testBytes(values[valuesIndex], 0, values[valuesIndex].length);
        assertEquals(expectedResults[i], result);
        valuesIndex++;
        if (expectedResults[i] == false) {
            valuesIndex += filter.getSucceedingPositionsToFail();
        }
    }
    assertEquals(new boolean[] { false, true, true, false, true, false }, filter.getFailed());
}
Also used : TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) Arrays(java.util.Arrays) Assert.assertEquals(com.facebook.presto.testing.assertions.Assert.assertEquals) Slices(io.airlift.slice.Slices) Test(org.testng.annotations.Test) PositionalFilter(com.facebook.presto.common.predicate.TupleDomainFilter.PositionalFilter) BytesRange(com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange) PositionalFilter(com.facebook.presto.common.predicate.TupleDomainFilter.PositionalFilter) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) Test(org.testng.annotations.Test)

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