Search in sources :

Example 1 with SOME

use of com.facebook.presto.orc.TestMapFlatSelectiveStreamReader.ExpectedValuesBuilder.Frequency.SOME 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)

Aggregations

Session (com.facebook.presto.Session)1 Page (com.facebook.presto.common.Page)1 Subfield (com.facebook.presto.common.Subfield)1 Block (com.facebook.presto.common.block.Block)1 SqlFunctionProperties (com.facebook.presto.common.function.SqlFunctionProperties)1 FilterFunction (com.facebook.presto.common.predicate.FilterFunction)1 TupleDomainFilter (com.facebook.presto.common.predicate.TupleDomainFilter)1 IS_NOT_NULL (com.facebook.presto.common.predicate.TupleDomainFilter.IS_NOT_NULL)1 IS_NULL (com.facebook.presto.common.predicate.TupleDomainFilter.IS_NULL)1 TupleDomainFilterUtils.toBigintValues (com.facebook.presto.common.predicate.TupleDomainFilterUtils.toBigintValues)1 Predicate (com.facebook.presto.common.relation.Predicate)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 BooleanType (com.facebook.presto.common.type.BooleanType)1 DoubleType (com.facebook.presto.common.type.DoubleType)1 IntegerType (com.facebook.presto.common.type.IntegerType)1 INTEGER (com.facebook.presto.common.type.IntegerType.INTEGER)1 NamedTypeSignature (com.facebook.presto.common.type.NamedTypeSignature)1 REAL (com.facebook.presto.common.type.RealType.REAL)1 RowFieldName (com.facebook.presto.common.type.RowFieldName)1 SMALLINT (com.facebook.presto.common.type.SmallintType.SMALLINT)1