[ 
https://issues.apache.org/jira/browse/HIVE-25234?focusedWorklogId=613161&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-613161
 ]

ASF GitHub Bot logged work on HIVE-25234:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 22/Jun/21 07:54
            Start Date: 22/Jun/21 07:54
    Worklog Time Spent: 10m 
      Work Description: pvary commented on a change in pull request #2382:
URL: https://github.com/apache/hive/pull/2382#discussion_r655272146



##########
File path: 
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java
##########
@@ -214,7 +219,7 @@ public void 
commitDropTable(org.apache.hadoop.hive.metastore.api.Table hmsTable,
   @Override
   public void preAlterTable(org.apache.hadoop.hive.metastore.api.Table 
hmsTable, EnvironmentContext context)
       throws MetaException {
-    super.preAlterTable(hmsTable, context);
+    setupAlterOperationType(hmsTable, context);

Review comment:
       We removed the `super.preAlterTable`. Is this intentional?

##########
File path: 
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/IcebergTableUtil.java
##########
@@ -106,4 +111,61 @@ public static PartitionSpec spec(Configuration 
configuration, Schema schema) {
     });
     return builder.build();
   }
+
+  public static void updateSpec(Configuration configuration, Table table) {
+    // get the new partition transform spec
+    PartitionSpec newPartitionSpec = spec(configuration, table.schema());
+    if (newPartitionSpec == null) {
+      LOG.debug("Iceberg Partition spec is not updated due to empty partition 
spec definition.");
+      return;
+    }
+
+    List<String> newPartitionNames =
+        
newPartitionSpec.fields().stream().map(PartitionField::name).collect(Collectors.toList());
+    List<String> currentPartitionNames = 
table.spec().fields().stream().map(PartitionField::name)
+        .collect(Collectors.toList());
+    List<String> intersectingPartitionNames =
+        
currentPartitionNames.stream().filter(newPartitionNames::contains).collect(Collectors.toList());
+
+    // delete those partitions which are not present among the new partion spec
+    UpdatePartitionSpec updatePartitionSpec = table.updateSpec();
+    currentPartitionNames.stream().filter(p -> 
!intersectingPartitionNames.contains(p))
+        .forEach(updatePartitionSpec::removeField);
+    updatePartitionSpec.apply();
+
+    // add new partitions which are not yet present
+    List<PartitionTransform.PartitionTransformSpec> partitionTransformSpecList 
= SessionStateUtil
+        .getResource(configuration, 
hive_metastoreConstants.PARTITION_TRANSFORM_SPEC)
+        .map(o -> (List<PartitionTransform.PartitionTransformSpec>) 
o).orElseGet(() -> null);
+    IntStream.range(0, partitionTransformSpecList.size())
+        .filter(i -> 
!intersectingPartitionNames.contains(newPartitionSpec.fields().get(i).name()))
+        .forEach(i -> {
+          PartitionTransform.PartitionTransformSpec spec = 
partitionTransformSpecList.get(i);
+          switch (spec.transformType) {

Review comment:
       This `switch` is very similar to the one where we are converting the 
json to the spec. Do we have a way to reuse code?

##########
File path: 
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergStorageHandlerNoScan.java
##########
@@ -155,6 +155,93 @@ public void after() throws Exception {
     HiveIcebergStorageHandlerTestUtils.close(shell);
   }
 
+  @Test
+  public void testPartitionEvolution() {

Review comment:
       What happens when I try to alter an HBase table with partition spec, or 
a normal Hive (non-Iceberg) table?




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

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


Issue Time Tracking
-------------------

    Worklog Id:     (was: 613161)
    Time Spent: 1h 50m  (was: 1h 40m)

> Implement ALTER TABLE ... SET PARTITION SPEC to change partitioning on 
> Iceberg tables
> -------------------------------------------------------------------------------------
>
>                 Key: HIVE-25234
>                 URL: https://issues.apache.org/jira/browse/HIVE-25234
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: László Pintér
>            Assignee: László Pintér
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 1h 50m
>  Remaining Estimate: 0h
>
> Provide a way to change the schema and the Iceberg partitioning specification 
> using Hive syntax.
> {code:sql}
> ALTER TABLE tbl SET PARTITION SPEC(...)
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to