Skip to content

Commit 942428e

Browse files
committed
Added test coverage for SPARK-2180.
This is a simple test for HAVING clauses.
1 parent 56084cc commit 942428e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,21 @@ class HiveQuerySuite extends HiveComparisonTest {
224224
TestHive.reset()
225225
}
226226

227+
test("SPARK-2180: HAVING support in GROUP BY clauses") {
228+
val fixture = List(("foo", 2), ("bar", 1), ("foo", 4), ("bar", 3))
229+
.zipWithIndex.map {case Pair(Pair(value, attr), key) => HavingRow(key, value, attr)}
230+
231+
TestHive.sparkContext.parallelize(fixture).registerAsTable("having_test")
232+
233+
val results = hql("SELECT value, max(attr) AS attr FROM having_test GROUP BY value HAVING attr > 3")
234+
.collect()
235+
.map(x => Pair(x.getString(0), x.getInt(1)))
236+
237+
assert(results === Array(Pair("foo", 4)))
238+
239+
TestHive.reset()
240+
}
241+
227242
test("Query Hive native command execution result") {
228243
val tableName = "test_native_commands"
229244

@@ -441,3 +456,6 @@ class HiveQuerySuite extends HiveComparisonTest {
441456
// since they modify /clear stuff.
442457

443458
}
459+
460+
// for SPARK-2180 test
461+
case class HavingRow(key: Int, value: String, attr: Int)

0 commit comments

Comments
 (0)