openinx commented on a change in pull request #2216:
URL: https://github.com/apache/iceberg/pull/2216#discussion_r589140285



##########
File path: data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
##########
@@ -110,7 +110,44 @@ protected long pos(T record) {
     return applyEqDeletes(applyPosDeletes(records));
   }
 
-  private CloseableIterable<T> applyEqDeletes(CloseableIterable<T> records) {
+  public CloseableIterable<T> matchEqDeletes(CloseableIterable<T> records) {
+    if (eqDeletes.isEmpty()) {
+      return records;
+    }
+
+    Multimap<Set<Integer>, DeleteFile> filesByDeleteIds = 
Multimaps.newMultimap(Maps.newHashMap(), Lists::newArrayList);
+    for (DeleteFile delete : eqDeletes) {
+      filesByDeleteIds.put(Sets.newHashSet(delete.equalityFieldIds()), delete);
+    }
+
+    CloseableIterable<T> remainRecords = records;
+    CloseableIterable<T> matchedRecords = CloseableIterable.empty();
+    for (Map.Entry<Set<Integer>, Collection<DeleteFile>> entry : 
filesByDeleteIds.asMap().entrySet()) {
+      Set<Integer> ids = entry.getKey();
+      Iterable<DeleteFile> deletes = entry.getValue();
+
+      Schema deleteSchema = TypeUtil.select(requiredSchema, ids);
+
+      // a projection to select and reorder fields of the file schema to match 
the delete rows
+      StructProjection projectRow = StructProjection.create(requiredSchema, 
deleteSchema);
+
+      Iterable<CloseableIterable<Record>> deleteRecords = 
Iterables.transform(deletes,
+          delete -> openDeletes(delete, deleteSchema));
+      StructLikeSet deleteSet = Deletes.toEqualitySet(
+          // copy the delete records because they will be held in a set
+          CloseableIterable.transform(CloseableIterable.concat(deleteRecords), 
Record::copy),
+          deleteSchema.asStruct());
+
+      matchedRecords = 
CloseableIterable.concat(Lists.newArrayList(matchedRecords, 
Deletes.match(remainRecords,

Review comment:
       > I think it would not iterate the data set several times since these 
are iterable chains and should be computed lazily.
   
   That's incorrect,  to analysis the complexity, we only need to consider the 
key sentence: 
   
   ```java
   Deletes.match(remainRecords, record -> 
projectRow.wrap(asStructLike(record)), deleteSet)
   ```
   
   The final returned `matchedRecords` is composed by several  above `Iterable` 
(s).  When iterate this `Iterable`,  we will scan all the elements in 
`remainRecords`,   finally we will scan the original data set multiple times.   
That's why I said the complexity is too high.




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