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


##########
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:
   Valid, but it's not new in this PR: `decomposePredicate` is unchanged from 
master except that `PARTITION__HASH` became `PARTITION__KEY` in the skip list. 
The same problem affects every skipped virtual column under an OR. It's tracked 
in [HIVE-30252](https://issues.apache.org/jira/browse/HIVE-30252), which has a 
reproducer and this fix: remove only the conjuncts of a top-level AND, and push 
nothing when any other expression references a skipped column.
   



##########
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:
   Outdated: edfea71ad2 removed `appendDeletedRecordColumns` and 
`deletedRecordColumns()`. `DeleteRewriter` now gets its columns from the 
handler through `acidSelectColumns(table, MERGE)`, the same columns 
`appendDeleteBranch` uses for MERGE's delete branch. The javadoc on 
`HiveStorageHandler#acidSelectColumns` states the contract: a merge-on-read 
DELETE selects MERGE's columns, which must hold only the 
`acidVirtualColumns()`. Copy-on-write still selects the DELETE columns, which 
include the row data. `NonNativeAcidMaterializedViewASTBuilder` selects the 
`acidVirtualColumns()`, the same columns.
   



##########
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 doesn't change how memory grows. The Iceberg writer behind it already 
keeps every partition it has seen until it closes: the DV writer 
(`BaseDVFileWriter`) stores the partition it receives for each data file in 
`deletesByPath`, next to that file's position bitmap, and `ClusteredWriter` 
keeps `completedPartitions`. With the cache, those per-file entries share one 
decoded partition per distinct partition. Evicting and decoding again would 
give the DV writer one copy per data file instead, so a bounded cache would use 
more memory, not less. The cache adds only one `PARTITION__KEY` byte array per 
distinct partition.
   



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