diff --git ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java index 77305ff..f849221 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -1416,13 +1416,7 @@ public void getMetaData(QB qb, ReadEntity parentInput) throws SemanticException // allocate a temporary output dir on the location of the table String tableName = getUnescapedName((ASTNode) ast.getChild(0)); Table newTable = db.newTable(tableName); - Path location; - try { - Warehouse wh = new Warehouse(conf); - location = wh.getDatabasePath(db.getDatabase(newTable.getDbName())); - } catch (MetaException e) { - throw new SemanticException(e); - } + Path location = getCTASTableName(qb); try { fname = ctx.getExternalTmpPath( FileUtils.makeQualified(location, conf).toUri()).toString(); @@ -11329,4 +11323,25 @@ private void addAlternateGByKeyMappings(ASTNode gByExpr, ColumnInfo colInfo, else return (ltd.getReplace() ? WriteEntity.WriteType.INSERT_OVERWRITE : WriteEntity.WriteType.INSERT); } + + private Path getCTASTableName(QB qb) throws SemanticException { + // get the table's default location + Table dumpTable; + Path targetPath; + try { + dumpTable = db.newTable(qb.getTableDesc().getTableName()); + if (!db.databaseExists(dumpTable.getDbName())) { + throw new SemanticException("ERROR: The database " + dumpTable.getDbName() + + " does not exist."); + } + Warehouse wh = new Warehouse(conf); + targetPath = wh.getTablePath(db.getDatabase(dumpTable.getDbName()), + dumpTable.getTableName()); + } catch (HiveException e) { + throw new SemanticException(e); + } catch (MetaException e) { + throw new SemanticException(e); + } + return targetPath; + } }