Index: ql/src/test/results/clientnegative/join_ambig_cond.q.out =================================================================== --- ql/src/test/results/clientnegative/join_ambig_cond.q.out (revision 0) +++ ql/src/test/results/clientnegative/join_ambig_cond.q.out (revision 0) @@ -0,0 +1 @@ +FAILED: Error in semantic analysis: line 1:40 Ambiguous Table Alias or Column Reference key Index: ql/src/test/queries/clientnegative/join_ambig_cond.q =================================================================== --- ql/src/test/queries/clientnegative/join_ambig_cond.q (revision 0) +++ ql/src/test/queries/clientnegative/join_ambig_cond.q (revision 0) @@ -0,0 +1 @@ +SELECT * FROM src src1 JOIN src src2 ON key Index: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (revision 4721) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (working copy) @@ -981,6 +981,32 @@ } /** + * Checks if the node is just an un-prefixed column. This could be either + * a primitive type column name like 'key' or a complex type column like + * 'col[x]' or 'S.x'. In either case, return true if there is no table + * prefix for the column and false otherwise. + * + * @param cond + * ASTNode to be checke + * + * @return whether the node is an column without a table prefix + */ + + private boolean isColumnWithoutTablePrefix(ASTNode cond) { + if (cond.getChildCount() > 0) { + int tokenType = cond.getToken().getType(); + int childTokenType = ((ASTNode) cond.getChild(0)).getToken().getType(); + if ( (tokenType == HiveParser.TOK_TABLE_OR_COL) || + ( ((tokenType == HiveParser.DOT) || + (tokenType == HiveParser.LSQUARE)) && + (childTokenType == HiveParser.TOK_TABLE_OR_COL) )) { + return true; + } + } + return false; + } + + /** * Parse the join condition. If the condition is a join condition, throw an * error if it is not an equality. Otherwise, break it into left and right * expressions and store in the join tree. If the condition is a join filter, @@ -1079,6 +1105,11 @@ rightAlias.add(right); } + if (isColumnWithoutTablePrefix(joinCond)) { + throw new SemanticException(ErrorMsg.AMBIGUOUS_TABLE_OR_COLUMN.getMsg(joinCond. + getChild(0))); + } + for (int ci = childrenBegin; ci < joinCond.getChildCount(); ci++) { parseJoinCondPopulateAlias(joinTree, (ASTNode) joinCond.getChild(ci), leftAlias.get(ci - childrenBegin), rightAlias.get(ci