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



##########
File path: core/src/main/java/org/apache/iceberg/io/BaseTaskWriter.java
##########
@@ -75,6 +81,135 @@ public WriteResult complete() throws IOException {
         .build();
   }
 
+  /**
+   * Base equality delta writer to write both insert records and 
equality-deletes.
+   */
+  protected abstract class BaseEqualityDeltaWriter implements Closeable {
+    private final StructProjection structProjection;
+    private RollingFileWriter dataWriter;
+    private RollingEqDeleteWriter eqDeleteWriter;
+    private SortedPosDeleteWriter<T> posDeleteWriter;
+    private Map<StructLike, PathOffset> insertedRowMap;
+
+    public BaseEqualityDeltaWriter(PartitionKey partition, Schema schema, 
Schema deleteSchema) {
+      Preconditions.checkNotNull(schema, "Iceberg table schema cannot be 
null.");
+      Preconditions.checkNotNull(deleteSchema, "Equality-delete schema cannot 
be null.");
+      this.structProjection = StructProjection.create(schema, deleteSchema);
+
+      this.dataWriter = new RollingFileWriter(partition);
+
+      this.eqDeleteWriter = new RollingEqDeleteWriter(partition);
+      this.insertedRowMap = StructLikeMap.create(deleteSchema.asStruct());
+
+      this.posDeleteWriter = new SortedPosDeleteWriter<>(appenderFactory, 
fileFactory, format, partition);
+    }
+
+    /**
+     * Make the generic data could be read as a {@link StructLike}.
+     */
+    protected abstract StructLike asStructLike(T data);
+
+    public void write(T row) throws IOException {
+      PathOffset pathOffset = PathOffset.of(dataWriter.currentPath(), 
dataWriter.currentRows());
+
+      StructLike copiedKey = structProjection.copy().wrap(asStructLike(row));
+      // Adding a pos-delete to replace the old path-offset.
+      PathOffset previous = insertedRowMap.put(copiedKey, pathOffset);

Review comment:
       Finally, I decided to introduce the `asCopiedStructLike`.  People don't 
have to care how to use it inside the `BaseEqualityDeltaWriter`,  just need to 
know we need to implement it as a totally new StructLike which won't effect the 
old one.




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