@@ -21,6 +21,7 @@ import org.apache.spark.sql.Row
2121import org .apache .spark .sql .catalyst .plans .logical .ExplainCommand
2222import org .apache .spark .sql .hive .test .TestHive
2323import org .apache .spark .sql .hive .test .TestHive ._
24+ import org .apache .spark .sql .execution .ExplainCommandPhysical
2425
2526/**
2627 * A set of test cases expressed in Hive QL that are not covered by the tests included in the hive distribution.
@@ -165,11 +166,16 @@ class HiveQuerySuite extends HiveComparisonTest {
165166
166167 test(" SPARK-1704: Explain commands as a SchemaRDD" ) {
167168 hql(" CREATE TABLE IF NOT EXISTS src (key INT, value STRING)" )
169+
168170 val rdd = hql(" explain select key, count(value) from src group by key" )
169- assert(rdd.collect().size == 1 )
170- assert(rdd.toString.contains(ExplainCommand .getClass.getSimpleName))
171- assert(rdd.filter(row => row.toString.contains(" ExplainCommand" )).collect().size == 0 ,
172- " actual contents of the result should be the plans of the query to be explained" )
171+ val explanation = rdd.select(' plan ).collect().map {
172+ case Row (plan : String ) => plan
173+ }
174+ assert(explanation.size == 1 )
175+
176+ val explainCommandClassName = classOf [ExplainCommandPhysical ].getSimpleName.stripSuffix(" $" )
177+ assert(explanation.head.contains(explainCommandClassName))
178+
173179 TestHive .reset()
174180 }
175181
@@ -225,13 +231,13 @@ class HiveQuerySuite extends HiveComparisonTest {
225231 rowsToPairs(hql(s " SET $testKey" ).collect())
226232 }
227233
228- assertResult(Array (testKey -> " <undefined>" )) {
234+ assertResult(Array (nonexistentKey -> " <undefined>" )) {
229235 rowsToPairs(hql(s " SET $nonexistentKey" ).collect())
230236 }
231237
232238 // Assert that sql() should have the same effects as hql() by repeating the above using sql().
233239 clear()
234- assert(sql(" set " ).collect().size == 0 )
240+ assert(sql(" SET " ).collect().size == 0 )
235241
236242 sql(s " SET $testKey= $testVal" )
237243 assert(hiveconf.get(testKey, " " ) == testVal)
@@ -249,7 +255,7 @@ class HiveQuerySuite extends HiveComparisonTest {
249255 rowsToPairs(sql(s " SET $testKey" ).collect())
250256 }
251257
252- assertResult(Array (testKey -> " <undefined>" )) {
258+ assertResult(Array (nonexistentKey -> " <undefined>" )) {
253259 rowsToPairs(sql(s " SET $nonexistentKey" ).collect())
254260 }
255261
0 commit comments