hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mit...@apache.org
Subject hive git commit: HIVE-8472: Add ALTER DATABASE SET LOCATION (Mithun Radhakrishnan, reviewed by Alan Gates)
Date Wed, 16 Aug 2017 17:05:27 GMT
Repository: hive
Updated Branches:
  refs/heads/branch-2.2 d8d387863 -> 289d8342a


HIVE-8472: Add ALTER DATABASE SET LOCATION (Mithun Radhakrishnan, reviewed by Alan Gates)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/289d8342
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/289d8342
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/289d8342

Branch: refs/heads/branch-2.2
Commit: 289d8342ad132a9d6e5397c5c6e089297bd2f747
Parents: d8d3878
Author: Mithun RK <mithun@apache.org>
Authored: Mon Aug 7 14:12:13 2017 -0700
Committer: Mithun RK <mithun@apache.org>
Committed: Tue Aug 15 13:47:17 2017 -0700

----------------------------------------------------------------------
 .../hive/metastore/TestHiveMetaStore.java       | 29 ++++++++++++
 .../TestAuthorizationPreEventListener.java      | 19 +++++++-
 .../hadoop/hive/metastore/HiveMetaStore.java    | 16 ++++++-
 .../hadoop/hive/metastore/ObjectStore.java      |  6 +++
 .../metastore/events/PreAlterDatabaseEvent.java | 47 ++++++++++++++++++++
 .../hive/metastore/events/PreEventContext.java  |  3 +-
 .../org/apache/hadoop/hive/ql/exec/DDLTask.java | 20 +++++++++
 .../hive/ql/parse/DDLSemanticAnalyzer.java      | 11 +++++
 .../apache/hadoop/hive/ql/parse/HiveParser.g    |  9 ++++
 .../hive/ql/parse/SemanticAnalyzerFactory.java  |  2 +
 .../hadoop/hive/ql/plan/AlterDatabaseDesc.java  | 18 +++++++-
 .../hadoop/hive/ql/plan/HiveOperation.java      |  1 +
 .../AuthorizationPreEventListener.java          | 19 ++++++++
 .../authorization/plugin/HiveOperationType.java |  1 +
 .../plugin/sqlstd/Operation2Privilege.java      |  2 +
 15 files changed, 198 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
index 8328760..4b6fe46 100644
--- a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
+++ b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java
@@ -19,6 +19,7 @@
 package org.apache.hadoop.hive.metastore;
 
 import java.lang.reflect.Field;
+import java.io.IOException;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
@@ -3140,6 +3141,34 @@ public abstract class TestHiveMetaStore extends TestCase {
     client.dropDatabase(dbName, true, true, true);
   }
 
+  @Test
+  public void testDBLocationChange() throws IOException, TException {
+    final String dbName = "alterDbLocation";
+    String defaultUri = HiveConf.getVar(hiveConf, HiveConf.ConfVars.METASTOREWAREHOUSE) +
"/default_location.db";
+    String newUri = HiveConf.getVar(hiveConf, HiveConf.ConfVars.METASTOREWAREHOUSE) + "/new_location.db";
+
+    Database db = new Database();
+    db.setName(dbName);
+    db.setLocationUri(defaultUri);
+    client.createDatabase(db);
+
+    db = client.getDatabase(dbName);
+
+    assertEquals("Incorrect default location of the database",
+        warehouse.getDnsPath(new Path(defaultUri)).toString(), db.getLocationUri());
+
+    db.setLocationUri(newUri);
+    client.alterDatabase(dbName, db);
+
+    db = client.getDatabase(dbName);
+
+    assertEquals("Incorrect new location of the database",
+        warehouse.getDnsPath(new Path(newUri)).toString(), db.getLocationUri());
+
+    client.dropDatabase(dbName);
+    silentDropDatabase(dbName);
+  }
+
   private void checkDbOwnerType(String dbName, String ownerName, PrincipalType ownerType)
       throws NoSuchObjectException, MetaException, TException {
     Database db = client.getDatabase(dbName);

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/TestAuthorizationPreEventListener.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/TestAuthorizationPreEventListener.java
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/TestAuthorizationPreEventListener.java
index 9dc45f2..b0da884 100644
--- a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/TestAuthorizationPreEventListener.java
+++ b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/TestAuthorizationPreEventListener.java
@@ -40,7 +40,7 @@ import org.apache.hadoop.hive.shims.ShimLoader;
 
 /**
  * TestAuthorizationPreEventListener. Test case for
- * {@link org.apache.hadoop.hive.metastore.AuthorizationPreEventListener} and
+ * {@link org.apache.hadoop.hive.ql.security.authorization.AuthorizationPreEventListener}
and
  * {@link org.apache.hadoop.hive.metastore.MetaStorePreEventListener}
  */
 public class TestAuthorizationPreEventListener extends TestCase {
@@ -160,6 +160,10 @@ public class TestAuthorizationPreEventListener extends TestCase {
     assertEquals(expectedDb, actualDb);
   }
 
+  private void validateAlterDb(Database expectedDb, Database actualDb) {
+    assertEquals(expectedDb, actualDb);
+  }
+
   public void testListener() throws Exception {
     String dbName = "hive3705";
     String tblName = "tmptbl";
@@ -325,6 +329,19 @@ public class TestAuthorizationPreEventListener extends TestCase {
 
     validateDropTable(tCustom, table2FromDropTableEvent);
 
+    // Test ALTER DATABASE SET LOCATION.
+    String oldDatabaseLocation = db.getLocationUri();
+    String newDatabaseLocation = oldDatabaseLocation.replace(db.getName(), "new." + db.getName());
+    driver.run("ALTER DATABASE " + dbName + " SET LOCATION \"" + newDatabaseLocation + "\"");
+    listSize = authCalls.size();
+    Database dbFromAlterDatabaseEvent =
+        (Database)assertAndExtractSingleObjectFromEvent(listSize, authCalls,
+        DummyHiveMetastoreAuthorizationProvider.AuthCallContextType.DB);
+    validateAlterDb(db, dbFromAlterDatabaseEvent);
+    // Reset database location.
+    driver.run("ALTER DATABASE " + dbName + " SET LOCATION \"" + oldDatabaseLocation + "\"");
+
+    // Test DROP DATABASE.
     driver.run("drop database " + dbName);
     listSize = authCalls.size();
     Database dbFromDropDatabaseEvent =

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
----------------------------------------------------------------------
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
index e0274d8..1c25189 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java
@@ -68,6 +68,7 @@ import org.apache.hadoop.hive.metastore.events.InsertEvent;
 import org.apache.hadoop.hive.metastore.events.LoadPartitionDoneEvent;
 import org.apache.hadoop.hive.metastore.events.PreAddIndexEvent;
 import org.apache.hadoop.hive.metastore.events.PreAddPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.PreAlterDatabaseEvent;
 import org.apache.hadoop.hive.metastore.events.PreAlterIndexEvent;
 import org.apache.hadoop.hive.metastore.events.PreAlterPartitionEvent;
 import org.apache.hadoop.hive.metastore.events.PreAlterTableEvent;
@@ -990,13 +991,24 @@ public class HiveMetaStore extends ThriftHiveMetastore {
     }
 
     @Override
-    public void alter_database(final String dbName, final Database db)
+    public void alter_database(final String dbName, final Database newDB)
         throws NoSuchObjectException, TException, MetaException {
       startFunction("alter_database" + dbName);
       boolean success = false;
       Exception ex = null;
+
+      // Perform the same URI normalization as create_database_core.
+      if (newDB.getLocationUri() != null) {
+        newDB.setLocationUri(wh.getDnsPath(new Path(newDB.getLocationUri())).toString());
+      }
+
       try {
-        getMS().alterDatabase(dbName, db);
+        Database oldDB = get_database_core(dbName);
+        if (oldDB == null) {
+          throw new MetaException("Could not alter database \"" + dbName + "\". Could not
retrieve old definition.");
+        }
+        firePreEvent(new PreAlterDatabaseEvent(oldDB, newDB, this));
+        getMS().alterDatabase(dbName, newDB);
         success = true;
       } catch (Exception e) {
         ex = e;

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
----------------------------------------------------------------------
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
index e5359b3..ddcb311 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
@@ -783,6 +783,12 @@ public class ObjectStore implements RawStore, Configurable {
       if (db.getOwnerType() != null) {
         mdb.setOwnerType(db.getOwnerType().name());
       }
+      if (org.apache.commons.lang.StringUtils.isNotBlank(db.getDescription())) {
+        mdb.setDescription(db.getDescription());
+      }
+      if (org.apache.commons.lang.StringUtils.isNotBlank(db.getLocationUri())) {
+        mdb.setLocationUri(db.getLocationUri());
+      }
       openTransaction();
       pm.makePersistent(mdb);
       committed = commitTransaction();

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterDatabaseEvent.java
----------------------------------------------------------------------
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterDatabaseEvent.java
b/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterDatabaseEvent.java
new file mode 100644
index 0000000..62e2674
--- /dev/null
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreAlterDatabaseEvent.java
@@ -0,0 +1,47 @@
+/**
+ * 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.metastore.events;
+
+import org.apache.hadoop.hive.metastore.HiveMetaStore.HMSHandler;
+import org.apache.hadoop.hive.metastore.api.Database;
+
+public class PreAlterDatabaseEvent extends PreEventContext {
+
+  private final Database oldDB, newDB;
+
+  public PreAlterDatabaseEvent(Database oldDB, Database newDB, HMSHandler handler) {
+    super (PreEventType.ALTER_DATABASE, handler);
+    this.oldDB = oldDB;
+    this.newDB = newDB;
+  }
+
+  /**
+   * @return the old db
+   */
+  public Database getOldDatabase () {
+    return oldDB;
+  }
+
+  /**
+   * @return the new db
+   */
+  public Database getNewDatabase() {
+    return newDB;
+  }
+}

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreEventContext.java
----------------------------------------------------------------------
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreEventContext.java
b/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreEventContext.java
index ee24a35..4ac94ea 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreEventContext.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/events/PreEventContext.java
@@ -42,7 +42,8 @@ public abstract class PreEventContext {
     READ_DATABASE,
     ADD_INDEX,
     ALTER_INDEX,
-    DROP_INDEX
+    DROP_INDEX,
+    ALTER_DATABASE
   }
 
   private final PreEventType eventType;

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java b/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
index 92859fe..76abc62 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java
@@ -930,6 +930,26 @@ public class DDLTask extends Task<DDLWork> implements Serializable
{
       database.setOwnerType(alterDbDesc.getOwnerPrincipal().getType());
       break;
 
+    case ALTER_LOCATION:
+      try {
+        String newLocation = alterDbDesc.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);
+      }
+      break;
+
     default:
       throw new AssertionError("Unsupported alter database type! : " + alterDbDesc.getAlterType());
     }

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
index 58c698d..b0e1cc9 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
@@ -467,6 +467,9 @@ public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer {
     case HiveParser.TOK_ALTERDATABASE_OWNER:
       analyzeAlterDatabaseOwner(ast);
       break;
+    case HiveParser.TOK_ALTERDATABASE_LOCATION:
+      analyzeAlterDatabaseLocation(ast);
+      break;
     case HiveParser.TOK_CREATEROLE:
       analyzeCreateRole(ast);
       break;
@@ -712,6 +715,14 @@ public class DDLSemanticAnalyzer extends BaseSemanticAnalyzer {
     addAlterDbDesc(alterDesc);
   }
 
+  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);
+    addAlterDbDesc(alterDesc);
+  }
+
   private void analyzeExchangePartition(String[] qualified, ASTNode ast) throws SemanticException
{
     Table destTable = getTable(qualified);
     Table sourceTable = getTable(getUnescapedName((ASTNode)ast.getChild(1)));

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
index 00b872d..b6653f0 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g
@@ -328,6 +328,7 @@ TOK_DATABASELOCATION;
 TOK_DBPROPLIST;
 TOK_ALTERDATABASE_PROPERTIES;
 TOK_ALTERDATABASE_OWNER;
+TOK_ALTERDATABASE_LOCATION;
 TOK_TABNAME;
 TOK_TABSRC;
 TOK_RESTRICT;
@@ -1154,6 +1155,7 @@ alterDatabaseStatementSuffix
 @after { popMsg(state); }
     : alterDatabaseSuffixProperties
     | alterDatabaseSuffixSetOwner
+    | alterDatabaseSuffixSetLocation
     ;
 
 alterDatabaseSuffixProperties
@@ -1170,6 +1172,13 @@ alterDatabaseSuffixSetOwner
     -> ^(TOK_ALTERDATABASE_OWNER $dbName principalName)
     ;
 
+alterDatabaseSuffixSetLocation
+@init { pushMsg("alter database set location", state); }
+@after { popMsg(state); }
+    : dbName=identifier KW_SET KW_LOCATION newLocation=StringLiteral
+    -> ^(TOK_ALTERDATABASE_LOCATION $dbName $newLocation)
+    ;
+
 alterStatementSuffixRename[boolean table]
 @init { pushMsg("rename statement", state); }
 @after { popMsg(state); }

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java
index 6b500bb..f4af31c 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzerFactory.java
@@ -113,6 +113,7 @@ public final class SemanticAnalyzerFactory {
     commandType.put(HiveParser.TOK_SHOW_ROLE_GRANT, HiveOperation.SHOW_ROLE_GRANT);
     commandType.put(HiveParser.TOK_ALTERDATABASE_PROPERTIES, HiveOperation.ALTERDATABASE);
     commandType.put(HiveParser.TOK_ALTERDATABASE_OWNER, HiveOperation.ALTERDATABASE_OWNER);
+    commandType.put(HiveParser.TOK_ALTERDATABASE_LOCATION, HiveOperation.ALTERDATABASE_LOCATION);
     commandType.put(HiveParser.TOK_DESCDATABASE, HiveOperation.DESCDATABASE);
     commandType.put(HiveParser.TOK_ALTERTABLE_SKEWED, HiveOperation.ALTERTABLE_SKEWED);
     commandType.put(HiveParser.TOK_ANALYZE, HiveOperation.ANALYZE_TABLE);
@@ -282,6 +283,7 @@ public final class SemanticAnalyzerFactory {
       case HiveParser.TOK_SHOW_ROLES:
       case HiveParser.TOK_ALTERDATABASE_PROPERTIES:
       case HiveParser.TOK_ALTERDATABASE_OWNER:
+      case HiveParser.TOK_ALTERDATABASE_LOCATION:
       case HiveParser.TOK_TRUNCATETABLE:
       case HiveParser.TOK_SHOW_SET_ROLE:
       case HiveParser.TOK_CACHE_METADATA:

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/ql/src/java/org/apache/hadoop/hive/ql/plan/AlterDatabaseDesc.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/plan/AlterDatabaseDesc.java b/ql/src/java/org/apache/hadoop/hive/ql/plan/AlterDatabaseDesc.java
index 5e218c4..4bbf2df 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/plan/AlterDatabaseDesc.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/plan/AlterDatabaseDesc.java
@@ -34,13 +34,14 @@ public class AlterDatabaseDesc extends DDLDesc implements Serializable
{
 
   // Only altering the database property and owner is currently supported
   public static enum ALTER_DB_TYPES {
-    ALTER_PROPERTY, ALTER_OWNER
+    ALTER_PROPERTY, ALTER_OWNER, ALTER_LOCATION
   };
 
   ALTER_DB_TYPES alterType;
   String databaseName;
   Map<String, String> dbProperties;
   PrincipalDesc ownerPrincipal;
+  String location;
 
   /**
    * For serialization only.
@@ -52,6 +53,7 @@ public class AlterDatabaseDesc extends DDLDesc implements Serializable {
     super();
     this.databaseName = databaseName;
     this.dbProperties = dbProps;
+    this.setDatabaseProperties(dbProps);
     this.setAlterType(ALTER_DB_TYPES.ALTER_PROPERTY);
   }
 
@@ -61,6 +63,12 @@ public class AlterDatabaseDesc extends DDLDesc implements Serializable
{
     this.setAlterType(ALTER_DB_TYPES.ALTER_OWNER);
   }
 
+  public AlterDatabaseDesc(String databaseName, String newLocation) {
+    this.databaseName = databaseName;
+    this.setLocation(newLocation);
+    this.setAlterType(ALTER_DB_TYPES.ALTER_LOCATION);
+  }
+
   @Explain(displayName="properties")
   public Map<String, String> getDatabaseProperties() {
     return dbProperties;
@@ -88,6 +96,14 @@ public class AlterDatabaseDesc extends DDLDesc implements Serializable
{
     this.ownerPrincipal = ownerPrincipal;
   }
 
+  @Explain(displayName="location")
+  public String getLocation() {
+    return location;
+  }
+
+  public void setLocation(String location) {
+    this.location = location;
+  }
   public ALTER_DB_TYPES getAlterType() {
     return alterType;
   }

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/ql/src/java/org/apache/hadoop/hive/ql/plan/HiveOperation.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/plan/HiveOperation.java b/ql/src/java/org/apache/hadoop/hive/ql/plan/HiveOperation.java
index d2746ae..d331be4 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/plan/HiveOperation.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/plan/HiveOperation.java
@@ -107,6 +107,7 @@ public enum HiveOperation {
   ALTERINDEX_PROPS("ALTERINDEX_PROPS",null, null),
   ALTERDATABASE("ALTERDATABASE", null, null),
   ALTERDATABASE_OWNER("ALTERDATABASE_OWNER", null, null),
+  ALTERDATABASE_LOCATION("ALTERDATABASE_LOCATION", new Privilege[]{Privilege.ALTER_DATA},
null),
   DESCDATABASE("DESCDATABASE", null, null),
   ALTERTABLE_MERGEFILES("ALTER_TABLE_MERGE", new Privilege[] { Privilege.SELECT }, new Privilege[]
{ Privilege.ALTER_DATA }),
   ALTERPARTITION_MERGEFILES("ALTER_PARTITION_MERGE", new Privilege[] { Privilege.SELECT },
new Privilege[] { Privilege.ALTER_DATA }),

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/AuthorizationPreEventListener.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/AuthorizationPreEventListener.java
b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/AuthorizationPreEventListener.java
index 82e7fc5..17630a3 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/AuthorizationPreEventListener.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/AuthorizationPreEventListener.java
@@ -38,6 +38,7 @@ import org.apache.hadoop.hive.metastore.api.MetaException;
 import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
 import org.apache.hadoop.hive.metastore.api.Partition;
 import org.apache.hadoop.hive.metastore.events.PreAddPartitionEvent;
+import org.apache.hadoop.hive.metastore.events.PreAlterDatabaseEvent;
 import org.apache.hadoop.hive.metastore.events.PreAlterPartitionEvent;
 import org.apache.hadoop.hive.metastore.events.PreAlterTableEvent;
 import org.apache.hadoop.hive.metastore.events.PreCreateDatabaseEvent;
@@ -163,6 +164,9 @@ public class AuthorizationPreEventListener extends MetaStorePreEventListener
{
     case CREATE_DATABASE:
       authorizeCreateDatabase((PreCreateDatabaseEvent)context);
       break;
+    case ALTER_DATABASE:
+        authorizeAlterDatabase((PreAlterDatabaseEvent) context);
+        break;
     case DROP_DATABASE:
       authorizeDropDatabase((PreDropDatabaseEvent)context);
       break;
@@ -257,6 +261,21 @@ public class AuthorizationPreEventListener extends MetaStorePreEventListener
{
     }
   }
 
+  private void authorizeAlterDatabase(PreAlterDatabaseEvent context)
+      throws InvalidOperationException, MetaException {
+    try {
+      for (HiveMetastoreAuthorizationProvider authorizer : tAuthorizers.get()) {
+        authorizer.authorize(new Database(context.getOldDatabase()),
+            HiveOperation.ALTERDATABASE_LOCATION.getInputRequiredPrivileges(),
+            HiveOperation.ALTERDATABASE_LOCATION.getOutputRequiredPrivileges());
+      }
+    } catch (AuthorizationException e) {
+      throw invalidOperationException(e);
+    } catch (HiveException e) {
+      throw metaException(e);
+    }
+  }
+
   private void authorizeCreateTable(PreCreateTableEvent context)
       throws InvalidOperationException, MetaException {
     try {

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/HiveOperationType.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/HiveOperationType.java
b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/HiveOperationType.java
index c507f67..b1022b1 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/HiveOperationType.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/HiveOperationType.java
@@ -113,6 +113,7 @@ public enum HiveOperationType {
   ALTERINDEX_PROPS,
   ALTERDATABASE,
   ALTERDATABASE_OWNER,
+  ALTERDATABASE_LOCATION,
   DESCDATABASE,
   ALTERTABLE_MERGEFILES,
   ALTERPARTITION_MERGEFILES,

http://git-wip-us.apache.org/repos/asf/hive/blob/289d8342/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/sqlstd/Operation2Privilege.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/sqlstd/Operation2Privilege.java
b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/sqlstd/Operation2Privilege.java
index cd608b3..6880671 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/sqlstd/Operation2Privilege.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/sqlstd/Operation2Privilege.java
@@ -372,6 +372,8 @@ public class Operation2Privilege {
 (null, ADMIN_PRIV_AR));
     op2Priv.put(HiveOperationType.ALTERDATABASE_OWNER, PrivRequirement.newIOPrivRequirement
 (null, ADMIN_PRIV_AR));
+    op2Priv.put(HiveOperationType.ALTERDATABASE_LOCATION, PrivRequirement.newIOPrivRequirement
+(null, ADMIN_PRIV_AR));
     op2Priv.put(HiveOperationType.DESCDATABASE, PrivRequirement.newIOPrivRequirement
 (null, null));
     op2Priv.put(HiveOperationType.DFS, PrivRequirement.newIOPrivRequirement


Mime
View raw message