Skip to content

Commit 964e3aa

Browse files
scwfmarmbrus
authored andcommitted
[SPARK-3792][SQL] Enable JavaHiveQLSuite
Do not use TestSQLContext in JavaHiveQLSuite, that may lead to two SparkContexts in one jvm and enable JavaHiveQLSuite Author: scwf <wangfei1@huawei.com> Closes #2652 from scwf/fix-JavaHiveQLSuite and squashes the following commits: be35c91 [scwf] enable JavaHiveQLSuite (cherry picked from commit 58f5361) Signed-off-by: Michael Armbrust <michael@databricks.com>
1 parent c068d90 commit 964e3aa

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

sql/hive/src/test/scala/org/apache/spark/sql/hive/api/java/JavaHiveQLSuite.scala

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,30 @@ import org.apache.spark.api.java.JavaSparkContext
2525
import org.apache.spark.sql.api.java.JavaSchemaRDD
2626
import org.apache.spark.sql.execution.ExplainCommand
2727
import org.apache.spark.sql.hive.test.TestHive
28-
import org.apache.spark.sql.test.TestSQLContext
2928

3029
// Implicits
3130
import scala.collection.JavaConversions._
3231

3332
class JavaHiveQLSuite extends FunSuite {
34-
lazy val javaCtx = new JavaSparkContext(TestSQLContext.sparkContext)
33+
lazy val javaCtx = new JavaSparkContext(TestHive.sparkContext)
3534

3635
// There is a little trickery here to avoid instantiating two HiveContexts in the same JVM
3736
lazy val javaHiveCtx = new JavaHiveContext(javaCtx) {
3837
override val sqlContext = TestHive
3938
}
4039

41-
ignore("SELECT * FROM src") {
40+
test("SELECT * FROM src") {
4241
assert(
4342
javaHiveCtx.sql("SELECT * FROM src").collect().map(_.getInt(0)) ===
4443
TestHive.sql("SELECT * FROM src").collect().map(_.getInt(0)).toSeq)
4544
}
4645

47-
private val explainCommandClassName =
48-
classOf[ExplainCommand].getSimpleName.stripSuffix("$")
49-
5046
def isExplanation(result: JavaSchemaRDD) = {
5147
val explanation = result.collect().map(_.getString(0))
52-
explanation.size > 1 && explanation.head.startsWith(explainCommandClassName)
48+
explanation.size > 1 && explanation.head.startsWith("== Physical Plan ==")
5349
}
5450

55-
ignore("Query Hive native command execution result") {
51+
test("Query Hive native command execution result") {
5652
val tableName = "test_native_commands"
5753

5854
assertResult(0) {
@@ -63,23 +59,18 @@ class JavaHiveQLSuite extends FunSuite {
6359
javaHiveCtx.sql(s"CREATE TABLE $tableName(key INT, value STRING)").count()
6460
}
6561

66-
javaHiveCtx.sql("SHOW TABLES").registerTempTable("show_tables")
67-
6862
assert(
6963
javaHiveCtx
70-
.sql("SELECT result FROM show_tables")
64+
.sql("SHOW TABLES")
7165
.collect()
7266
.map(_.getString(0))
7367
.contains(tableName))
7468

75-
assertResult(Array(Array("key", "int", "None"), Array("value", "string", "None"))) {
76-
javaHiveCtx.sql(s"DESCRIBE $tableName").registerTempTable("describe_table")
77-
78-
69+
assertResult(Array(Array("key", "int"), Array("value", "string"))) {
7970
javaHiveCtx
80-
.sql("SELECT result FROM describe_table")
71+
.sql(s"describe $tableName")
8172
.collect()
82-
.map(_.getString(0).split("\t").map(_.trim))
73+
.map(row => Array(row.get(0).asInstanceOf[String], row.get(1).asInstanceOf[String]))
8374
.toArray
8475
}
8576

@@ -89,7 +80,7 @@ class JavaHiveQLSuite extends FunSuite {
8980
TestHive.reset()
9081
}
9182

92-
ignore("Exactly once semantics for DDL and command statements") {
83+
test("Exactly once semantics for DDL and command statements") {
9384
val tableName = "test_exactly_once"
9485
val q0 = javaHiveCtx.sql(s"CREATE TABLE $tableName(key INT, value STRING)")
9586

0 commit comments

Comments
 (0)