Search in sources :

Example 11 with TupleDomainFilter

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

the class TestListFilter method assertPositionalFilter.

private void assertPositionalFilter(Map<RowAndColumn, TupleDomainFilter> filters, Integer[][][] data) {
    ListFilter listFilter = buildListFilter(filters, data);
    TestFilter2 testFilter = (i, j, value) -> Optional.ofNullable(filters.get(RowAndColumn.of(i + 1, j + 1))).map(filter -> value == null ? filter.testNull() : filter.testLong(value)).orElse(true);
    PositionalFilter positionalFilter = listFilter.getChild().getPositionalFilter();
    for (int i = 0; i < data.length; i++) {
        boolean expectedToPass = true;
        int passCount = 0;
        int failCount = 0;
        for (int j = 0; j < data[i].length; j++) {
            if (!expectedToPass) {
                failCount += data[i][j].length;
                continue;
            }
            for (int k = 0; k < data[i][j].length; k++) {
                Integer value = data[i][j][k];
                expectedToPass = testFilter.test(j, k, value);
                assertEquals(value == null ? positionalFilter.testNull() : positionalFilter.testLong(value), expectedToPass);
                if (!expectedToPass) {
                    assertEquals(positionalFilter.getPrecedingPositionsToFail(), passCount);
                    failCount = data[i][j].length - k - 1;
                    break;
                }
                passCount++;
            }
        }
        assertEquals(positionalFilter.getSucceedingPositionsToFail(), failCount);
    }
}
Also used : ListFilter(com.facebook.presto.orc.reader.ListFilter) LIST(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.LIST) Arrays(java.util.Arrays) ListFilter(com.facebook.presto.orc.reader.ListFilter) ImmutableMap(com.google.common.collect.ImmutableMap) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Random(java.util.Random) String.format(java.lang.String.format) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) Objects(java.util.Objects) INT(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.INT) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Subfield(com.facebook.presto.common.Subfield) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Optional(java.util.Optional) OrcType(com.facebook.presto.orc.metadata.OrcType) PositionalFilter(com.facebook.presto.common.predicate.TupleDomainFilter.PositionalFilter) PositionalFilter(com.facebook.presto.common.predicate.TupleDomainFilter.PositionalFilter)

Example 12 with TupleDomainFilter

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

the class TestListFilter method assertPositionalFilter.

private void assertPositionalFilter(Map<Integer, TupleDomainFilter> filters, Integer[][] data) {
    ListFilter listFilter = buildListFilter(filters, data);
    TestFilter1 testFilter = (i, value) -> Optional.ofNullable(filters.get(i + 1)).map(filter -> value == null ? filter.testNull() : filter.testLong(value)).orElse(true);
    PositionalFilter positionalFilter = listFilter.getPositionalFilter();
    for (int i = 0; i < data.length; i++) {
        for (int j = 0; j < data[i].length; j++) {
            Integer value = data[i][j];
            boolean expectedToPass = testFilter.test(j, value);
            assertEquals(value == null ? positionalFilter.testNull() : positionalFilter.testLong(value), expectedToPass);
            if (!expectedToPass) {
                assertEquals(positionalFilter.getPrecedingPositionsToFail(), j);
                assertEquals(positionalFilter.getSucceedingPositionsToFail(), data[i].length - j - 1);
                break;
            }
        }
    }
}
Also used : ListFilter(com.facebook.presto.orc.reader.ListFilter) LIST(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.LIST) Arrays(java.util.Arrays) ListFilter(com.facebook.presto.orc.reader.ListFilter) ImmutableMap(com.google.common.collect.ImmutableMap) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Random(java.util.Random) String.format(java.lang.String.format) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) Objects(java.util.Objects) INT(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.INT) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Subfield(com.facebook.presto.common.Subfield) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Optional(java.util.Optional) OrcType(com.facebook.presto.orc.metadata.OrcType) PositionalFilter(com.facebook.presto.common.predicate.TupleDomainFilter.PositionalFilter) PositionalFilter(com.facebook.presto.common.predicate.TupleDomainFilter.PositionalFilter)

Example 13 with TupleDomainFilter

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

the class FilteringPageSource method getNextPage.

@Override
public Page getNextPage() {
    Page page = delegate.getNextPage();
    if (page == null || page.getPositionCount() == 0) {
        return page;
    }
    int positionCount = page.getPositionCount();
    int[] positions = new int[positionCount];
    for (int i = 0; i < positionCount; i++) {
        positions[i] = i;
    }
    for (int i = 0; i < page.getChannelCount(); i++) {
        TupleDomainFilter domainFilter = domainFilters[i];
        if (domainFilter != null) {
            positionCount = filterBlock(page.getBlock(i), columnTypes[i], domainFilter, positions, positionCount);
            if (positionCount == 0) {
                return new Page(0);
            }
        }
    }
    if (filterFunction != null) {
        RuntimeException[] errors = new RuntimeException[positionCount];
        int[] inputChannels = filterFunction.getInputChannels();
        Block[] inputBlocks = new Block[inputChannels.length];
        for (int i = 0; i < inputChannels.length; i++) {
            inputBlocks[i] = page.getBlock(this.functionInputs.get(inputChannels[i]));
        }
        Page inputPage = new Page(page.getPositionCount(), inputBlocks);
        positionCount = filterFunction.filter(inputPage, positions, positionCount, errors);
        for (int i = 0; i < positionCount; i++) {
            if (errors[i] != null) {
                throw errors[i];
            }
        }
        if (positionCount == 0) {
            return new Page(0);
        }
    }
    if (outputBlockCount == page.getChannelCount()) {
        return page.getPositions(positions, 0, positionCount);
    }
    Block[] blocks = new Block[outputBlockCount];
    for (int i = 0; i < outputBlockCount; i++) {
        blocks[i] = page.getBlock(i);
    }
    return new Page(page.getPositionCount(), blocks).getPositions(positions, 0, positionCount);
}
Also used : Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter)

Example 14 with TupleDomainFilter

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

the class TestSelectiveOrcReader method testOutputNotRequired.

@Test
public void testOutputNotRequired() throws Exception {
    List<Type> types = ImmutableList.of(VARCHAR, VARCHAR);
    TempFile tempFile = new TempFile();
    List<String> varcharDirectValues = newArrayList(limit(cycle(ImmutableList.of("A", "B", "C")), NUM_ROWS));
    List<List<?>> values = ImmutableList.of(varcharDirectValues, varcharDirectValues);
    writeOrcColumnsPresto(tempFile.getFile(), DWRF, NONE, Optional.empty(), types, values, new OrcWriterStats());
    OrcPredicate orcPredicate = createOrcPredicate(types, values, DWRF, false);
    // ImmutableMap.of(1, stringIn(true, "10", "11"));
    Map<Subfield, TupleDomainFilter> filters = ImmutableMap.of(new Subfield("c"), stringIn(true, "A", "B", "C"));
    Map<Integer, Type> includedColumns = IntStream.range(0, types.size()).boxed().collect(toImmutableMap(Function.identity(), types::get));
    // Do not output column 0 but only column 1
    List<Integer> outputColumns = ImmutableList.of(1);
    try (OrcSelectiveRecordReader recordReader = createCustomOrcSelectiveRecordReader(tempFile.getFile(), DWRF.getOrcEncoding(), orcPredicate, types, MAX_BATCH_SIZE, ImmutableMap.of(0, filters), OrcReaderSettings.builder().build().getFilterFunctions(), OrcReaderSettings.builder().build().getFilterFunctionInputMapping(), OrcReaderSettings.builder().build().getRequiredSubfields(), ImmutableMap.of(), ImmutableMap.of(), includedColumns, outputColumns, false, new TestingHiveOrcAggregatedMemoryContext(), false)) {
        assertEquals(recordReader.getReaderPosition(), 0);
        assertEquals(recordReader.getFilePosition(), 0);
        int rowsProcessed = 0;
        while (true) {
            Page page = recordReader.getNextPage();
            if (page == null) {
                break;
            }
            int positionCount = page.getPositionCount();
            if (positionCount == 0) {
                continue;
            }
            page.getLoadedPage();
            // The output block should be the second block
            assertBlockPositions(page.getBlock(0), varcharDirectValues.subList(rowsProcessed, rowsProcessed + positionCount));
            rowsProcessed += positionCount;
        }
        assertEquals(rowsProcessed, NUM_ROWS);
    }
}
Also used : OrcTester.createCustomOrcSelectiveRecordReader(com.facebook.presto.orc.OrcTester.createCustomOrcSelectiveRecordReader) 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) 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) TestingOrcPredicate.createOrcPredicate(com.facebook.presto.orc.TestingOrcPredicate.createOrcPredicate) Subfield(com.facebook.presto.common.Subfield) Test(org.testng.annotations.Test)

Example 15 with TupleDomainFilter

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

the class TestListFilter method buildListFilter.

private static ListFilter buildListFilter(Map<Integer, TupleDomainFilter> filters, Integer[][] data) {
    Map<Subfield, TupleDomainFilter> subfieldFilters = filters.entrySet().stream().collect(toImmutableMap(entry -> toSubfield(entry.getKey()), Map.Entry::getValue));
    ListFilter filter = new ListFilter(makeStreamDescriptor(1), subfieldFilters);
    int[] lengths = Arrays.stream(data).mapToInt(v -> v.length).toArray();
    filter.populateElementFilters(data.length, null, lengths, Arrays.stream(lengths).sum());
    return filter;
}
Also used : LIST(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.LIST) Arrays(java.util.Arrays) ListFilter(com.facebook.presto.orc.reader.ListFilter) ImmutableMap(com.google.common.collect.ImmutableMap) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) Random(java.util.Random) String.format(java.lang.String.format) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) Objects(java.util.Objects) INT(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.INT) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Subfield(com.facebook.presto.common.Subfield) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Optional(java.util.Optional) OrcType(com.facebook.presto.orc.metadata.OrcType) PositionalFilter(com.facebook.presto.common.predicate.TupleDomainFilter.PositionalFilter) ListFilter(com.facebook.presto.orc.reader.ListFilter) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Map(java.util.Map) 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