aokolnychyi commented on code in PR #7565:
URL: https://github.com/apache/iceberg/pull/7565#discussion_r1194613874
##########
spark/v3.4/spark/src/main/java/org/apache/iceberg/spark/actions/RewritePositionDeleteFilesSparkAction.java:
##########
@@ -133,55 +133,59 @@ public RewritePositionDeleteFiles.Result execute() {
}
}
- private Map<StructLike, List<List<PositionDeletesScanTask>>>
planFileGroups() {
- Table deletesTable =
- MetadataTableUtils.createMetadataTableInstance(table,
MetadataTableType.POSITION_DELETES);
- CloseableIterable<PositionDeletesScanTask> scanTasks =
- CloseableIterable.transform(
- deletesTable.newBatchScan().ignoreResiduals().planFiles(),
- t -> (PositionDeletesScanTask) t);
+ private StructLikeMap<List<List<PositionDeletesScanTask>>> planFileGroups() {
+ CloseableIterable<PositionDeletesScanTask> fileTasks = planFiles();
try {
StructType partitionType = Partitioning.partitionType(table);
- StructLikeMap<List<PositionDeletesScanTask>> filesByPartition =
- StructLikeMap.create(partitionType);
-
- for (PositionDeletesScanTask task : scanTasks) {
- StructLike coerced = coercePartition(task, partitionType);
-
- List<PositionDeletesScanTask> partitionTasks =
filesByPartition.get(coerced);
- if (partitionTasks == null) {
- partitionTasks = Lists.newArrayList();
- }
- partitionTasks.add(task);
- filesByPartition.put(coerced, partitionTasks);
- }
+ StructLikeMap<List<PositionDeletesScanTask>> fileTasksByPartition =
+ filesByPartition(partitionType, fileTasks);
- StructLikeMap<List<List<PositionDeletesScanTask>>> fileGroupsByPartition
=
- StructLikeMap.create(partitionType);
-
- filesByPartition.forEach(
- (partition, partitionTasks) -> {
- Iterable<List<PositionDeletesScanTask>> plannedFileGroups =
- rewriter.planFileGroups(partitionTasks);
- List<List<PositionDeletesScanTask>> groups =
ImmutableList.copyOf(plannedFileGroups);
- if (groups.size() > 0) {
- fileGroupsByPartition.put(partition, groups);
- }
- });
-
- return fileGroupsByPartition;
+ return fileGroupsByPartition(fileTasksByPartition);
} finally {
try {
- scanTasks.close();
+ fileTasks.close();
} catch (IOException io) {
LOG.error("Cannot properly close file iterable while planning for
rewrite", io);
}
}
}
- @VisibleForTesting
- RewritePositionDeletesGroup rewriteDeleteFiles(
+ private CloseableIterable<PositionDeletesScanTask> planFiles() {
+ Table deletesTable =
+ MetadataTableUtils.createMetadataTableInstance(table,
MetadataTableType.POSITION_DELETES);
+
+ return CloseableIterable.transform(
+ deletesTable.newBatchScan().ignoreResiduals().planFiles(),
+ t -> (PositionDeletesScanTask) t);
+ }
+
+ private StructLikeMap<List<PositionDeletesScanTask>> filesByPartition(
Review Comment:
Optional: What about calling it `groupByPartition`?
--
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]