Skip to content

Commit

Permalink
Added semantic error for HAVING without GROUP BY
Browse files Browse the repository at this point in the history
  • Loading branch information
willb committed Jun 20, 2014
1 parent 942428e commit b880bef
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b880bef

Please sign in to comment.