rdblue commented on a change in pull request #2651:
URL: https://github.com/apache/iceberg/pull/2651#discussion_r651317476
##########
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);
+
+ return iter;
+ }
+
+ private class PositionCheckIterator extends CheckIterator<T> {
Review comment:
I think to keep this clean, we should rewrite `PositionFilterIterator`
so that it is based on this class. The `check` method here duplicates
`shouldKeep` in the filter and I don't think it is a good idea to have that
code duplicated.
--
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]