HIVE-10719: Hive metastore failure when alter table rename is attempted. 
(Vikram Dixit K, reviewed by Thejas Nair, Sergey Shelukhin)


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

Branch: refs/heads/parquet
Commit: 325a592f5f670bef6d6921161ef2d511d21c07d8
Parents: 129c496
Author: vikram <vik...@hortonworks.com>
Authored: Mon May 18 12:46:49 2015 -0700
Committer: vikram <vik...@hortonworks.com>
Committed: Mon May 18 13:52:46 2015 -0700

----------------------------------------------------------------------
 .../hadoop/hive/metastore/HiveAlterHandler.java |  4 +--
 .../clientpositive/alter_change_db_location.q   |  5 +++
 .../alter_change_db_location.q.out              | 35 ++++++++++++++++++++
 3 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/325a592f/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
----------------------------------------------------------------------
diff --git 
a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java 
b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
index a3f2359..5391171 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
@@ -175,8 +175,8 @@ public class HiveAlterHandler implements AlterHandler {
         // that means user is asking metastore to move data to new location
         // corresponding to the new name
         // get new location
-        Path databasePath = constructRenamedPath(
-            wh.getDefaultDatabasePath(newt.getDbName()), srcPath);
+        Database db = msdb.getDatabase(newt.getDbName());
+        Path databasePath = constructRenamedPath(wh.getDatabasePath(db), 
srcPath);
         destPath = new Path(databasePath, newt.getTableName());
         destFs = wh.getFs(destPath);
 

http://git-wip-us.apache.org/repos/asf/hive/blob/325a592f/ql/src/test/queries/clientpositive/alter_change_db_location.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientpositive/alter_change_db_location.q 
b/ql/src/test/queries/clientpositive/alter_change_db_location.q
new file mode 100644
index 0000000..a74ba2a
--- /dev/null
+++ b/ql/src/test/queries/clientpositive/alter_change_db_location.q
@@ -0,0 +1,5 @@
+create database newDB location "/tmp/";
+describe database extended newDB;
+use newDB;
+create table tab (name string);
+alter table tab rename to newName;

http://git-wip-us.apache.org/repos/asf/hive/blob/325a592f/ql/src/test/results/clientpositive/alter_change_db_location.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientpositive/alter_change_db_location.q.out 
b/ql/src/test/results/clientpositive/alter_change_db_location.q.out
new file mode 100644
index 0000000..64bd680
--- /dev/null
+++ b/ql/src/test/results/clientpositive/alter_change_db_location.q.out
@@ -0,0 +1,35 @@
+#### A masked pattern was here ####
+PREHOOK: type: CREATEDATABASE
+PREHOOK: Output: database:newDB
+#### A masked pattern was here ####
+POSTHOOK: type: CREATEDATABASE
+POSTHOOK: Output: database:newDB
+#### A masked pattern was here ####
+PREHOOK: query: describe database extended newDB
+PREHOOK: type: DESCDATABASE
+POSTHOOK: query: describe database extended newDB
+POSTHOOK: type: DESCDATABASE
+newdb          location/in/test        hive_test_user  USER    
+PREHOOK: query: use newDB
+PREHOOK: type: SWITCHDATABASE
+PREHOOK: Input: database:newdb
+POSTHOOK: query: use newDB
+POSTHOOK: type: SWITCHDATABASE
+POSTHOOK: Input: database:newdb
+PREHOOK: query: create table tab (name string)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:newdb
+PREHOOK: Output: newDB@tab
+POSTHOOK: query: create table tab (name string)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:newdb
+POSTHOOK: Output: newDB@tab
+PREHOOK: query: alter table tab rename to newName
+PREHOOK: type: ALTERTABLE_RENAME
+PREHOOK: Input: newdb@tab
+PREHOOK: Output: newdb@tab
+POSTHOOK: query: alter table tab rename to newName
+POSTHOOK: type: ALTERTABLE_RENAME
+POSTHOOK: Input: newdb@tab
+POSTHOOK: Output: newDB@newName
+POSTHOOK: Output: newdb@tab

Reply via email to