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


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/compaction/IcebergMajorQueryCompactor.java:
##########
@@ -68,7 +84,38 @@ public boolean run(CompactorContext context) throws 
IOException, HiveException,
       Map<String, String> partSpecMap = new LinkedHashMap<>();
       Warehouse.makeSpecFromName(partSpecMap, new Path(partSpec), null);
 
-      List<FieldSchema> partitionKeys = 
table.getStorageHandler().getPartitionKeys(table);
+      Table icebergTable = IcebergTableUtil.getTable(conf, table.getTTable());
+      Expression expression = 
IcebergTableUtil.generateExpressionFromPartitionSpec(icebergTable, partSpecMap);
+      PartitionsTable partitionsTable = (PartitionsTable) MetadataTableUtils
+          .createMetadataTableInstance(icebergTable, 
MetadataTableType.PARTITIONS);
+      List<Pair<PartitionData, Integer>> partitionList = Lists.newArrayList();
+      try (CloseableIterable<FileScanTask> fileScanTasks = 
partitionsTable.newScan().planFiles()) {
+        fileScanTasks.forEach(task ->
+            
partitionList.addAll(Sets.newHashSet(CloseableIterable.transform(task.asDataTask().rows(),
 row -> {
+              StructProjection data = row.get(IcebergTableUtil.PART_IDX, 
StructProjection.class);
+              Integer specId = row.get(IcebergTableUtil.SPEC_IDX, 
Integer.class);
+              return Pair.of(IcebergTableUtil
+                  .toPartitionData(data, 
Partitioning.partitionType(icebergTable),
+                      icebergTable.specs().get(specId).partitionType()), 
specId);
+            })).stream()
+                .filter(pair -> {
+                  ResidualEvaluator resEval = 
ResidualEvaluator.of(icebergTable.specs().get(pair.second()),
+                      expression, false);
+                  return 
resEval.residualFor(pair.first()).isEquivalentTo(Expressions.alwaysTrue()) &&
+                      pair.first().size() == partSpecMap.size();
+                })
+                .collect(Collectors.toSet())));
+      }
+
+      if (partitionList.isEmpty()) {
+        throw new HiveException("Invalid partition spec, no corresponding 
spec_id found");
+      }
+
+      int specId = partitionList.get(0).second();

Review Comment:
   Done



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