diff --git metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java index a3f2359..5391171 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java @@ -175,8 +175,8 @@ public void alterTable(RawStore msdb, Warehouse wh, String dbname, // 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); diff --git ql/src/test/queries/clientpositive/alter_change_db_location.q ql/src/test/queries/clientpositive/alter_change_db_location.q new file mode 100644 index 0000000..a74ba2a --- /dev/null +++ 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; diff --git ql/src/test/results/clientpositive/alter_change_db_location.q.out ql/src/test/results/clientpositive/alter_change_db_location.q.out new file mode 100644 index 0000000..64bd680 --- /dev/null +++ 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