You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2020/08/11 10:08:18 UTC

[GitHub] [iceberg] JingsongLi commented on a change in pull request #1309: Add set-based equality and position filters

JingsongLi commented on a change in pull request #1309:
URL: https://github.com/apache/iceberg/pull/1309#discussion_r468469651



##########
File path: core/src/main/java/org/apache/iceberg/deletes/Deletes.java
##########
@@ -50,9 +54,47 @@
   private Deletes() {
   }
 
-  public static <T> CloseableIterable<T> positionFilter(CloseableIterable<T> rows, Function<T, Long> rowToPosition,
-                                                        CloseableIterable<Long> posDeletes) {
-    return new PositionDeleteFilter<>(rows, rowToPosition, posDeletes);
+  public static <T> CloseableIterable<T> equalitySetFilter(CloseableIterable<T> rows,
+                                                           Function<T, StructLike> rowToDeleteKey,
+                                                           Types.StructType eqType,
+                                                           CloseableIterable<StructLike> eqDeletes) {
+    try (CloseableIterable<StructLike> deletes = eqDeletes) {
+      CloseableIterator<StructLike> eqDeleteIterator = deletes.iterator();
+      if (eqDeleteIterator.hasNext()) {
+        StructLikeSet deleteSet = StructLikeSet.create(eqType);

Review comment:
       Maybe this set can be reused? A set gets bigger and bigger in merging?
   So can we have a method like `addAll(CloseableIterable<StructLike>)` in `StructLikeSet`?

##########
File path: core/src/main/java/org/apache/iceberg/deletes/Deletes.java
##########
@@ -50,9 +54,47 @@
   private Deletes() {
   }
 
-  public static <T> CloseableIterable<T> positionFilter(CloseableIterable<T> rows, Function<T, Long> rowToPosition,
-                                                        CloseableIterable<Long> posDeletes) {
-    return new PositionDeleteFilter<>(rows, rowToPosition, posDeletes);
+  public static <T> CloseableIterable<T> equalitySetFilter(CloseableIterable<T> rows,
+                                                           Function<T, StructLike> rowToDeleteKey,
+                                                           Types.StructType eqType,
+                                                           CloseableIterable<StructLike> eqDeletes) {
+    try (CloseableIterable<StructLike> deletes = eqDeletes) {
+      CloseableIterator<StructLike> eqDeleteIterator = deletes.iterator();
+      if (eqDeleteIterator.hasNext()) {
+        StructLikeSet deleteSet = StructLikeSet.create(eqType);
+        Iterators.addAll(deleteSet, eqDeleteIterator);
+        EqualitySetDeleteFilter<T> equalityFilter = new EqualitySetDeleteFilter<>(rowToDeleteKey, deleteSet);
+        return equalityFilter.filter(rows);
+      } else {
+        return rows;
+      }
+    } catch (IOException e) {
+      throw new UncheckedIOException("Failed to close equality delete source", e);
+    }
+  }
+
+  public static <T> CloseableIterable<T> positionSetFilter(CloseableIterable<T> rows,
+                                                           Function<T, Long> rowToPosition,
+                                                           CloseableIterable<Long> posDeletes) {
+    try (CloseableIterable<Long> deletes = posDeletes) {

Review comment:
       Can we have a static method `toLongSet`(We can optimize it to primitive long set in future) in `CloseableIterable`(Or some other places)?




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org