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

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

                Author: ASF GitHub Bot
            Created on: 03/May/23 10:51
            Start Date: 03/May/23 10:51
    Worklog Time Spent: 10m 
      Work Description: zhangbutao commented on code in PR #4216:
URL: https://github.com/apache/hive/pull/4216#discussion_r1183529581


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java:
##########
@@ -676,6 +678,35 @@ public void 
executeOperation(org.apache.hadoop.hive.ql.metadata.Table hmsTable,
     }
   }
 
+  @Override
+  public void createBranchOperation(org.apache.hadoop.hive.ql.metadata.Table 
hmsTable,
+      AlterTableCreateBranchSpec createBranchSpec) {
+    TableDesc tableDesc = Utilities.getTableDesc(hmsTable);
+    Table icebergTable = IcebergTableUtil.getTable(conf, 
tableDesc.getProperties());
+
+    String branchName = createBranchSpec.getBranchName();
+    Optional.ofNullable(icebergTable.currentSnapshot()).orElseThrow(() -> new 
UnsupportedOperationException(
+        String.format("Cannot create branch %s on iceberg table %s.%s which 
has no snapshot",
+            branchName, hmsTable.getDbName(), hmsTable.getTableName())));
+    Long snapshotId = Optional.ofNullable(createBranchSpec.getSnapshotId())
+        .orElse(icebergTable.currentSnapshot().snapshotId());
+    LOG.info("Creating branch {} on iceberg table {}.{}", branchName, 
hmsTable.getDbName(),
+        hmsTable.getTableName());
+    ManageSnapshots manageSnapshots = icebergTable.manageSnapshots();
+    manageSnapshots.createBranch(branchName, snapshotId);

Review Comment:
   If user omits ` snapshotId ` when creating branch, then current snapshotId 
will be used.
   if user passes a non-existent `snapshotId` when creating branch, exception 
`unknown snapshot` will be thrown from iceberg lib.





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

    Worklog Id:     (was: 860287)
    Time Spent: 6h 10m  (was: 6h)

> Iceberg:  CREATE BRANCH SQL implementation
> ------------------------------------------
>
>                 Key: HIVE-27234
>                 URL: https://issues.apache.org/jira/browse/HIVE-27234
>             Project: Hive
>          Issue Type: Sub-task
>          Components: Iceberg integration
>            Reporter: zhangbutao
>            Assignee: zhangbutao
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 6h 10m
>  Remaining Estimate: 0h
>
> Maybe we can follow spark sql about branch ddl implementation 
> [https://github.com/apache/iceberg/pull/6617]



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to