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


##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/tag/create/AlterTableCreateTagAnalyzer.java:
##########
@@ -0,0 +1,93 @@
+/*
+ * 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.tag.create;
+
+import java.time.ZoneId;
+import java.util.Locale;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import org.apache.hadoop.hive.common.TableName;
+import org.apache.hadoop.hive.common.type.TimestampTZ;
+import org.apache.hadoop.hive.common.type.TimestampTZUtil;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.ql.QueryState;
+import org.apache.hadoop.hive.ql.ddl.DDLSemanticAnalyzerFactory;
+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.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.AlterTableTagSpec;
+import org.apache.hadoop.hive.ql.parse.HiveParser;
+import org.apache.hadoop.hive.ql.parse.SemanticException;
+import org.apache.hadoop.hive.ql.session.SessionState;
+
+import static 
org.apache.hadoop.hive.ql.parse.AlterTableTagSpec.AlterTagOperationType.CREATE_TAG;
+
+@DDLSemanticAnalyzerFactory.DDLType(types = 
HiveParser.TOK_ALTERTABLE_CREATE_TAG)
+public class AlterTableCreateTagAnalyzer extends AbstractAlterTableAnalyzer {
+  public AlterTableCreateTagAnalyzer(QueryState queryState) throws 
SemanticException {
+    super(queryState);
+  }
+
+  @Override
+  protected void analyzeCommand(TableName tableName, Map<String, String> 
partitionSpec, ASTNode command)
+      throws SemanticException {
+    Table table = getTable(tableName);
+    validateAlterTableType(table, AlterTableType.CREATE_TAG, false);
+    DDLUtils.validateTableIsIceberg(table);
+    inputs.add(new ReadEntity(table));
+
+    String tagName = command.getChild(0).getText();
+    Long snapshotId = null;
+    Long asOfTime = null;
+    Long maxRefAgeMs = null;
+    for (int i = 1; i < command.getChildCount(); i++) {
+      ASTNode childNode = (ASTNode) command.getChild(i);
+      switch (childNode.getToken().getType()) {
+      case HiveParser.TOK_AS_OF_VERSION:
+        snapshotId = Long.parseLong(childNode.getChild(0).getText());
+        break;
+      case HiveParser.TOK_AS_OF_TIME:
+        ZoneId timeZone = SessionState.get() == null ? new 
HiveConf().getLocalTimeZone() :
+            SessionState.get().getConf().getLocalTimeZone();
+        TimestampTZ ts = 
TimestampTZUtil.parse(stripQuotes(childNode.getChild(0).getText()), timeZone);
+        asOfTime = ts.toEpochMilli();
+        break;
+      case HiveParser.TOK_RETAIN:
+        String maxRefAge = childNode.getChild(0).getText();
+        String timeUnitOfBranchRetain = childNode.getChild(1).getText();
+        maxRefAgeMs =
+            
TimeUnit.valueOf(timeUnitOfBranchRetain.toUpperCase(Locale.ENGLISH)).toMillis(Long.parseLong(maxRefAge));
+        break;
+      default:
+        throw new SemanticException("Unrecognized token in ALTER CREATE TAG 
statement");
+      }
+    }
+
+    AlterTableTagSpec.CreateTagSpec createTagspec =
+        new AlterTableTagSpec.CreateTagSpec(tagName, snapshotId, asOfTime, 
maxRefAgeMs);
+    AlterTableTagSpec alterTableTagSpec = new AlterTableTagSpec(CREATE_TAG, 
createTagspec);
+    AlterTableCreateTagDesc desc = new AlterTableCreateTagDesc(tableName, 
alterTableTagSpec);

Review Comment:
   I create a new abtract class 
`ql/src/java/org/apache/hadoop/hive/ql/ddl/table/AlterTableCreateMetaRefAnalyzer.java`
 to make code reusable.
   
https://github.com/apache/hive/pull/4372/files#diff-eac7a1ce623e75ae7789cba72422c240ec9d4f877db53280251a6ad9816e8bf5



-- 
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: gitbox-unsubscr...@hive.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to