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



##########
File path: data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
##########
@@ -139,39 +139,80 @@ protected long pos(T record) {
           CloseableIterable.transform(CloseableIterable.concat(deleteRecords), 
Record::copy),
           deleteSchema.asStruct());
 
-      Predicate<T> isInDeleteSet = record -> 
deleteSet.contains(projectRow.wrap(asStructLike(record)));
-      isInDeleteSets.add(isInDeleteSet);
+      isDeleted = isDeleted.or(record -> 
deleteSet.contains(projectRow.wrap(asStructLike(record))));
     }
 
-    return isInDeleteSets;
+    return isDeleted;
   }
 
-  public CloseableIterable<T> findEqualityDeleteRows(CloseableIterable<T> 
records) {
+  private Predicate<T> buildPosDeletePredicate() {
+    if (posDeletes.isEmpty()) {
+      return null;
+    }
+
+    List<CloseableIterable<Record>> deletes = Lists.transform(posDeletes, 
this::openPosDeletes);
+    Set<Long> deleteSet = Deletes.toPositionSet(dataFile.path(), 
CloseableIterable.concat(deletes));
+    if (deleteSet.isEmpty()) {
+      return null;
+    }
+
+    return record -> deleteSet.contains(pos(record));
+  }
+
+  public CloseableIterable<T> keepRowsFromDeletes(CloseableIterable<T> 
records) {
+    return 
CloseableIterable.concat(Lists.newArrayList(keepRowsFromPosDeletes(records),
+        keepRowsFromEqualityDeletes(records)));
+  }
+
+  public CloseableIterable<T> keepRowsFromEqualityDeletes(CloseableIterable<T> 
records) {
     // Predicate to test whether a row has been deleted by equality deletions.
-    Predicate<T> deletedRows = applyEqDeletes().stream()
-        .reduce(Predicate::or)
-        .orElse(t -> false);
+    Predicate<T> predicate = buildEqDeletePredicate();
+    if (predicate == null) {
+      return CloseableIterable.empty();
+    }
 
     Filter<T> deletedRowsFilter = new Filter<T>() {
       @Override
       protected boolean shouldKeep(T item) {
-        return deletedRows.test(item);
+        return predicate.test(item);
       }
     };
     return deletedRowsFilter.filter(records);
   }
 
+  public CloseableIterable<T> keepRowsFromPosDeletes(CloseableIterable<T> 
records) {
+    // if there are fewer deletes than a reasonable number to keep in memory, 
use a set
+    if (posDeletes.stream().mapToLong(DeleteFile::recordCount).sum() < 
setFilterThreshold) {
+      // Predicate to test whether a row has been deleted by equality 
deletions.
+      Predicate<T> predicate = buildPosDeletePredicate();
+      if (predicate == null) {
+        return CloseableIterable.empty();
+      }
+
+      Filter<T> deletedRowsFilter = new Filter<T>() {
+        @Override
+        protected boolean shouldKeep(T item) {
+          return predicate.test(item);
+        }
+      };
+      return deletedRowsFilter.filter(records);
+    } else {
+      List<CloseableIterable<Record>> deletes = Lists.transform(posDeletes, 
this::openPosDeletes);
+      return Deletes.streamingSelector(records, this::pos, 
Deletes.deletePositions(dataFile.path(), deletes));
+    }
+  }
+
   private CloseableIterable<T> applyEqDeletes(CloseableIterable<T> records) {
     // Predicate to test whether a row should be visible to user after 
applying equality deletions.
-    Predicate<T> remainingRows = applyEqDeletes().stream()
-        .map(Predicate::negate)
-        .reduce(Predicate::and)
-        .orElse(t -> true);
+    Predicate<T> predicate = buildEqDeletePredicate();

Review comment:
       I think it would be more clear if this were named `isDeleted`.




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