diff --git ql/src/java/org/apache/hadoop/hive/ql/Context.java ql/src/java/org/apache/hadoop/hive/ql/Context.java index f04aed47b2..d6046d19d8 100644 --- ql/src/java/org/apache/hadoop/hive/ql/Context.java +++ ql/src/java/org/apache/hadoop/hive/ql/Context.java @@ -56,6 +56,7 @@ import org.apache.hadoop.hive.ql.parse.ExplainConfiguration; import org.apache.hadoop.hive.ql.parse.ExplainConfiguration.AnalyzeState; import org.apache.hadoop.hive.ql.parse.HiveParser; +import org.apache.hadoop.hive.ql.parse.QB; import org.apache.hadoop.hive.ql.plan.LoadTableDesc; import org.apache.hadoop.hive.ql.session.SessionState; import org.apache.hadoop.hive.shims.ShimLoader; @@ -169,8 +170,17 @@ private String getMatchedText(ASTNode n) { /** * The suffix is always relative to a given ASTNode */ - public DestClausePrefix getDestNamePrefix(ASTNode curNode) { + public DestClausePrefix getDestNamePrefix(ASTNode curNode, QB queryBlock) { assert curNode != null : "must supply curNode"; + if(queryBlock.isInsideView() || queryBlock.getParseInfo().getIsSubQ()) { + /** + * Views get inlined in the logical plan but not in the AST + * {@link org.apache.hadoop.hive.ql.parse.SemanticAnalyzer#replaceViewReferenceWithDefinition(QB, Table, String, String)} + * Since here we only care to identify clauses representing Update/Delete which are not + * possible inside a view/subquery, we can immediately return the default {@link DestClausePrefix.INSERT} + */ + return DestClausePrefix.INSERT; + } if(curNode.getType() != HiveParser.TOK_INSERT_INTO) { //select statement assert curNode.getType() == HiveParser.TOK_DESTINATION; 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 1c74779dec..db29e3aa5d 100644 --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java @@ -1490,7 +1490,7 @@ public boolean doPhase1(ASTNode ast, QB qb, Phase1Ctx ctx_1, PlannerContext plan qbp.addInsertIntoTable(tab_name, ast); case HiveParser.TOK_DESTINATION: - ctx_1.dest = this.ctx.getDestNamePrefix(ast).toString() + ctx_1.nextNum; + ctx_1.dest = this.ctx.getDestNamePrefix(ast, qb).toString() + ctx_1.nextNum; ctx_1.nextNum++; boolean isTmpFileDest = false; if (ast.getChildCount() > 0 && ast.getChild(0) instanceof ASTNode) {