File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
main/scala/org/apache/spark/sql/hive
test/scala/org/apache/spark/sql/hive/execution Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -587,8 +587,11 @@ private[hive] object HiveQl {
587587 throw new SemanticException (" HAVING specified without GROUP BY" )
588588 }
589589
590- val Seq (havingExpr) = h.getChildren.toSeq
591- Filter (nodeToExpr(havingExpr), withDistinct)
590+ val havingExpr = h.getChildren.toSeq match {
591+ case Seq (hexpr) => nodeToExpr(hexpr)
592+ }
593+
594+ Filter (Cast (havingExpr, BooleanType ), withDistinct)
592595 }.getOrElse(withDistinct)
593596
594597 val withSort =
Original file line number Diff line number Diff line change @@ -230,7 +230,8 @@ class HiveQuerySuite extends HiveComparisonTest {
230230
231231 TestHive .sparkContext.parallelize(fixture).registerAsTable(" having_test" )
232232
233- val results = hql(" SELECT value, max(attr) AS attr FROM having_test GROUP BY value HAVING attr > 3" )
233+ val results =
234+ hql(" SELECT value, max(attr) AS attr FROM having_test GROUP BY value HAVING attr > 3" )
234235 .collect()
235236 .map(x => Pair (x.getString(0 ), x.getInt(1 )))
236237
@@ -244,6 +245,10 @@ class HiveQuerySuite extends HiveComparisonTest {
244245 hql(" SELECT value, attr FROM having_test HAVING attr > 3" )
245246 }
246247 }
248+
249+ test(" SPARK-2180: HAVING with non-boolean clause raises no exceptions" ) {
250+ val results = hql(" select key, count(*) c from src group by key having c" ).collect()
251+ }
247252
248253 test(" Query Hive native command execution result" ) {
249254 val tableName = " test_native_commands"
You can’t perform that action at this time.
0 commit comments