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



##########
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:
       I'm a little hesitant about the `asCopiedStructLike`,  because it 
introduces complexity to the compute engine developer, people need to consider 
in which case they need to use `asStructLike` other cases they need to use 
`asCopiedStructLike`.  Implementing the two abstracted method will need 
carefully coding.   So I'm thinking how about always copy the `StructLike`  ?   
see the flink implementation 
[here](https://github.com/apache/iceberg/pull/1896/files#diff-e497cabcc9fcf3b1edcd987693853c2dd578f0b3231d5a8f4c3b6f0338bf5e3cR95).
 
   
   The copy is light-weight because only few references copy ( from 
`RowDataWrapper` ).  That would simplify the abstracted methods design.




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