[ https://issues.apache.org/jira/browse/HIVE-26228?focusedWorklogId=774435&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-774435 ]
ASF GitHub Bot logged work on HIVE-26228: ----------------------------------------- Author: ASF GitHub Bot Created on: 25/May/22 09:08 Start Date: 25/May/22 09:08 Worklog Time Spent: 10m Work Description: 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`? Issue Time Tracking ------------------- Worklog Id: (was: 774435) Time Spent: 3.5h (was: 3h 20m) > Implement Iceberg table rollback feature > ---------------------------------------- > > Key: HIVE-26228 > URL: https://issues.apache.org/jira/browse/HIVE-26228 > Project: Hive > Issue Type: New Feature > Reporter: László Pintér > Assignee: László Pintér > Priority: Major > Labels: pull-request-available > Time Spent: 3.5h > Remaining Estimate: 0h > > We should allow rolling back iceberg table's data to the state at an older > table snapshot. > Rollback to the last snapshot before a specific timestamp > {code:java} > ALTER TABLE ice_t EXECUTE ROLLBACK('2022-05-12 00:00:00') > {code} > Rollback to a specific snapshot ID > {code:java} > ALTER TABLE ice_t EXECUTE ROLLBACK(1111); > {code} -- This message was sent by Atlassian Jira (v8.20.7#820007)