pvary commented on code in PR #18198:
URL: https://github.com/apache/iceberg/pull/18198#discussion_r4063840850
##########
core/src/main/java/org/apache/iceberg/encryption/InputFilesDecryptor.java:
##########
@@ -18,51 +18,80 @@
*/
package org.apache.iceberg.encryption;
-import java.nio.ByteBuffer;
-import java.util.Collections;
+import java.util.Collection;
import java.util.Map;
-import java.util.stream.Stream;
import org.apache.iceberg.CombinedScanTask;
+import org.apache.iceberg.ContentFile;
+import org.apache.iceberg.DeleteFile;
import org.apache.iceberg.FileScanTask;
import org.apache.iceberg.io.FileIO;
import org.apache.iceberg.io.InputFile;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+/** Resolves the files referenced by scan tasks into readable, decrypted
{@link InputFile}s. */
public class InputFilesDecryptor {
- private final Map<String, InputFile> decryptedInputFiles;
+ private final Iterable<? extends ContentFile<?>> referencedFiles;
+ private final EncryptingFileIO encryptingIO;
+ private Map<String, InputFile> lazyInputFiles = null;
+ /**
+ * @deprecated since 1.12.0, will be removed in 1.13.0; use {@link
#fromTasks(Iterable,
+ * EncryptingFileIO)} instead.
+ */
+ @Deprecated
public InputFilesDecryptor(
CombinedScanTask combinedTask, FileIO io, EncryptionManager encryption) {
- Map<String, ByteBuffer> keyMetadata = Maps.newHashMap();
- combinedTask.files().stream()
- .flatMap(
- fileScanTask ->
- Stream.concat(Stream.of(fileScanTask.file()),
fileScanTask.deletes().stream()))
- .forEach(file -> keyMetadata.put(file.location(), file.keyMetadata()));
- Stream<EncryptedInputFile> encrypted =
- keyMetadata.entrySet().stream()
- .map(
- entry ->
- EncryptedFiles.encryptedInput(
- io.newInputFile(entry.getKey()), entry.getValue()));
+ this(
+ () -> referencedFiles(combinedTask.files()).iterator(),
+ EncryptingFileIO.combine(io, encryption));
+ }
+
+ public static InputFilesDecryptor fromTasks(
+ Iterable<FileScanTask> tasks, EncryptingFileIO encryptingIO) {
+ return new InputFilesDecryptor(() -> referencedFiles(tasks).iterator(),
encryptingIO);
+ }
+
+ private InputFilesDecryptor(
+ Iterable<? extends ContentFile<?>> files, EncryptingFileIO encryptingIO)
{
+ this.referencedFiles = files;
+ this.encryptingIO = encryptingIO;
+ }
+
+ private Map<String, InputFile> inputFiles() {
+ if (lazyInputFiles == null) {
+ this.lazyInputFiles = encryptingIO.bulkDecrypt(referencedFiles);
Review Comment:
Do we need to synchronize this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]