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