Index: ql/src/test/results/clientnegative/groupby2_key.q.out =================================================================== --- ql/src/test/results/clientnegative/groupby2_key.q.out (revision 0) +++ ql/src/test/results/clientnegative/groupby2_key.q.out (revision 0) @@ -0,0 +1 @@ +FAILED: Error in semantic analysis: line 1:22 Repeated Key in Group By and Distinct value Index: ql/src/test/queries/clientnegative/groupby2_key.q =================================================================== --- ql/src/test/queries/clientnegative/groupby2_key.q (revision 0) +++ ql/src/test/queries/clientnegative/groupby2_key.q (revision 0) @@ -0,0 +1 @@ +SELECT count(distinct value) FROM src GROUP BY value; Index: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (revision 1069320) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (working copy) @@ -2664,6 +2664,10 @@ int ri; for (ri = 0; ri < reduceKeys.size(); ri++) { if (reduceKeys.get(ri).getExprString().equals(expr.getExprString())) { + if (ri < grpByExprs.size()) { + throw new SemanticException(ErrorMsg.DUPLICATE_GROUPBY_DISTINCT_KEY + .getMsg(parameter)); + } break; } } Index: ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java (revision 1069320) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java (working copy) @@ -60,6 +60,7 @@ INVALID_JOIN_CONDITION_3("OR not supported in Join currently"), INVALID_TRANSFORM("TRANSFORM with Other Select Columns not Supported"), DUPLICATE_GROUPBY_KEY("Repeated Key in Group By"), + DUPLICATE_GROUPBY_DISTINCT_KEY("Repeated Key in Group By and Distinct"), UNSUPPORTED_MULTIPLE_DISTINCTS("DISTINCT on Different Columns not Supported with skew in data"), NO_SUBQUERY_ALIAS("No Alias For Subquery"), NO_INSERT_INSUBQUERY("Cannot insert in a Subquery. Inserting to table "),