deniskuzZ commented on code in PR #6925:
URL: https://github.com/apache/hive/pull/6925#discussion_r4700020092


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/writer/HiveIcebergDeleteWriter.java:
##########
@@ -20,47 +20,62 @@
 package org.apache.iceberg.mr.hive.writer;
 
 import java.io.IOException;
+import java.nio.ByteBuffer;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.function.Supplier;
 import org.apache.hadoop.io.Writable;
 import org.apache.iceberg.DeleteFile;
-import org.apache.iceberg.PartitionKey;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.StructLike;
 import org.apache.iceberg.Table;
-import org.apache.iceberg.data.GenericRecord;
 import org.apache.iceberg.data.Record;
-import org.apache.iceberg.deletes.PositionDelete;
 import org.apache.iceberg.io.DeleteWriteResult;
 import org.apache.iceberg.io.OutputFileFactory;
 import org.apache.iceberg.mr.hive.FilesForCommit;
 import org.apache.iceberg.mr.hive.IcebergAcidUtil;
 import org.apache.iceberg.mr.hive.writer.WriterBuilder.Context;
 import org.apache.iceberg.mr.mapred.Container;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Maps;
+import org.apache.iceberg.types.Type;
 import org.apache.iceberg.util.DeleteFileSet;
 
 class HiveIcebergDeleteWriter extends HiveIcebergWriterBase {
 
-  private final GenericRecord rowDataTemplate;
-  private final boolean isMergeTask;
+  // the partitions of the deleted records by spec and serialized partition
+  private final Map<Integer, Map<ByteBuffer, StructLike>> partitions;
 
   HiveIcebergDeleteWriter(
-      Table table, Map<String, DeleteFileSet> rewritableDeletes,
+      Table table, Supplier<Map<String, DeleteFileSet>> rewritableDeletes,
       HiveFileWriterFactory writerFactory, OutputFileFactory deleteFileFactory,
       Context context) {
     super(table, newDeleteWriter(table, rewritableDeletes, writerFactory, 
deleteFileFactory, context));
-
-    this.rowDataTemplate = GenericRecord.create(table.schema());
-    this.isMergeTask = context.isMergeTask();
+    this.partitions = Maps.newHashMapWithExpectedSize(specs.size());
   }
 
   @Override
   public void write(Writable row) throws IOException {
     Record rec = ((Container<Record>) row).get();
-    PositionDelete<Record> positionDelete = 
IcebergAcidUtil.getPositionDelete(rec, rowDataTemplate, isMergeTask);
-    int specId = IcebergAcidUtil.parseSpecId(rec);
-    PartitionKey partitionKey = isMergeTask ? 
IcebergAcidUtil.parsePartitionKey(rec) :
-        partition(rowDataTemplate, specId);
-    writer.write(positionDelete, specs.get(specId), partitionKey);
+    PartitionSpec spec = specs.get(IcebergAcidUtil.parseSpecId(rec));
+    StructLike partition = partitions.computeIfAbsent(spec.specId(), id -> 
newPartitionCache(spec))
+        .computeIfAbsent(IcebergAcidUtil.parseSerializedPartition(rec),
+            serialized -> IcebergAcidUtil.deserializePartition(serialized, 
spec));

Review Comment:
   The key can't change while it's in the map. For every row, the serde copies 
the partition bytes into a new array (LazyUtils.createByteArray → 
Arrays.copyOf), and IcebergBinaryObjectInspector.convert wraps that new array. 
Nothing else holds the buffer. Its only reader, 
IcebergAcidUtil.deserializePartition, gets the bytes through 
ByteBuffers.toByteArray, which never moves the buffer's position or limit. So 
hashCode and equals stay the same for as long as the key is in the map, and 
another copy would only add one allocation per row.             



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

To unsubscribe, e-mail: [email protected]

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