Search in sources :

Example 1 with PositionalFilter

use of com.facebook.presto.common.predicate.TupleDomainFilter.PositionalFilter 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)

Example 2 with PositionalFilter

use of com.facebook.presto.common.predicate.TupleDomainFilter.PositionalFilter 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 3 with PositionalFilter

use of com.facebook.presto.common.predicate.TupleDomainFilter.PositionalFilter 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)

Aggregations

TupleDomainFilter (com.facebook.presto.common.predicate.TupleDomainFilter)3 PositionalFilter (com.facebook.presto.common.predicate.TupleDomainFilter.PositionalFilter)3 Arrays (java.util.Arrays)3 Test (org.testng.annotations.Test)3 Subfield (com.facebook.presto.common.Subfield)2 BigintRange (com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange)2 OrcType (com.facebook.presto.orc.metadata.OrcType)2 INT (com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.INT)2 LIST (com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.LIST)2 ListFilter (com.facebook.presto.orc.reader.ListFilter)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)2 String.format (java.lang.String.format)2 Map (java.util.Map)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 Random (java.util.Random)2 Assert.assertEquals (org.testng.Assert.assertEquals)2 BytesRange (com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange)1