Search in sources :

Example 1 with MAP

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

Aggregations

RuntimeStats (com.facebook.presto.common.RuntimeStats)1 Subfield (com.facebook.presto.common.Subfield)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 Type (com.facebook.presto.common.type.Type)1 VARCHAR (com.facebook.presto.common.type.VarcharType.VARCHAR)1 AbstractOrcRecordReader.getDecryptionKeyMetadata (com.facebook.presto.orc.AbstractOrcRecordReader.getDecryptionKeyMetadata)1 AbstractTestOrcReader.intsBetween (com.facebook.presto.orc.AbstractTestOrcReader.intsBetween)1 DwrfEncryptionInfo.createNodeToGroupMap (com.facebook.presto.orc.DwrfEncryptionInfo.createNodeToGroupMap)1 NOOP_ORC_AGGREGATED_MEMORY_CONTEXT (com.facebook.presto.orc.NoopOrcAggregatedMemoryContext.NOOP_ORC_AGGREGATED_MEMORY_CONTEXT)1 DWRF (com.facebook.presto.orc.OrcEncoding.DWRF)1 MAX_BATCH_SIZE (com.facebook.presto.orc.OrcReader.MAX_BATCH_SIZE)1 OrcReader.validateEncryption (com.facebook.presto.orc.OrcReader.validateEncryption)1 HIVE_STORAGE_TIME_ZONE (com.facebook.presto.orc.OrcTester.HIVE_STORAGE_TIME_ZONE)1 MAX_BLOCK_SIZE (com.facebook.presto.orc.OrcTester.MAX_BLOCK_SIZE)1 OrcTester.assertFileContentsPresto (com.facebook.presto.orc.OrcTester.assertFileContentsPresto)1 OrcTester.rowType (com.facebook.presto.orc.OrcTester.rowType)1 OrcTester.writeOrcColumnsPresto (com.facebook.presto.orc.OrcTester.writeOrcColumnsPresto)1 StripeReader.getDiskRanges (com.facebook.presto.orc.StripeReader.getDiskRanges)1 StorageOrcFileTailSource (com.facebook.presto.orc.cache.StorageOrcFileTailSource)1 DEFAULT_SEQUENCE_ID (com.facebook.presto.orc.metadata.ColumnEncoding.DEFAULT_SEQUENCE_ID)1