flyrain commented on code in PR #5248:
URL: https://github.com/apache/iceberg/pull/5248#discussion_r930272329


##########
spark/v3.3/spark/src/main/java/org/apache/iceberg/spark/source/BaseReader.java:
##########
@@ -137,21 +157,36 @@ public void close() throws IOException {
     }
   }
 
-  protected InputFile getInputFile(FileScanTask task) {
-    Preconditions.checkArgument(!task.isDataTask(), "Invalid task type");
-    return inputFiles.get(task.file().path().toString());
+  protected InputFile getInputFile(String location) {
+    return inputFiles().get(location);
   }
 
-  protected InputFile getInputFile(String location) {
-    return inputFiles.get(location);
+  private Map<String, InputFile> inputFiles() {
+    if (lazyInputFiles == null) {
+      Stream<EncryptedInputFile> encryptedFiles = taskGroup.tasks().stream()
+          .flatMap(this::referencedFiles)
+          .map(file ->
+              
EncryptedFiles.encryptedInput(table.io().newInputFile(file.path().toString()), 
file.keyMetadata()));
+
+      // decrypt with the batch call to avoid multiple RPCs to a key server, 
if possible
+      Iterable<InputFile> decryptedFiles = 
table.encryption().decrypt(encryptedFiles::iterator);
+
+      Map<String, InputFile> files = 
Maps.newHashMapWithExpectedSize(taskGroup.tasks().size());
+      decryptedFiles.forEach(decrypted -> 
files.putIfAbsent(decrypted.location(), decrypted));
+      this.lazyInputFiles = ImmutableMap.copyOf(files);
+    }
+
+    return lazyInputFiles;
   }
 
-  protected Map<Integer, ?> constantsMap(FileScanTask task, Schema readSchema) 
{
+  protected abstract Stream<ContentFile<?>> referencedFiles(TaskT task);
+
+  protected Map<Integer, ?> constantsMap(ContentScanTask<?> task, Schema 
readSchema) {
     if (readSchema.findField(MetadataColumns.PARTITION_COLUMN_ID) != null) {
-      StructType partitionType = Partitioning.partitionType(table);
-      return PartitionUtil.constantsMap(task, partitionType, 
BaseDataReader::convertConstant);
+      Types.StructType partitionType = Partitioning.partitionType(table);

Review Comment:
   No. Let me remove it.



-- 
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]

Reply via email to