rdblue commented on a change in pull request #1888:
URL: https://github.com/apache/iceberg/pull/1888#discussion_r539639585
##########
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:
Doesn't this have the problem you were talking about with using only
wrappers? If `asStructLike` uses a wrapper that is reused, then even if the key
is a new instance, the underlying data in the `StructLike` wrapper returned
will change on the next call to write.
I think instead of copying the projection, this needs to copy the result of
the projection into a new struct and add that to the map.
----------------------------------------------------------------
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]