diff --git a/core/src/main/java/org/apache/iceberg/deletes/Deletes.java b/core/src/main/java/org/apache/iceberg/deletes/Deletes.java index 25047bc173e9..a727cf8623ce 100644 --- a/core/src/main/java/org/apache/iceberg/deletes/Deletes.java +++ b/core/src/main/java/org/apache/iceberg/deletes/Deletes.java @@ -147,11 +147,15 @@ public static CharSequenceMap toPosi CharSequenceMap indexes = CharSequenceMap.create(); try (CloseableIterable deletes = posDeletes) { + String lastFilePath = null; + PositionDeleteIndex index = null; for (T delete : deletes) { CharSequence filePath = (CharSequence) FILENAME_ACCESSOR.get(delete); long position = (long) POSITION_ACCESSOR.get(delete); - PositionDeleteIndex index = - indexes.computeIfAbsent(filePath, key -> new BitmapPositionDeleteIndex(file)); + if (lastFilePath == null || !lastFilePath.equals(filePath)) { + lastFilePath = filePath.toString(); + index = indexes.computeIfAbsent(filePath, key -> new BitmapPositionDeleteIndex(file)); + } index.delete(position); } } catch (IOException e) {