chenjunjiedada commented on a change in pull request #2320:
URL: https://github.com/apache/iceberg/pull/2320#discussion_r592940864
##########
File path: data/src/main/java/org/apache/iceberg/data/DeleteFilter.java
##########
@@ -110,6 +113,41 @@ protected long pos(T record) {
return applyEqDeletes(applyPosDeletes(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);
+ }
+
+ List<Predicate<T>> deleteSetFilters = Lists.newArrayList();
+ 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());
+
+ Predicate<T> predicate = record ->
deleteSet.contains(projectRow.wrap(asStructLike(record)));
+ deleteSetFilters.add(predicate);
+ }
Review comment:
The patch looks great! I applied it.
----------------------------------------------------------------
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]