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/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/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java (revision 51256) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java (working copy) @@ -59,6 +59,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 "), Index: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (revision 52697) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (working copy) @@ -2472,6 +2472,9 @@ break; } } + if (ri < grpByExprs.size()) { + throw new SemanticException(ErrorMsg.DUPLICATE_GROUPBY_DISTINCT_KEY.getMsg(parameter)); + } // add the expr to reduceKeys if it is not present if (ri == reduceKeys.size()) { reduceKeys.add(expr);