From b880bef264431f6ab71032b6bd8b63a521f4cb84 Mon Sep 17 00:00:00 2001 From: William Benton Date: Thu, 19 Jun 2014 15:59:08 -0500 Subject: [PATCH] Added semantic error for HAVING without GROUP BY --- .../src/main/scala/org/apache/spark/sql/hive/HiveQl.scala | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala index 67ab17dd1fc20..fe05757753b1f 100644 --- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala +++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala @@ -204,6 +204,9 @@ private[hive] object HiveQl { class ParseException(sql: String, cause: Throwable) extends Exception(s"Failed to parse: $sql", cause) + class SemanticException(msg: String) + extends Exception(msg) + /** * Returns the AST for the given SQL string. */ @@ -579,6 +582,11 @@ private[hive] object HiveQl { if (selectDistinctClause.isDefined) Distinct(withProject) else withProject val withHaving = havingClause.map { h => + + if (groupByClause == None) { + throw new SemanticException("Error in semantic analysis: HAVING specified without GROUP BY") + } + val Seq(havingExpr) = h.getChildren.toSeq Filter(nodeToExpr(havingExpr), withDistinct) }.getOrElse(withDistinct)