Index: ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java (revision 1186306) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java (working copy) @@ -186,7 +186,7 @@ NO_COMPARE_BIGINT_DOUBLE("In strict mode, comparing bigints and doubles is not allowed, " + "it may result in a loss of precision. " + "If you really want to perform the operation, set hive.mapred.mode=nonstrict"), - FUNCTIONS_ARE_NOT_SUPPORTED_IN_ORDER_BY("functions are not supported in order by"), + FUNCTIONS_ARE_NOT_SUPPORTED_IN_CLAUSE("functions are not supported in the clause"), ; private String mesg; Index: ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java =================================================================== --- ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (revision 1186306) +++ ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (working copy) @@ -4551,9 +4551,7 @@ // ClusterBy order.append("+"); } - if (cl.getType() == HiveParser.TOK_FUNCTION) { - throw new SemanticException(ErrorMsg.FUNCTIONS_ARE_NOT_SUPPORTED_IN_ORDER_BY.getMsg()); - } + validateClause(cl, sortExprs); ExprNodeDesc exprNode = genExprNodeDesc(cl, inputRR); sortCols.add(exprNode); } @@ -4605,6 +4603,15 @@ return output; } + public void validateClause(ASTNode childNode, ASTNode rootNode) throws SemanticException { + if (rootNode.getType() == HiveParser.TOK_ORDERBY || rootNode.getType() == HiveParser.TOK_SORTBY) { + if (childNode.getType() == HiveParser.TOK_FUNCTION) { + throw new SemanticException(ErrorMsg.FUNCTIONS_ARE_NOT_SUPPORTED_IN_CLAUSE + .getMsg(rootNode.getText())); + } + } + } + private Operator genJoinOperatorChildren(QBJoinTree join, Operator left, Operator[] right, HashSet omitOpts) throws SemanticException { Index: ql/src/test/queries/clientnegative/orderby_function.q =================================================================== --- ql/src/test/queries/clientnegative/orderby_function.q (revision 1186306) +++ ql/src/test/queries/clientnegative/orderby_function.q (working copy) @@ -1 +1 @@ -select src.key FROM src ORDER BY count(1) limit 1; +select src.key FROM src ORDER BY count(1) limit 1; Index: ql/src/test/queries/clientnegative/sortby_function.q =================================================================== --- ql/src/test/queries/clientnegative/sortby_function.q (revision 0) +++ ql/src/test/queries/clientnegative/sortby_function.q (revision 0) @@ -0,0 +1 @@ +select src.key FROM src SORT BY count(1); Index: ql/src/test/results/clientnegative/orderby_function.q.out =================================================================== --- ql/src/test/results/clientnegative/orderby_function.q.out (revision 1186306) +++ ql/src/test/results/clientnegative/orderby_function.q.out (working copy) @@ -1 +1 @@ -FAILED: Error in semantic analysis: functions are not supported in order by +FAILED: Error in semantic analysis: functions are not supported in the clause TOK_ORDERBY Index: ql/src/test/results/clientnegative/sortby_function.q.out =================================================================== --- ql/src/test/results/clientnegative/sortby_function.q.out (revision 0) +++ ql/src/test/results/clientnegative/sortby_function.q.out (revision 0) @@ -0,0 +1 @@ +FAILED: Error in semantic analysis: functions are not supported in the clause TOK_SORTBY