Skip to content

Commit b880bef

Browse files
committed
Added semantic error for HAVING without GROUP BY
1 parent 942428e commit b880bef

File tree

1 file changed

+8
-0
lines changed
  • sql/hive/src/main/scala/org/apache/spark/sql/hive

1 file changed

+8
-0
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ private[hive] object HiveQl {
204204
class ParseException(sql: String, cause: Throwable)
205205
extends Exception(s"Failed to parse: $sql", cause)
206206

207+
class SemanticException(msg: String)
208+
extends Exception(msg)
209+
207210
/**
208211
* Returns the AST for the given SQL string.
209212
*/
@@ -579,6 +582,11 @@ private[hive] object HiveQl {
579582
if (selectDistinctClause.isDefined) Distinct(withProject) else withProject
580583

581584
val withHaving = havingClause.map { h =>
585+
586+
if (groupByClause == None) {
587+
throw new SemanticException("Error in semantic analysis: HAVING specified without GROUP BY")
588+
}
589+
582590
val Seq(havingExpr) = h.getChildren.toSeq
583591
Filter(nodeToExpr(havingExpr), withDistinct)
584592
}.getOrElse(withDistinct)

0 commit comments

Comments
 (0)