diff --git ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AbstractAlterDatabaseDesc.java ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AbstractAlterDatabaseDesc.java new file mode 100644 index 0000000000..20374ef084 --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AbstractAlterDatabaseDesc.java @@ -0,0 +1,54 @@ +/* + * 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.database; + +import java.io.Serializable; + +import org.apache.hadoop.hive.ql.ddl.DDLDesc; +import org.apache.hadoop.hive.ql.parse.ReplicationSpec; +import org.apache.hadoop.hive.ql.plan.Explain; +import org.apache.hadoop.hive.ql.plan.Explain.Level; + +/** + * DDL task description for ALTER DATABASE commands. + */ +public abstract class AbstractAlterDatabaseDesc implements DDLDesc, Serializable { + private static final long serialVersionUID = 1L; + + private final String databaseName; + private final ReplicationSpec replicationSpec; + + public AbstractAlterDatabaseDesc(String databaseName, ReplicationSpec replicationSpec) { + this.databaseName = databaseName; + this.replicationSpec = replicationSpec; + } + + @Explain(displayName="name", explainLevels = {Level.USER, Level.DEFAULT, Level.EXTENDED }) + public String getDatabaseName() { + return databaseName; + } + + /** + * @return what kind of replication scope this alter is running under. + * This can result in a "ALTER IF NEWER THAN" kind of semantic + */ + public ReplicationSpec getReplicationSpec() { + return this.replicationSpec; + } +} diff --git ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseOperation.java ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AbstractAlterDatabaseOperation.java similarity index 50% rename from ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseOperation.java rename to ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AbstractAlterDatabaseOperation.java index 9ce3b62046..61076fabc5 100644 --- ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseOperation.java +++ ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AbstractAlterDatabaseOperation.java @@ -18,11 +18,8 @@ package org.apache.hadoop.hive.ql.ddl.database; -import java.net.URI; -import java.net.URISyntaxException; import java.util.Map; -import org.apache.commons.lang.StringUtils; import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.ql.ErrorMsg; import org.apache.hadoop.hive.ql.ddl.DDLOperation; @@ -32,8 +29,8 @@ /** * Operation process of altering a database. */ -public class AlterDatabaseOperation extends DDLOperation { - public AlterDatabaseOperation(DDLOperationContext context, AlterDatabaseDesc desc) { +public abstract class AbstractAlterDatabaseOperation extends DDLOperation { + public AbstractAlterDatabaseOperation(DDLOperationContext context, T desc) { super(context, desc); } @@ -52,60 +49,11 @@ public int execute() throws HiveException { return 0; // no replacement, the existing database state is newer than our update. } - switch (desc.getAlterType()) { - case ALTER_PROPERTY: - alterProperties(database, params); - break; - - case ALTER_OWNER: - alterOwner(database); - break; - - case ALTER_LOCATION: - alterLocation(database); - break; - - default: - throw new AssertionError("Unsupported alter database type! : " + desc.getAlterType()); - } + doAlteration(database, params); context.getDb().alterDatabase(database.getName(), database); return 0; } - private void alterProperties(Database database, Map params) { - Map newParams = desc.getDatabaseProperties(); - - // if both old and new params are not null, merge them - if (params != null && newParams != null) { - params.putAll(newParams); - database.setParameters(params); - } else { - // if one of them is null, replace the old params with the new one - database.setParameters(newParams); - } - } - - private void alterOwner(Database database) { - database.setOwnerName(desc.getOwnerPrincipal().getName()); - database.setOwnerType(desc.getOwnerPrincipal().getType()); - } - - private void alterLocation(Database database) throws HiveException { - try { - String newLocation = desc.getLocation(); - URI locationURI = new URI(newLocation); - if (!locationURI.isAbsolute() || StringUtils.isBlank(locationURI.getScheme())) { - throw new HiveException(ErrorMsg.BAD_LOCATION_VALUE, newLocation); - } - - if (newLocation.equals(database.getLocationUri())) { - LOG.info("AlterDatabase skipped. No change in location."); - } else { - database.setLocationUri(newLocation); - } - } catch (URISyntaxException e) { - throw new HiveException(e); - } - } + protected abstract void doAlteration(Database database, Map params) throws HiveException; } diff --git ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseDesc.java ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseDesc.java deleted file mode 100644 index f83c74c9a5..0000000000 --- ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseDesc.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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.database; - -import java.io.Serializable; -import java.util.Map; - -import org.apache.hadoop.hive.ql.ddl.DDLDesc; -import org.apache.hadoop.hive.ql.ddl.privilege.PrincipalDesc; -import org.apache.hadoop.hive.ql.parse.ReplicationSpec; -import org.apache.hadoop.hive.ql.plan.Explain; -import org.apache.hadoop.hive.ql.plan.Explain.Level; - -/** - * DDL task description for ALTER DATABASE commands. - */ -@Explain(displayName = "Alter Database", explainLevels = { Level.USER, Level.DEFAULT, Level.EXTENDED }) -public class AlterDatabaseDesc implements DDLDesc, Serializable { - private static final long serialVersionUID = 1L; - - /** - * Supported type of alter db commands. - * Only altering the database property and owner is currently supported - */ - public enum AlterDbType { - ALTER_PROPERTY, ALTER_OWNER, ALTER_LOCATION - }; - - private final AlterDbType alterType; - private final String databaseName; - private final Map dbProperties; - private final ReplicationSpec replicationSpec; - private final PrincipalDesc ownerPrincipal; - private final String location; - - public AlterDatabaseDesc(String databaseName, Map dbProperties, ReplicationSpec replicationSpec) { - this.alterType = AlterDbType.ALTER_PROPERTY; - this.databaseName = databaseName; - this.dbProperties = dbProperties; - this.replicationSpec = replicationSpec; - this.ownerPrincipal = null; - this.location = null; - } - - public AlterDatabaseDesc(String databaseName, PrincipalDesc ownerPrincipal, ReplicationSpec replicationSpec) { - this.alterType = AlterDbType.ALTER_OWNER; - this.databaseName = databaseName; - this.dbProperties = null; - this.replicationSpec = replicationSpec; - this.ownerPrincipal = ownerPrincipal; - this.location = null; - } - - public AlterDatabaseDesc(String databaseName, String location) { - this.alterType = AlterDbType.ALTER_LOCATION; - this.databaseName = databaseName; - this.dbProperties = null; - this.replicationSpec = null; - this.ownerPrincipal = null; - this.location = location; - } - - public AlterDbType getAlterType() { - return alterType; - } - - @Explain(displayName="name", explainLevels = {Level.USER, Level.DEFAULT, Level.EXTENDED }) - public String getDatabaseName() { - return databaseName; - } - - @Explain(displayName="properties") - public Map getDatabaseProperties() { - return dbProperties; - } - - /** - * @return what kind of replication scope this alter is running under. - * This can result in a "ALTER IF NEWER THAN" kind of semantic - */ - public ReplicationSpec getReplicationSpec() { - return this.replicationSpec; - } - - @Explain(displayName="owner") - public PrincipalDesc getOwnerPrincipal() { - return ownerPrincipal; - } - - @Explain(displayName="location") - public String getLocation() { - return location; - } -} diff --git ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetLocationDesc.java ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetLocationDesc.java new file mode 100644 index 0000000000..cb7fb3d077 --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetLocationDesc.java @@ -0,0 +1,42 @@ +/* + * 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.database; + +import org.apache.hadoop.hive.ql.plan.Explain; +import org.apache.hadoop.hive.ql.plan.Explain.Level; + +/** + * DDL task description for ALTER DATABASE ... SET LOCATION ... commands. + */ +@Explain(displayName = "Set Database Location", explainLevels = { Level.USER, Level.DEFAULT, Level.EXTENDED }) +public class AlterDatabaseSetLocationDesc extends AbstractAlterDatabaseDesc { + private static final long serialVersionUID = 1L; + + private final String location; + + public AlterDatabaseSetLocationDesc(String databaseName, String location) { + super(databaseName, null); + this.location = location; + } + + @Explain(displayName="location") + public String getLocation() { + return location; + } +} diff --git ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetLocationOperation.java ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetLocationOperation.java new file mode 100644 index 0000000000..e136cdb5e8 --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetLocationOperation.java @@ -0,0 +1,57 @@ +/* + * 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.database; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Map; + +import org.apache.commons.lang.StringUtils; +import org.apache.hadoop.hive.metastore.api.Database; +import org.apache.hadoop.hive.ql.ErrorMsg; +import org.apache.hadoop.hive.ql.ddl.DDLOperationContext; +import org.apache.hadoop.hive.ql.metadata.HiveException; + +/** + * Operation process of altering a database's location. + */ +public class AlterDatabaseSetLocationOperation extends AbstractAlterDatabaseOperation { + public AlterDatabaseSetLocationOperation(DDLOperationContext context, AlterDatabaseSetLocationDesc desc) { + super(context, desc); + } + + @Override + protected void doAlteration(Database database, Map params) throws HiveException { + try { + String newLocation = desc.getLocation(); + URI locationURI = new URI(newLocation); + if (!locationURI.isAbsolute() || StringUtils.isBlank(locationURI.getScheme())) { + throw new HiveException(ErrorMsg.BAD_LOCATION_VALUE, newLocation); + } + + if (newLocation.equals(database.getLocationUri())) { + LOG.info("AlterDatabase skipped. No change in location."); + } else { + database.setLocationUri(newLocation); + } + } catch (URISyntaxException e) { + throw new HiveException(e); + } + } +} diff --git ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetOwnerDesc.java ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetOwnerDesc.java new file mode 100644 index 0000000000..97870de33a --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetOwnerDesc.java @@ -0,0 +1,44 @@ +/* + * 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.database; + +import org.apache.hadoop.hive.ql.ddl.privilege.PrincipalDesc; +import org.apache.hadoop.hive.ql.parse.ReplicationSpec; +import org.apache.hadoop.hive.ql.plan.Explain; +import org.apache.hadoop.hive.ql.plan.Explain.Level; + +/** + * DDL task description for ALTER DATABASE ... SET OWNER ... commands. + */ +@Explain(displayName = "Set Database Owner", explainLevels = { Level.USER, Level.DEFAULT, Level.EXTENDED }) +public class AlterDatabaseSetOwnerDesc extends AbstractAlterDatabaseDesc { + private static final long serialVersionUID = 1L; + + private final PrincipalDesc ownerPrincipal; + + public AlterDatabaseSetOwnerDesc(String databaseName, PrincipalDesc ownerPrincipal, ReplicationSpec replicationSpec) { + super(databaseName, replicationSpec); + this.ownerPrincipal = ownerPrincipal; + } + + @Explain(displayName="owner") + public PrincipalDesc getOwnerPrincipal() { + return ownerPrincipal; + } +} diff --git ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetOwnerOperation.java ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetOwnerOperation.java new file mode 100644 index 0000000000..9b20311dcb --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetOwnerOperation.java @@ -0,0 +1,39 @@ +/* + * 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.database; + +import java.util.Map; + +import org.apache.hadoop.hive.metastore.api.Database; +import org.apache.hadoop.hive.ql.ddl.DDLOperationContext; + +/** + * Operation process of altering a database's owner. + */ +public class AlterDatabaseSetOwnerOperation extends AbstractAlterDatabaseOperation { + public AlterDatabaseSetOwnerOperation(DDLOperationContext context, AlterDatabaseSetOwnerDesc desc) { + super(context, desc); + } + + @Override + protected void doAlteration(Database database, Map params) { + database.setOwnerName(desc.getOwnerPrincipal().getName()); + database.setOwnerType(desc.getOwnerPrincipal().getType()); + } +} diff --git ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetPropertiesDesc.java ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetPropertiesDesc.java new file mode 100644 index 0000000000..1a2075b00a --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetPropertiesDesc.java @@ -0,0 +1,46 @@ +/* + * 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.database; + +import java.util.Map; + +import org.apache.hadoop.hive.ql.parse.ReplicationSpec; +import org.apache.hadoop.hive.ql.plan.Explain; +import org.apache.hadoop.hive.ql.plan.Explain.Level; + +/** + * DDL task description for ALTER DATABASE ... SET PROPERTIES ... commands. + */ +@Explain(displayName = "Set Database Properties", explainLevels = { Level.USER, Level.DEFAULT, Level.EXTENDED }) +public class AlterDatabaseSetPropertiesDesc extends AbstractAlterDatabaseDesc { + private static final long serialVersionUID = 1L; + + private final Map dbProperties; + + public AlterDatabaseSetPropertiesDesc(String databaseName, Map dbProperties, + ReplicationSpec replicationSpec) { + super(databaseName, replicationSpec); + this.dbProperties = dbProperties; + } + + @Explain(displayName="properties") + public Map getDatabaseProperties() { + return dbProperties; + } +} diff --git ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetPropertiesOperation.java ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetPropertiesOperation.java new file mode 100644 index 0000000000..7f73502d2b --- /dev/null +++ ql/src/java/org/apache/hadoop/hive/ql/ddl/database/AlterDatabaseSetPropertiesOperation.java @@ -0,0 +1,48 @@ +/* + * 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.database; + +import java.util.Map; + +import org.apache.hadoop.hive.metastore.api.Database; +import org.apache.hadoop.hive.ql.ddl.DDLOperationContext; + +/** + * Operation process of altering a database's properties. + */ +public class AlterDatabaseSetPropertiesOperation + extends AbstractAlterDatabaseOperation { + public AlterDatabaseSetPropertiesOperation(DDLOperationContext context, AlterDatabaseSetPropertiesDesc desc) { + super(context, desc); + } + + @Override + protected void doAlteration(Database database, Map params) { + Map newParams = desc.getDatabaseProperties(); + + // if both old and new params are not null, merge them + if (params != null && newParams != null) { + params.putAll(newParams); + database.setParameters(params); + } else { + // if one of them is null, replace the old params with the new one + database.setParameters(newParams); + } + } +} diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/repl/bootstrap/load/LoadDatabase.java ql/src/java/org/apache/hadoop/hive/ql/exec/repl/bootstrap/load/LoadDatabase.java index ac5f375ed1..2a5966b8dd 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/repl/bootstrap/load/LoadDatabase.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/repl/bootstrap/load/LoadDatabase.java @@ -21,7 +21,8 @@ import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.metastore.api.InvalidOperationException; import org.apache.hadoop.hive.ql.ddl.DDLWork; -import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseDesc; +import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseSetOwnerDesc; +import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseSetPropertiesDesc; import org.apache.hadoop.hive.ql.ddl.database.CreateDatabaseDesc; import org.apache.hadoop.hive.ql.ddl.privilege.PrincipalDesc; import org.apache.hadoop.hive.ql.exec.Task; @@ -131,8 +132,8 @@ private boolean isDbEmpty(String dbName) throws HiveException { } private Task setOwnerInfoTask(Database dbObj) { - AlterDatabaseDesc alterDbDesc = new AlterDatabaseDesc(dbObj.getName(), new PrincipalDesc(dbObj.getOwnerName(), - dbObj.getOwnerType()), null); + AlterDatabaseSetOwnerDesc alterDbDesc = new AlterDatabaseSetOwnerDesc(dbObj.getName(), + new PrincipalDesc(dbObj.getOwnerName(), dbObj.getOwnerType()), null); DDLWork work = new DDLWork(new HashSet<>(), new HashSet<>(), alterDbDesc); return TaskFactory.get(work, context.hiveConf); } @@ -161,7 +162,7 @@ private boolean isDbEmpty(String dbName) throws HiveException { private static Task alterDbTask(String dbName, Map props, HiveConf hiveConf) { - AlterDatabaseDesc alterDbDesc = new AlterDatabaseDesc(dbName, props, null); + AlterDatabaseSetPropertiesDesc alterDbDesc = new AlterDatabaseSetPropertiesDesc(dbName, props, null); DDLWork work = new DDLWork(new HashSet<>(), new HashSet<>(), alterDbDesc); return TaskFactory.get(work, hiveConf); } diff --git ql/src/java/org/apache/hadoop/hive/ql/exec/repl/incremental/IncrementalLoadTasksBuilder.java ql/src/java/org/apache/hadoop/hive/ql/exec/repl/incremental/IncrementalLoadTasksBuilder.java index e3480d3fe2..e83b9f8da7 100644 --- ql/src/java/org/apache/hadoop/hive/ql/exec/repl/incremental/IncrementalLoadTasksBuilder.java +++ ql/src/java/org/apache/hadoop/hive/ql/exec/repl/incremental/IncrementalLoadTasksBuilder.java @@ -27,7 +27,7 @@ import org.apache.hadoop.hive.metastore.api.ReplLastIdInfo; import org.apache.hadoop.hive.ql.DriverContext; import org.apache.hadoop.hive.ql.ddl.DDLWork; -import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseDesc; +import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseSetPropertiesDesc; import org.apache.hadoop.hive.ql.ddl.misc.ReplRemoveFirstIncLoadPendFlagDesc; import org.apache.hadoop.hive.ql.ddl.table.misc.AlterTableSetPropertiesDesc; import org.apache.hadoop.hive.ql.exec.Task; @@ -278,7 +278,8 @@ private boolean shouldReplayEvent(FileStatus dir, DumpType dumpType, String dbNa HashMap mapProp = new HashMap<>(); mapProp.put(ReplicationSpec.KEY.CURR_STATE_ID.toString(), replState); - AlterDatabaseDesc alterDbDesc = new AlterDatabaseDesc(dbName, mapProp, new ReplicationSpec(replState, replState)); + AlterDatabaseSetPropertiesDesc alterDbDesc = new AlterDatabaseSetPropertiesDesc(dbName, mapProp, + new ReplicationSpec(replState, replState)); Task updateReplIdTask = TaskFactory.get(new DDLWork(inputs, outputs, alterDbDesc), conf); // Link the update repl state task with dependency collection task diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java index c74b8da89f..4e02ce7b64 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java @@ -74,7 +74,10 @@ import org.apache.hadoop.hive.ql.ddl.DDLDesc; import org.apache.hadoop.hive.ql.ddl.DDLDesc.DDLDescWithWriteId; import org.apache.hadoop.hive.ql.ddl.DDLWork; -import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseDesc; +import org.apache.hadoop.hive.ql.ddl.database.AbstractAlterDatabaseDesc; +import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseSetLocationDesc; +import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseSetOwnerDesc; +import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseSetPropertiesDesc; import org.apache.hadoop.hive.ql.ddl.database.CreateDatabaseDesc; import org.apache.hadoop.hive.ql.ddl.database.DescDatabaseDesc; import org.apache.hadoop.hive.ql.ddl.database.DropDatabaseDesc; @@ -811,11 +814,11 @@ private void analyzeAlterDatabaseProperties(ASTNode ast) throws SemanticExceptio throw new SemanticException("Unrecognized token in CREATE DATABASE statement"); } } - AlterDatabaseDesc alterDesc = new AlterDatabaseDesc(dbName, dbProps, null); + AlterDatabaseSetPropertiesDesc alterDesc = new AlterDatabaseSetPropertiesDesc(dbName, dbProps, null); addAlterDbDesc(alterDesc); } - private void addAlterDbDesc(AlterDatabaseDesc alterDesc) throws SemanticException { + private void addAlterDbDesc(AbstractAlterDatabaseDesc alterDesc) throws SemanticException { Database database = getDatabase(alterDesc.getDatabaseName()); outputs.add(new WriteEntity(database, WriteEntity.WriteType.DDL_NO_LOCK)); rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), alterDesc))); @@ -835,7 +838,7 @@ private void analyzeAlterDatabaseOwner(ASTNode ast) throws SemanticException { throw new SemanticException("Owner type " + nullCmdMsg); } - AlterDatabaseDesc alterDesc = new AlterDatabaseDesc(dbName, principalDesc, null); + AlterDatabaseSetOwnerDesc alterDesc = new AlterDatabaseSetOwnerDesc(dbName, principalDesc, null); addAlterDbDesc(alterDesc); } @@ -843,7 +846,7 @@ private void analyzeAlterDatabaseLocation(ASTNode ast) throws SemanticException String dbName = getUnescapedName((ASTNode) ast.getChild(0)); String newLocation = unescapeSQLString(ast.getChild(1).getText()); addLocationToOutputs(newLocation); - AlterDatabaseDesc alterDesc = new AlterDatabaseDesc(dbName, newLocation); + AlterDatabaseSetLocationDesc alterDesc = new AlterDatabaseSetLocationDesc(dbName, newLocation); addAlterDbDesc(alterDesc); } diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/repl/load/message/AlterDatabaseHandler.java ql/src/java/org/apache/hadoop/hive/ql/parse/repl/load/message/AlterDatabaseHandler.java index 6305754492..189e9aa9fe 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/repl/load/message/AlterDatabaseHandler.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/repl/load/message/AlterDatabaseHandler.java @@ -21,7 +21,9 @@ import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.metastore.messaging.AlterDatabaseMessage; import org.apache.hadoop.hive.ql.ddl.DDLWork; -import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseDesc; +import org.apache.hadoop.hive.ql.ddl.database.AbstractAlterDatabaseDesc; +import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseSetOwnerDesc; +import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseSetPropertiesDesc; import org.apache.hadoop.hive.ql.ddl.privilege.PrincipalDesc; import org.apache.hadoop.hive.ql.exec.Task; import org.apache.hadoop.hive.ql.exec.TaskFactory; @@ -50,7 +52,7 @@ try { Database oldDb = msg.getDbObjBefore(); Database newDb = msg.getDbObjAfter(); - AlterDatabaseDesc alterDbDesc; + AbstractAlterDatabaseDesc alterDbDesc; if ((oldDb.getOwnerType() == newDb.getOwnerType()) && oldDb.getOwnerName().equalsIgnoreCase(newDb.getOwnerName())) { @@ -70,10 +72,10 @@ } newDbProps.put(key, entry.getValue()); } - alterDbDesc = new AlterDatabaseDesc(actualDbName, newDbProps, context.eventOnlyReplicationSpec()); + alterDbDesc = new AlterDatabaseSetPropertiesDesc(actualDbName, newDbProps, context.eventOnlyReplicationSpec()); } else { - alterDbDesc = new AlterDatabaseDesc(actualDbName, new PrincipalDesc(newDb.getOwnerName(), newDb.getOwnerType()), - context.eventOnlyReplicationSpec()); + alterDbDesc = new AlterDatabaseSetOwnerDesc(actualDbName, new PrincipalDesc(newDb.getOwnerName(), + newDb.getOwnerType()), context.eventOnlyReplicationSpec()); } Task alterDbTask = TaskFactory.get( diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/repl/load/message/CreateDatabaseHandler.java ql/src/java/org/apache/hadoop/hive/ql/parse/repl/load/message/CreateDatabaseHandler.java index eb4d8b46a4..1438a5288c 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/repl/load/message/CreateDatabaseHandler.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/repl/load/message/CreateDatabaseHandler.java @@ -24,7 +24,8 @@ import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.ql.ErrorMsg; import org.apache.hadoop.hive.ql.ddl.DDLWork; -import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseDesc; +import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseSetOwnerDesc; +import org.apache.hadoop.hive.ql.ddl.database.AlterDatabaseSetPropertiesDesc; import org.apache.hadoop.hive.ql.ddl.database.CreateDatabaseDesc; import org.apache.hadoop.hive.ql.ddl.privilege.PrincipalDesc; import org.apache.hadoop.hive.ql.exec.Task; @@ -61,14 +62,14 @@ Task createDBTask = TaskFactory.get( new DDLWork(new HashSet<>(), new HashSet<>(), createDatabaseDesc), context.hiveConf); if (!db.getParameters().isEmpty()) { - AlterDatabaseDesc alterDbDesc = new AlterDatabaseDesc(destinationDBName, db.getParameters(), - context.eventOnlyReplicationSpec()); + AlterDatabaseSetPropertiesDesc alterDbDesc = new AlterDatabaseSetPropertiesDesc(destinationDBName, + db.getParameters(), context.eventOnlyReplicationSpec()); Task alterDbProperties = TaskFactory .get(new DDLWork(new HashSet<>(), new HashSet<>(), alterDbDesc), context.hiveConf); createDBTask.addDependentTask(alterDbProperties); } if (StringUtils.isNotEmpty(db.getOwnerName())) { - AlterDatabaseDesc alterDbOwner = new AlterDatabaseDesc(destinationDBName, + AlterDatabaseSetOwnerDesc alterDbOwner = new AlterDatabaseSetOwnerDesc(destinationDBName, new PrincipalDesc(db.getOwnerName(), db.getOwnerType()), context.eventOnlyReplicationSpec()); Task alterDbTask = TaskFactory diff --git ql/src/test/queries/clientpositive/alter_db_owner.q ql/src/test/queries/clientpositive/alter_db_owner.q index b224f3339e..94c7511d81 100644 --- ql/src/test/queries/clientpositive/alter_db_owner.q +++ ql/src/test/queries/clientpositive/alter_db_owner.q @@ -2,6 +2,7 @@ create database db_alter_onr; describe database db_alter_onr; +explain alter database db_alter_onr set owner user user1; alter database db_alter_onr set owner user user1; describe database db_alter_onr; diff --git ql/src/test/results/clientpositive/alter_db_owner.q.out ql/src/test/results/clientpositive/alter_db_owner.q.out index bc3752f9a6..de4ba6437a 100644 --- ql/src/test/results/clientpositive/alter_db_owner.q.out +++ ql/src/test/results/clientpositive/alter_db_owner.q.out @@ -11,6 +11,23 @@ POSTHOOK: query: describe database db_alter_onr POSTHOOK: type: DESCDATABASE POSTHOOK: Input: database:db_alter_onr db_alter_onr location/in/test hive_test_user USER +#### A masked pattern was here #### +PREHOOK: type: ALTERDATABASE_OWNER +PREHOOK: Output: database:db_alter_onr +#### A masked pattern was here #### +POSTHOOK: type: ALTERDATABASE_OWNER +POSTHOOK: Output: database:db_alter_onr +STAGE DEPENDENCIES: + Stage-0 is a root stage + +STAGE PLANS: + Stage: Stage-0 +#### A masked pattern was here #### + name: db_alter_onr +#### A masked pattern was here #### + Principal + name: user1 + #### A masked pattern was here #### PREHOOK: type: ALTERDATABASE_OWNER PREHOOK: Output: database:db_alter_onr diff --git ql/src/test/results/clientpositive/db_ddl_explain.q.out ql/src/test/results/clientpositive/db_ddl_explain.q.out index 8e85d75fac..8cf5f9cc50 100644 --- ql/src/test/results/clientpositive/db_ddl_explain.q.out +++ ql/src/test/results/clientpositive/db_ddl_explain.q.out @@ -81,7 +81,7 @@ STAGE DEPENDENCIES: STAGE PLANS: Stage: Stage-0 - Alter Database + Set Database Properties name: d properties: test yesthisis