ayushtkn commented on code in PR #4510:
URL: https://github.com/apache/hive/pull/4510#discussion_r1281801530
##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergBranchOperation.java:
##########
@@ -181,4 +181,20 @@ public void testCreateBranchWithNonIcebergTable() {
Assert.assertTrue(e.getMessage().contains("Not an iceberg table"));
}
}
+
+ @Test
+ public void testDropBranch() throws InterruptedException, IOException {
+ Table table =
+ testTables.createTableWithVersions(shell, "customers",
HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA,
+ fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS,
2);
+
+ String branchName = "test_branch_1";
+ shell.executeStatement(String.format("ALTER TABLE customers CREATE BRANCH
%s", branchName));
+ table.refresh();
+ Assert.assertTrue(table.refs().get(branchName) != null);
+
+ shell.executeStatement(String.format("ALTER TABLE customers DROP BRANCH IF
EXISTS %s", branchName));
+ table.refresh();
+ Assert.assertTrue(table.refs().get(branchName) == null);
Review Comment:
change to
```
Assert.assertNull(table.refs().get(branchName));
```
##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/snapshotref/AlterTableDropSnapshotRefAnalyzer.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.hadoop.hive.ql.ddl.table.snapshotref;
+
+import java.util.Map;
+import org.apache.hadoop.hive.common.TableName;
+import org.apache.hadoop.hive.ql.QueryState;
+import org.apache.hadoop.hive.ql.ddl.DDLUtils;
+import org.apache.hadoop.hive.ql.ddl.DDLWork;
+import org.apache.hadoop.hive.ql.ddl.table.AbstractAlterTableAnalyzer;
+import org.apache.hadoop.hive.ql.ddl.table.AbstractAlterTableDesc;
+import org.apache.hadoop.hive.ql.ddl.table.AlterTableType;
+import org.apache.hadoop.hive.ql.exec.TaskFactory;
+import org.apache.hadoop.hive.ql.hooks.ReadEntity;
+import org.apache.hadoop.hive.ql.metadata.Table;
+import org.apache.hadoop.hive.ql.parse.ASTNode;
+import org.apache.hadoop.hive.ql.parse.AlterTableSnapshotRefSpec;
+import org.apache.hadoop.hive.ql.parse.HiveParser;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+
+public class AlterTableDropSnapshotRefAnalyzer extends
AbstractAlterTableAnalyzer {
+ protected AlterTableType alterTableType;
+
+ public AlterTableDropSnapshotRefAnalyzer(QueryState queryState) throws
SemanticException {
+ super(queryState);
+ }
+
+ @Override
+ protected void analyzeCommand(TableName tableName, Map<String, String>
partitionSpec, ASTNode command)
+ throws SemanticException {
+ boolean ifExists = (command.getFirstChildWithType(HiveParser.TOK_IFEXISTS)
!= null);
+ Table table = getTable(tableName);
+ DDLUtils.validateTableIsIceberg(table);
+ inputs.add(new ReadEntity(table));
+ validateAlterTableType(table, alterTableType, false);
+ String refName = !ifExists ? command.getChild(0).getText() :
command.getChild(1).getText();
Review Comment:
can we have ```ifExists``` ? rather than ```!ifExists```, that would be more
readable
##########
iceberg/iceberg-handler/src/test/java/org/apache/iceberg/mr/hive/TestHiveIcebergBranchOperation.java:
##########
@@ -181,4 +181,20 @@ public void testCreateBranchWithNonIcebergTable() {
Assert.assertTrue(e.getMessage().contains("Not an iceberg table"));
}
}
+
+ @Test
+ public void testDropBranch() throws InterruptedException, IOException {
+ Table table =
+ testTables.createTableWithVersions(shell, "customers",
HiveIcebergStorageHandlerTestUtils.CUSTOMER_SCHEMA,
+ fileFormat, HiveIcebergStorageHandlerTestUtils.CUSTOMER_RECORDS,
2);
+
+ String branchName = "test_branch_1";
+ shell.executeStatement(String.format("ALTER TABLE customers CREATE BRANCH
%s", branchName));
+ table.refresh();
+ Assert.assertTrue(table.refs().get(branchName) != null);
Review Comment:
Change to
```
Assert.assertNotNull(table.refs().get(branchName));
```
##########
ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/HiveOperationType.java:
##########
@@ -141,6 +141,7 @@ public enum HiveOperationType {
ALTERTABLE_UPDATECOLUMNS,
ALTERTABLE_CREATEBRANCH,
ALTERTABLE_CREATETAG,
+ ALTERTABLE_DROPBRANCH,
Review Comment:
nit can we pull this up, to keep it together with create branch
##########
ql/src/java/org/apache/hadoop/hive/ql/parse/AlterTableSnapshotRefSpec.java:
##########
@@ -89,9 +89,32 @@ public CreateSnapshotRefSpec(String refName, Long
snapShotId, Long asOfTime, Lon
}
public String toString() {
- return MoreObjects.toStringHelper(this).add("branchName",
refName).add("snapshotId", snapshotId)
+ return MoreObjects.toStringHelper(this).add("refName",
refName).add("snapshotId", snapshotId)
.add("asOfTime", asOfTime).add("maxRefAgeMs",
maxRefAgeMs).add("minSnapshotsToKeep", minSnapshotsToKeep)
.add("maxSnapshotAgeMs",
maxSnapshotAgeMs).omitNullValues().toString();
}
}
+ public static class DropSnapshotRefSpec {
+
+ private String refName;
+ private boolean ifExists;
+
+ public String getRefName() {
+ return refName;
+ }
+
+ public boolean getIfExists() {
+ return ifExists;
+ }
+
+ public DropSnapshotRefSpec(String refName, Boolean ifExists) {
+ this.refName = refName;
+ this.ifExists = ifExists;
+ }
+
+ public String toString() {
+ return MoreObjects.toStringHelper(this).add("refName",
refName).add("ifExists", ifExists).omitNullValues()
Review Comment:
```omitNullValues``` in which case this will kick in?
##########
ql/src/java/org/apache/hadoop/hive/ql/parse/AlterTableSnapshotRefSpec.java:
##########
@@ -89,9 +89,32 @@ public CreateSnapshotRefSpec(String refName, Long
snapShotId, Long asOfTime, Lon
}
public String toString() {
- return MoreObjects.toStringHelper(this).add("branchName",
refName).add("snapshotId", snapshotId)
+ return MoreObjects.toStringHelper(this).add("refName",
refName).add("snapshotId", snapshotId)
.add("asOfTime", asOfTime).add("maxRefAgeMs",
maxRefAgeMs).add("minSnapshotsToKeep", minSnapshotsToKeep)
.add("maxSnapshotAgeMs",
maxSnapshotAgeMs).omitNullValues().toString();
}
}
+ public static class DropSnapshotRefSpec {
+
+ private String refName;
+ private boolean ifExists;
Review Comment:
can be ``final``
##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/IcebergBranchExec.java:
##########
@@ -63,4 +64,15 @@ public static void createBranch(Table table,
AlterTableSnapshotRefSpec.CreateSna
manageSnapshots.commit();
}
+
+ public static void dropBranch(Table table,
AlterTableSnapshotRefSpec.DropSnapshotRefSpec dropBranchSpec) {
+ String branchName = dropBranchSpec.getRefName();
+ Boolean ifExists = dropBranchSpec.getIfExists();
Review Comment:
why object? can be ``boolean``?
##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/AlterTableType.java:
##########
@@ -42,6 +42,7 @@ public enum AlterTableType {
EXECUTE("execute"),
CREATE_BRANCH("create branch"),
CREATE_TAG("create tag"),
+ DROP_BRANCH("drop branch"),
Review Comment:
nit
can we pull this up and let it stay with create branch
--
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]