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());
}
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);
}
}
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;
}
}
}
}
Aggregations