rdblue commented on a change in pull request #2651:
URL: https://github.com/apache/iceberg/pull/2651#discussion_r651316675



##########
File path: core/src/main/java/org/apache/iceberg/deletes/Deletes.java
##########
@@ -246,4 +265,79 @@ protected boolean shouldKeep(T posDelete) {
       return CHARSEQ_COMPARATOR.compare(dataLocation, (CharSequence) 
FILENAME_ACCESSOR.get(posDelete)) == 0;
     }
   }
+
+  private static class PositionStreamDeleteChecker<T> extends CloseableGroup 
implements CloseableIterable<Optional<T>> {
+    private final CloseableIterable<T> rows;
+    private final Function<T, Long> extractPos;
+    private final CloseableIterable<Long> deletePositions;
+
+    private PositionStreamDeleteChecker(CloseableIterable<T> rows, Function<T, 
Long> extractPos,
+                                        CloseableIterable<Long> 
deletePositions) {
+      this.rows = rows;
+      this.extractPos = extractPos;
+      this.deletePositions = deletePositions;
+    }
+
+    @Override
+    public CloseableIterator<Optional<T>> iterator() {
+      CloseableIterator<Long> deletePosIterator = deletePositions.iterator();
+
+      CloseableIterator<Optional<T>> iter;
+      if (deletePosIterator.hasNext()) {
+        iter = new PositionCheckIterator(rows.iterator(), deletePosIterator);
+      } else {
+        iter = CloseableIterator.transform(rows.iterator(), 
Optional::ofNullable);
+        try {
+          deletePosIterator.close();
+        } catch (IOException e) {
+          throw new UncheckedIOException("Failed to close delete positions 
iterator", e);
+        }
+      }
+
+      addCloseable(iter);

Review comment:
       This should be done before trying to close `deletePosIterator` in the 
`else` block, or else failing to close the delete positions iterator could leak 
the open rows iterator.




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

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