Skip to content

Commit

Permalink
Added casts to HAVING expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
willb committed Jun 20, 2014
1 parent 83f1340 commit 3bbaf26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -587,8 +587,11 @@ private[hive] object HiveQl {
throw new SemanticException("HAVING specified without GROUP BY")
}

val Seq(havingExpr) = h.getChildren.toSeq
Filter(nodeToExpr(havingExpr), withDistinct)
val havingExpr = h.getChildren.toSeq match {
case Seq(hexpr) => nodeToExpr(hexpr)
}

Filter(Cast(havingExpr, BooleanType), withDistinct)
}.getOrElse(withDistinct)

val withSort =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ class HiveQuerySuite extends HiveComparisonTest {

TestHive.sparkContext.parallelize(fixture).registerAsTable("having_test")

val results = hql("SELECT value, max(attr) AS attr FROM having_test GROUP BY value HAVING attr > 3")
val results =
hql("SELECT value, max(attr) AS attr FROM having_test GROUP BY value HAVING attr > 3")
.collect()
.map(x => Pair(x.getString(0), x.getInt(1)))

Expand All @@ -244,6 +245,10 @@ class HiveQuerySuite extends HiveComparisonTest {
hql("SELECT value, attr FROM having_test HAVING attr > 3")
}
}

test("SPARK-2180: HAVING with non-boolean clause raises no exceptions") {
val results = hql("select key, count(*) c from src group by key having c").collect()
}

test("Query Hive native command execution result") {
val tableName = "test_native_commands"
Expand Down

0 comments on commit 3bbaf26

Please sign in to comment.