Search in sources :

Example 1 with INT

use of com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.INT in project presto by prestodb.

the class TestDecryption method validateFileStatistics.

private static void validateFileStatistics(TempFile tempFile, Optional<DwrfWriterEncryption> dwrfWriterEncryption, Map<Integer, Slice> readerIntermediateKeys) throws IOException {
    OrcReader readerNoKeys = OrcTester.createCustomOrcReader(tempFile, DWRF, false, ImmutableMap.of());
    if (readerNoKeys.getFooter().getStripes().isEmpty()) {
        // files w/o stripes don't have stats
        assertEquals(readerNoKeys.getFooter().getFileStats().size(), 0);
        return;
    }
    if (dwrfWriterEncryption.isPresent()) {
        List<OrcType> types = readerNoKeys.getTypes();
        List<ColumnStatistics> fileStatsNoKey = readerNoKeys.getFooter().getFileStats();
        assertEquals(fileStatsNoKey.size(), types.size());
        Set<Integer> allEncryptedNodes = dwrfWriterEncryption.get().getWriterEncryptionGroups().stream().flatMap(group -> group.getNodes().stream()).flatMap(node -> collectNodeTree(types, node).stream()).collect(Collectors.toSet());
        for (Set<Integer> readerKeyNodes : Sets.powerSet(readerIntermediateKeys.keySet())) {
            Map<Integer, Slice> readerKeys = new HashMap<>();
            readerKeyNodes.forEach(node -> readerKeys.put(node, readerIntermediateKeys.get(node)));
            // nodes that are supposed to be decrypted by the reader
            Set<Integer> decryptedNodes = readerKeys.keySet().stream().flatMap(node -> collectNodeTree(types, node).stream()).collect(Collectors.toSet());
            // decryptedNodes should be a subset of encrypted nodes
            assertTrue(allEncryptedNodes.containsAll(decryptedNodes));
            OrcReader readerWithKeys = OrcTester.createCustomOrcReader(tempFile, DWRF, false, readerIntermediateKeys);
            List<ColumnStatistics> fileStatsWithKey = readerWithKeys.getFooter().getFileStats();
            assertEquals(fileStatsWithKey.size(), types.size());
            for (int node = 0; node < types.size(); node++) {
                ColumnStatistics statsWithKey = fileStatsWithKey.get(node);
                ColumnStatistics statsNoKey = fileStatsNoKey.get(node);
                OrcType type = types.get(node);
                // encrypted nodes should have no type info
                if (allEncryptedNodes.contains(node)) {
                    assertTrue(hasNoTypeStats(statsNoKey));
                } else {
                    assertStatsTypeMatch(statsNoKey, type);
                    assertStatsTypeMatch(statsWithKey, type);
                    assertEquals(statsNoKey, statsWithKey);
                }
                if (decryptedNodes.contains(node)) {
                    assertStatsTypeMatch(statsWithKey, type);
                }
            }
        }
    }
}
Also used : ColumnStatistics(com.facebook.presto.orc.metadata.statistics.ColumnStatistics) Test(org.testng.annotations.Test) OrcReader.validateEncryption(com.facebook.presto.orc.OrcReader.validateEncryption) DwrfEncryption(com.facebook.presto.orc.metadata.DwrfEncryption) StripeReader.getDiskRanges(com.facebook.presto.orc.StripeReader.getDiskRanges) INT(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.INT) Arrays.asList(java.util.Arrays.asList) Slices(io.airlift.slice.Slices) Map(java.util.Map) HIVE_STORAGE_TIME_ZONE(com.facebook.presto.orc.OrcTester.HIVE_STORAGE_TIME_ZONE) StripeInformation(com.facebook.presto.orc.metadata.StripeInformation) RuntimeStats(com.facebook.presto.common.RuntimeStats) ImmutableMap(com.google.common.collect.ImmutableMap) Footer(com.facebook.presto.orc.metadata.Footer) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) OrcTester.assertFileContentsPresto(com.facebook.presto.orc.OrcTester.assertFileContentsPresto) Assert.assertNotNull(org.testng.Assert.assertNotNull) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) NOOP_ORC_AGGREGATED_MEMORY_CONTEXT(com.facebook.presto.orc.NoopOrcAggregatedMemoryContext.NOOP_ORC_AGGREGATED_MEMORY_CONTEXT) ColumnStatistics(com.facebook.presto.orc.metadata.statistics.ColumnStatistics) DEFAULT_SEQUENCE_ID(com.facebook.presto.orc.metadata.ColumnEncoding.DEFAULT_SEQUENCE_ID) Resources.getResource(com.google.common.io.Resources.getResource) DataSize(io.airlift.units.DataSize) List(java.util.List) DWRF(com.facebook.presto.orc.OrcEncoding.DWRF) Optional(java.util.Optional) AbstractOrcRecordReader.getDecryptionKeyMetadata(com.facebook.presto.orc.AbstractOrcRecordReader.getDecryptionKeyMetadata) MAP(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.MAP) IntStream(java.util.stream.IntStream) MAX_BLOCK_SIZE(com.facebook.presto.orc.OrcTester.MAX_BLOCK_SIZE) LIST(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.LIST) ROW_INDEX(com.facebook.presto.orc.metadata.Stream.StreamKind.ROW_INDEX) Slice(io.airlift.slice.Slice) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) AbstractTestOrcReader.intsBetween(com.facebook.presto.orc.AbstractTestOrcReader.intsBetween) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) Assert.assertEquals(org.testng.Assert.assertEquals) HashMap(java.util.HashMap) UNKNOWN(com.facebook.presto.orc.metadata.KeyProvider.UNKNOWN) HashSet(java.util.HashSet) OptionalLong(java.util.OptionalLong) Subfield(com.facebook.presto.common.Subfield) ImmutableList(com.google.common.collect.ImmutableList) OrcTester.writeOrcColumnsPresto(com.facebook.presto.orc.OrcTester.writeOrcColumnsPresto) OrcType(com.facebook.presto.orc.metadata.OrcType) Type(com.facebook.presto.common.type.Type) MAX_BATCH_SIZE(com.facebook.presto.orc.OrcReader.MAX_BATCH_SIZE) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) STRUCT(com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.STRUCT) IOException(java.io.IOException) File(java.io.File) Stream(com.facebook.presto.orc.metadata.Stream) EncryptionGroup(com.facebook.presto.orc.metadata.EncryptionGroup) StorageOrcFileTailSource(com.facebook.presto.orc.cache.StorageOrcFileTailSource) Collectors.toList(java.util.stream.Collectors.toList) OrcTester.rowType(com.facebook.presto.orc.OrcTester.rowType) Assert.assertTrue(org.testng.Assert.assertTrue) DATA(com.facebook.presto.orc.metadata.Stream.StreamKind.DATA) DwrfEncryptionInfo.createNodeToGroupMap(com.facebook.presto.orc.DwrfEncryptionInfo.createNodeToGroupMap) ZSTD(com.facebook.presto.orc.metadata.CompressionKind.ZSTD) OrcType(com.facebook.presto.orc.metadata.OrcType) HashMap(java.util.HashMap) Slice(io.airlift.slice.Slice)

Example 2 with INT

use of com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.INT 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 INT

use of com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.INT 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 4 with INT

use of com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.INT 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)

Example 5 with INT

use of com.facebook.presto.orc.metadata.OrcType.OrcTypeKind.INT in project presto by prestodb.

the class TestListFilter method buildListFilter.

private static ListFilter buildListFilter(Map<RowAndColumn, 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(2), subfieldFilters);
    int[] lengths = Arrays.stream(data).mapToInt(v -> v.length).toArray();
    filter.populateElementFilters(data.length, null, lengths, Arrays.stream(lengths).sum());
    int[] nestedLenghts = Arrays.stream(data).flatMap(Arrays::stream).mapToInt(v -> v.length).toArray();
    ((ListFilter) filter.getChild()).populateElementFilters(Arrays.stream(lengths).sum(), null, nestedLenghts, Arrays.stream(nestedLenghts).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) Arrays(java.util.Arrays) 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

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