pvary commented on code in PR #3287: URL: https://github.com/apache/hive/pull/3287#discussion_r881413044
########## ql/src/java/org/apache/hadoop/hive/ql/ddl/table/execute/AlterTableExecuteAnalyzer.java: ########## @@ -0,0 +1,84 @@ +/* + * 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.execute; + +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.DDLType; +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.HiveParser; +import org.apache.hadoop.hive.ql.parse.AlterTableExecuteSpec; +import org.apache.hadoop.hive.ql.parse.SemanticException; +import org.apache.hadoop.hive.ql.plan.PlanUtils; +import org.apache.hadoop.hive.ql.session.SessionState; + +import java.time.ZoneId; +import java.util.Map; + +/** + * Analyzer for ALTER TABLE ... EXECUTE commands. + */ +@DDLType(types = HiveParser.TOK_ALTERTABLE_EXECUTE) +public class AlterTableExecuteAnalyzer extends AbstractAlterTableAnalyzer { + + public AlterTableExecuteAnalyzer(QueryState queryState) throws SemanticException { + super(queryState); + } + + @Override + protected void analyzeCommand(TableName tableName, Map<String, String> partitionSpec, ASTNode command) + throws SemanticException { + Table table = getTable(tableName); + // the first child must be the execute operation type + ASTNode executeCommandType = (ASTNode) command.getChild(0); + validateAlterTableType(table, AlterTableType.EXECUTE, false); + inputs.add(new ReadEntity(table)); + AlterTableExecuteDesc desc = null; + if (HiveParser.KW_ROLLBACK == executeCommandType.getType()) { + AlterTableExecuteSpec<AlterTableExecuteSpec.RollbackSpec> spec; + // the second child must be the rollback parameter + ASTNode child = (ASTNode) command.getChild(1); + + if (child.getType() == HiveParser.StringLiteral) { + ZoneId timeZone = SessionState.get() == null ? new HiveConf().getLocalTimeZone() : SessionState.get().getConf() + .getLocalTimeZone(); + TimestampTZ time = TimestampTZUtil.parse(PlanUtils.stripQuotes(child.getText()), timeZone); + spec = new AlterTableExecuteSpec(AlterTableExecuteSpec.ExecuteOperationType.ROLLBACK, + new AlterTableExecuteSpec.RollbackSpec(AlterTableExecuteSpec.RollbackSpec.RollbackType.TIME, Review Comment: nit: maybe static import `AlterTableExecuteSpec.RollbackSpec`? -- 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]
