Index: metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (revision 1076105) +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (revision ) @@ -538,6 +538,8 @@ ms.openTransaction(); if (null == db.getLocationUri()) { db.setLocationUri(wh.getDefaultDatabasePath(db.getName()).toString()); + } else { + db.setLocationUri(wh.getDnsPath(new Path(db.getLocationUri())).toString()); } ms.createDatabase(db); success = ms.commitTransaction(); @@ -866,7 +868,7 @@ } private void create_table_core(final RawStore ms, final Table tbl) - throws AlreadyExistsException, MetaException, InvalidObjectException { + throws AlreadyExistsException, MetaException, InvalidObjectException, NoSuchObjectException { if (!MetaStoreUtils.validateName(tbl.getTableName()) || !MetaStoreUtils.validateColNames(tbl.getSd().getCols()) @@ -890,8 +892,7 @@ if (!TableType.VIRTUAL_VIEW.toString().equals(tbl.getTableType())) { if (tbl.getSd().getLocation() == null || tbl.getSd().getLocation().isEmpty()) { - tblPath = wh.getDefaultTablePath( - tbl.getDbName(), tbl.getTableName()); + tblPath = wh.getTablePath(ms.getDatabase(tbl.getDbName()), tbl.getTableName()); } else { if (!isExternal(tbl) && !MetaStoreUtils.isNonNativeTable(tbl)) { LOG.warn("Location: " + tbl.getSd().getLocation() Index: metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java (revision 1061038) +++ metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java (revision ) @@ -40,6 +40,7 @@ import org.apache.hadoop.hive.common.FileUtils; import org.apache.hadoop.hive.common.JavaUtils; import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.metastore.api.Database; import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.metastore.api.MetaException; import org.apache.hadoop.util.ReflectionUtils; @@ -148,6 +149,18 @@ return new Path(getWhRoot(), dbName.toLowerCase() + DATABASE_WAREHOUSE_SUFFIX); } + public Path getDatabasePath(Database db) throws MetaException { + if (db.getName().equalsIgnoreCase(DEFAULT_DATABASE_NAME)) { + return getWhRoot(); + } + return new Path(db.getLocationUri(), db.getName().toLowerCase() + DATABASE_WAREHOUSE_SUFFIX); + } + + public Path getTablePath(Database db, String tableName) + throws MetaException { + return new Path(getDatabasePath(db), tableName.toLowerCase()); + } + public Path getDefaultTablePath(String dbName, String tableName) throws MetaException { return new Path(getDefaultDatabasePath(dbName), tableName.toLowerCase());