zhangbutao commented on code in PR #4641:
URL: https://github.com/apache/hive/pull/4641#discussion_r1312526880


##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/execute/AlterTableExecuteAnalyzer.java:
##########
@@ -124,6 +126,11 @@ protected void analyzeCommand(TableName tableName, 
Map<String, String> partition
       AlterTableExecuteSpec spec =
           new AlterTableExecuteSpec(FAST_FORWARD, new 
FastForwardSpec(branchName, targetBranchName));
       desc = new AlterTableExecuteDesc(tableName, partitionSpec, spec);
+    } else if (HiveParser.KW_CHERRY_PICK == executeCommandType.getType()) {
+      ASTNode child = (ASTNode) command.getChild(1);
+      long snapshotId = Long.parseLong(child.getText());
+      AlterTableExecuteSpec spec = new AlterTableExecuteSpec(CHERRY_PICK, new 
CherryPickSpec(snapshotId));
+      desc = new AlterTableExecuteDesc(tableName, partitionSpec, spec);

Review Comment:
   I see each `else if` clause has partial same code snippet. e.g.
   `ASTNode child = (ASTNode) command.getChild(1);`
   and
   ` desc = new AlterTableExecuteDesc(tableName, partitionSpec, spec);`
   
   Could we extract these common logic to make code more cleaner?



##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergCherryPick.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iceberg.mr.hive;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import static org.apache.iceberg.mr.hive.TestTables.TestTableType.HIVE_CATALOG;
+import static org.junit.Assert.assertEquals;
+
+public class TestHiveIcebergCherryPick {
+
+  private TestTables testTables;
+  private TestHiveShell shell;
+  private TemporaryFolder temp = new TemporaryFolder();
+
+  @Before
+  public void before() throws IOException {
+    shell = HiveIcebergStorageHandlerTestUtils.shell();
+    temp.create();
+    testTables = HiveIcebergStorageHandlerTestUtils.testTables(shell, 
HIVE_CATALOG, temp);
+    HiveIcebergStorageHandlerTestUtils.init(shell, testTables, temp, "tez");
+  }
+
+  @After
+  public void after() throws Exception {
+    HiveIcebergStorageHandlerTestUtils.close(shell);
+  }
+
+  @Test
+  public void testCherryPick() {
+    TableIdentifier identifier = TableIdentifier.of("default", 
"testCherryPick");
+    shell.executeStatement(String.format("CREATE EXTERNAL TABLE %s (id INT) 
STORED BY iceberg  %s %s",
+            identifier.name(),
+            testTables.locationForCreateTableSQL(identifier),
+            testTables.propertiesForCreateTableSQL(ImmutableMap.of())));
+
+    shell.executeStatement(String.format("INSERT INTO TABLE %s 
VALUES(1),(2),(3),(4)", identifier.name()));
+
+    org.apache.iceberg.Table icebergTable = testTables.loadTable(identifier);
+    long id1 = icebergTable.currentSnapshot().snapshotId();
+
+    // make 2 new inserts to the main branch
+    shell.executeStatement(String.format("INSERT INTO TABLE %s VALUES(5),(6)", 
identifier.name()));
+    shell.executeStatement(String.format("INSERT INTO TABLE %s VALUES(7),(8)", 
identifier.name()));
+
+    icebergTable.refresh();
+    long id2 = icebergTable.currentSnapshot().snapshotId();
+
+    Assert.assertNotEquals(id1, id2);
+
+    // Rollback to the previous id before inserts.

Review Comment:
   This comment seems to be unclear. I only see `rollback `and do not see 
`insert `after `rollback`.



##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java:
##########
@@ -1400,7 +1405,7 @@ private static boolean 
hasParquetNestedTypeWithinListOrMap(Properties tableProps
    * Generates {@link JobContext}s for the OutputCommitter for the specific 
table.
    * @param configuration The configuration used for as a base of the JobConf
    * @param tableName The name of the table we are planning to commit
-   * @param overwrite If we have to overwrite the existing table or just add 
the new data
+   * @param branchName If we have to overwrite the existing table or just add 
the new data

Review Comment:
   Need to change the description of `branchName`.



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