Skip to content

Commit cf11b0e

Browse files
aarondavwillb
authored andcommitted
Fix flakey HiveQuerySuite test
Result may not be returned in the expected order, so relax that constraint. Author: Aaron Davidson <[email protected]> Closes #1514 from aarondav/flakey and squashes the following commits: e5af823 [Aaron Davidson] Fix flakey HiveQuerySuite test Conflicts: sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveQuerySuite.scala
1 parent c567a68 commit cf11b0e

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -520,62 +520,64 @@ class HiveQuerySuite extends HiveComparisonTest {
520520
val testKey = "spark.sql.key.usedfortestonly"
521521
val testVal = "test.val.0"
522522
val nonexistentKey = "nonexistent"
523+
def collectResults(rdd: SchemaRDD): Set[(String, String)] =
524+
rdd.collect().map { case Row(key: String, value: String) => key -> value }.toSet
523525

524526
clear()
525527

526528
// "set" itself returns all config variables currently specified in SQLConf.
527529
// TODO: Should we be listing the default here always? probably...
528530
assert(sql("SET").collect().size == 0)
529531

530-
assertResult(Array(s"$testKey=$testVal")) {
531-
sql(s"SET $testKey=$testVal").collect().map(_.getString(0))
532+
assertResult(Set(testKey -> testVal)) {
533+
collectResults(hql(s"SET $testKey=$testVal"))
532534
}
533535

534536
assert(hiveconf.get(testKey, "") == testVal)
535-
assertResult(Array(s"$testKey=$testVal")) {
536-
sql(s"SET $testKey=$testVal").collect().map(_.getString(0))
537+
assertResult(Set(testKey -> testVal)) {
538+
collectResults(hql("SET"))
537539
}
538540

539541
sql(s"SET ${testKey + testKey}=${testVal + testVal}")
540542
assert(hiveconf.get(testKey + testKey, "") == testVal + testVal)
541-
assertResult(Array(s"$testKey=$testVal", s"${testKey + testKey}=${testVal + testVal}")) {
542-
sql(s"SET").collect().map(_.getString(0))
543+
assertResult(Set(testKey -> testVal, (testKey + testKey) -> (testVal + testVal))) {
544+
collectResults(hql("SET"))
543545
}
544546

545547
// "set key"
546-
assertResult(Array(s"$testKey=$testVal")) {
547-
sql(s"SET $testKey").collect().map(_.getString(0))
548+
assertResult(Set(testKey -> testVal)) {
549+
collectResults(hql(s"SET $testKey"))
548550
}
549551

550-
assertResult(Array(s"$nonexistentKey=<undefined>")) {
551-
sql(s"SET $nonexistentKey").collect().map(_.getString(0))
552+
assertResult(Set(nonexistentKey -> "<undefined>")) {
553+
collectResults(hql(s"SET $nonexistentKey"))
552554
}
553555

554556
// Assert that sql() should have the same effects as sql() by repeating the above using sql().
555557
clear()
556558
assert(sql("SET").collect().size == 0)
557559

558-
assertResult(Array(s"$testKey=$testVal")) {
559-
sql(s"SET $testKey=$testVal").collect().map(_.getString(0))
560+
assertResult(Set(testKey -> testVal)) {
561+
collectResults(sql(s"SET $testKey=$testVal"))
560562
}
561563

562564
assert(hiveconf.get(testKey, "") == testVal)
563-
assertResult(Array(s"$testKey=$testVal")) {
564-
sql("SET").collect().map(_.getString(0))
565+
assertResult(Set(testKey -> testVal)) {
566+
collectResults(sql("SET"))
565567
}
566568

567569
sql(s"SET ${testKey + testKey}=${testVal + testVal}")
568570
assert(hiveconf.get(testKey + testKey, "") == testVal + testVal)
569-
assertResult(Array(s"$testKey=$testVal", s"${testKey + testKey}=${testVal + testVal}")) {
570-
sql("SET").collect().map(_.getString(0))
571+
assertResult(Set(testKey -> testVal, (testKey + testKey) -> (testVal + testVal))) {
572+
collectResults(sql("SET"))
571573
}
572574

573-
assertResult(Array(s"$testKey=$testVal")) {
574-
sql(s"SET $testKey").collect().map(_.getString(0))
575+
assertResult(Set(testKey -> testVal)) {
576+
collectResults(sql(s"SET $testKey"))
575577
}
576578

577-
assertResult(Array(s"$nonexistentKey=<undefined>")) {
578-
sql(s"SET $nonexistentKey").collect().map(_.getString(0))
579+
assertResult(Set(nonexistentKey -> "<undefined>")) {
580+
collectResults(sql(s"SET $nonexistentKey"))
579581
}
580582

581583
clear()

0 commit comments

Comments
 (0)