difin commented on code in PR #5328:
URL: https://github.com/apache/hive/pull/5328#discussion_r1688387338


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/compaction/IcebergMajorQueryCompactor.java:
##########
@@ -63,20 +63,33 @@ public boolean run(CompactorContext context) throws 
IOException, HiveException,
 
     HiveConf conf = new HiveConf(context.getConf());
     String partSpec = context.getCompactionInfo().partName;
+    org.apache.hadoop.hive.ql.metadata.Table table = 
Hive.get(conf).getTable(context.getTable().getDbName(),
+        context.getTable().getTableName());
+    Table icebergTable = IcebergTableUtil.getTable(conf, table.getTTable());
     String compactionQuery;
 
     if (partSpec == null) {
-      HiveConf.setVar(conf, ConfVars.REWRITE_POLICY, 
RewritePolicy.ALL_PARTITIONS.name());
-      compactionQuery = String.format("insert overwrite table %s select * from 
%<s", compactTableName);
+      if (!IcebergTableUtil.isPartitioned(icebergTable)) {
+        HiveConf.setVar(conf, ConfVars.REWRITE_POLICY, 
RewritePolicy.ALL_PARTITIONS.name());
+        compactionQuery = String.format("insert overwrite table %s select * 
from %<s", compactTableName);
+      } else if (icebergTable.specs().size() > 1) {
+        // Compacting partitions of old partition specs on a partitioned table 
with partition evolution
+        HiveConf.setVar(conf, ConfVars.REWRITE_POLICY, 
RewritePolicy.PARTITION.name());
+        conf.set(IcebergCompactionService.PARTITION_SPEC_ID, 
String.valueOf(icebergTable.spec().specId()));
+        // A single filter on a virtual column causes errors during 
compilation,
+        // added another filter on file_path as a workaround.
+        compactionQuery = String.format("insert overwrite table %1$s select * 
from %1$s " +
+                "where %2$s != %3$d and %4$s is not null",
+            compactTableName, VirtualColumn.PARTITION_SPEC_ID.getName(), 
icebergTable.spec().specId(),
+            VirtualColumn.FILE_PATH.getName());
+      } else {
+        return true;

Review Comment:
   Yes, agreed, added a comment and an exception



-- 
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: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to