Index: metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java (revision 1571889) +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java (working copy) @@ -511,16 +511,37 @@ hook.preCreateTable(tbl); } boolean success = false; + boolean rolledBack = false; try { client.create_table_with_environment_context(tbl, envContext); if (hook != null) { hook.commitCreateTable(tbl); } success = true; - } finally { + } catch(Exception e) { if (!success && (hook != null)) { hook.rollbackCreateTable(tbl); + rolledBack = true; } + if (e instanceof AlreadyExistsException) { + throw (AlreadyExistsException)(e); + } + else if (e instanceof InvalidObjectException) { + throw (InvalidObjectException)(e); + } + else if (e instanceof MetaException) { + throw (MetaException)(e); + } + else if (e instanceof NoSuchObjectException) { + throw (NoSuchObjectException)(e); + } + else if (e instanceof TException) { + throw (TException)(e); + } + } finally { + if (!success && (hook != null) && !rolledBack) { + hook.rollbackCreateTable(tbl); + } } } Index: metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (revision 1571889) +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (working copy) @@ -1175,21 +1175,25 @@ + " already exists"); } - if (!TableType.VIRTUAL_VIEW.toString().equals(tbl.getTableType())) { - if (tbl.getSd().getLocation() == null - || tbl.getSd().getLocation().isEmpty()) { - tblPath = wh.getTablePath( - ms.getDatabase(tbl.getDbName()), tbl.getTableName()); - } else { - if (!isExternal(tbl) && !MetaStoreUtils.isNonNativeTable(tbl)) { - LOG.warn("Location: " + tbl.getSd().getLocation() - + " specified for non-external table:" + tbl.getTableName()); - } - tblPath = wh.getDnsPath(new Path(tbl.getSd().getLocation())); - } - tbl.getSd().setLocation(tblPath.toString()); + try { + if (!TableType.VIRTUAL_VIEW.toString().equals(tbl.getTableType())) { + if (tbl.getSd().getLocation() == null + || tbl.getSd().getLocation().isEmpty()) { + tblPath = wh.getTablePath( + ms.getDatabase(tbl.getDbName()), tbl.getTableName()); + } else { + if (!isExternal(tbl) && !MetaStoreUtils.isNonNativeTable(tbl)) { + LOG.warn("Location: " + tbl.getSd().getLocation() + + " specified for non-external table:" + tbl.getTableName()); + } + tblPath = wh.getDnsPath(new Path(tbl.getSd().getLocation())); + } + tbl.getSd().setLocation(tblPath.toString()); + } + } catch(Exception e) { + throw new MetaException("Error while trying to locate the table : " + + e.getMessage()); } - if (tblPath != null) { if (!wh.isDir(tblPath)) { if (!wh.mkdirs(tblPath)) {