SourabhBadhya commented on code in PR #4672:
URL: https://github.com/apache/hive/pull/4672#discussion_r1326900592


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java:
##########
@@ -597,12 +600,49 @@ public void 
rollbackAlterTable(org.apache.hadoop.hive.metastore.api.Table hmsTab
   }
 
   @Override
-  public void preTruncateTable(org.apache.hadoop.hive.metastore.api.Table 
table, EnvironmentContext context)
+  public void preTruncateTable(org.apache.hadoop.hive.metastore.api.Table 
table, EnvironmentContext context,
+      List<String> partNames)
       throws MetaException {
     this.catalogProperties = getCatalogProperties(table);
     this.icebergTable = Catalogs.loadTable(conf, catalogProperties);
+    Map<String, PartitionField> partitionFieldMap = Maps.newHashMap();
+    for (PartitionField partField : icebergTable.spec().fields()) {
+      partitionFieldMap.put(partField.name(), partField);
+    }
+    Expression finalExp = Expressions.alwaysTrue();
+    if (partNames != null && !partNames.isEmpty()) {

Review Comment:
   Done.



##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java:
##########
@@ -597,12 +600,49 @@ public void 
rollbackAlterTable(org.apache.hadoop.hive.metastore.api.Table hmsTab
   }
 
   @Override
-  public void preTruncateTable(org.apache.hadoop.hive.metastore.api.Table 
table, EnvironmentContext context)
+  public void preTruncateTable(org.apache.hadoop.hive.metastore.api.Table 
table, EnvironmentContext context,
+      List<String> partNames)
       throws MetaException {
     this.catalogProperties = getCatalogProperties(table);
     this.icebergTable = Catalogs.loadTable(conf, catalogProperties);
+    Map<String, PartitionField> partitionFieldMap = Maps.newHashMap();
+    for (PartitionField partField : icebergTable.spec().fields()) {
+      partitionFieldMap.put(partField.name(), partField);
+    }
+    Expression finalExp = Expressions.alwaysTrue();
+    if (partNames != null && !partNames.isEmpty()) {
+      for (String partName : partNames) {
+        String[] partColPairs = partName.split("/");
+        Expression subExp = Expressions.alwaysTrue();
+        for (String partColPair : partColPairs) {
+          String[] partColNameValue = partColPair.split("=");
+          assert partColNameValue.length == 2;
+          String partColName = partColNameValue[0];
+          String partColValue = partColNameValue[1];
+          if (partitionFieldMap.containsKey(partColName)) {
+            PartitionField partitionField = partitionFieldMap.get(partColName);
+            Type resultType = 
partitionField.transform().getResultType(icebergTable.schema()
+                    .findField(partitionField.sourceId()).type());
+            TransformSpec.TransformType transformType = 
IcebergTableUtil.getTransformType(partitionField.transform());
+            Object value = Conversions.fromPartitionString(resultType, 
partColValue);
+            Iterable iterable = () -> 
Collections.singletonList(value).iterator();
+            if (transformType.equals(TransformSpec.TransformType.IDENTITY)) {

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