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


##########
ql/src/java/org/apache/hadoop/hive/ql/parse/rewrite/sql/NonNativeAcidMultiInsertSqlGenerator.java:
##########
@@ -51,16 +52,27 @@ public void 
appendAcidSelectColumnsForDeletedRecords(Operation operation, boolea
   @Override
   public void appendAcidSelectColumnsForDeletedRecords(
       Operation operation, boolean skipPrefix, String deletedRowIdExpr) {
-    appendAcidSelectColumns(operation, true, skipPrefix, deletedRowIdExpr);
+    appendAcidSelectColumns(
+        targetTable.getStorageHandler().acidSelectColumns(targetTable, 
operation), true, skipPrefix, deletedRowIdExpr);
   }
 
-  private void appendAcidSelectColumns(
-      Operation operation, boolean markRowIdAsDeleted, boolean skipPrefix, 
String deletedRowIdExpr) {
-    List<FieldSchema> acidSelectColumns = 
targetTable.getStorageHandler().acidSelectColumns(targetTable, operation);
+  @Override
+  public void appendDeletedRecordColumns() {
+    appendAcidSelectColumns(deletedRecordColumns(), false, false, "-1");
+  }
+
+  // the virtual columns that identify a deleted record in merge-on-read
+  private List<FieldSchema> deletedRecordColumns() {
+    return targetTable.getStorageHandler().acidVirtualColumns().stream()

Review Comment:
   This bypasses the public handler's DELETE projection, so a handler that 
needs data columns receives a truncated record (or an empty SELECT if it 
registers no virtual columns). Add an opt-in deleted-record projection that 
defaults to `acidSelectColumns(table, DELETE)`, and let Iceberg return its four 
virtual columns. Use the same hook in `MultiInsertSqlGenerator.java:118` and 
`NonNativeAcidMaterializedViewASTBuilder.java:73`.



##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java:
##########
@@ -449,7 +447,7 @@ public DecomposedPredicate decomposePredicate(JobConf 
jobConf, Deserializer dese
 
     List<ExprNodeDesc> subExprNodes = pushedPredicate.getChildren();
     Set<String> skipList =
-        Stream.of(FILE_PATH, PARTITION_SPEC_ID, PARTITION_HASH, PARTITION_NAME,
+        Stream.of(FILE_PATH, PARTITION_SPEC_ID, PARTITION_KEY, PARTITION_NAME,

Review Comment:
   Removing the `PARTITION__KEY` child is only safe for an AND. For example, 
`WHERE PARTITION__KEY IS NOT NULL OR id = 1` is reduced here to the pushed 
predicate `id = 1`; Iceberg can then prune files containing other IDs even 
though every row satisfies the first disjunct. Keep the whole predicate 
residual when a non-AND expression contains a skipped virtual column, and only 
remove individual conjuncts.



##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/writer/HiveIcebergDeleteWriter.java:
##########
@@ -20,49 +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.conf.Configuration;
 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;
+  // deserialized partitions, by spec id and serialized partition
+  private final Map<Integer, Map<ByteBuffer, StructLike>> partitions;
 
   HiveIcebergDeleteWriter(
       Table table, Supplier<Map<String, DeleteFileSet>> rewritableDeletes, 
Configuration conf,
       HiveFileWriterFactory writerFactory, OutputFileFactory deleteFileFactory,
       Context context) {
     super(table, newDeleteWriter(table, rewritableDeletes, conf, 
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:
   This cache retains both the serialized key and decoded record for every 
distinct partition until the writer closes. A large delete over 
high-cardinality identity partitions therefore has task memory proportional to 
all partitions encountered, including the full string values, and can exhaust 
the task heap. Bound the cache or evict completed partitions; a miss can safely 
deserialize the key again.



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