Skip to content

[SPARK-3792][SQL]enable JavaHiveQLSuite #2652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,30 @@ import org.apache.spark.api.java.JavaSparkContext
import org.apache.spark.sql.api.java.JavaSchemaRDD
import org.apache.spark.sql.execution.ExplainCommand
import org.apache.spark.sql.hive.test.TestHive
import org.apache.spark.sql.test.TestSQLContext

// Implicits
import scala.collection.JavaConversions._

class JavaHiveQLSuite extends FunSuite {
lazy val javaCtx = new JavaSparkContext(TestSQLContext.sparkContext)
lazy val javaCtx = new JavaSparkContext(TestHive.sparkContext)

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

ignore("SELECT * FROM src") {
test("SELECT * FROM src") {
assert(
javaHiveCtx.sql("SELECT * FROM src").collect().map(_.getInt(0)) ===
TestHive.sql("SELECT * FROM src").collect().map(_.getInt(0)).toSeq)
}

private val explainCommandClassName =
classOf[ExplainCommand].getSimpleName.stripSuffix("$")

def isExplanation(result: JavaSchemaRDD) = {
val explanation = result.collect().map(_.getString(0))
explanation.size > 1 && explanation.head.startsWith(explainCommandClassName)
explanation.size > 1 && explanation.head.startsWith("== Physical Plan ==")
}

ignore("Query Hive native command execution result") {
test("Query Hive native command execution result") {
val tableName = "test_native_commands"

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

javaHiveCtx.sql("SHOW TABLES").registerTempTable("show_tables")

assert(
javaHiveCtx
.sql("SELECT result FROM show_tables")
.sql("SHOW TABLES")
.collect()
.map(_.getString(0))
.contains(tableName))

assertResult(Array(Array("key", "int", "None"), Array("value", "string", "None"))) {
javaHiveCtx.sql(s"DESCRIBE $tableName").registerTempTable("describe_table")


assertResult(Array(Array("key", "int"), Array("value", "string"))) {
javaHiveCtx
.sql("SELECT result FROM describe_table")
.sql(s"describe $tableName")
.collect()
.map(_.getString(0).split("\t").map(_.trim))
.map(row => Array(row.get(0).asInstanceOf[String], row.get(1).asInstanceOf[String]))
.toArray
}

Expand All @@ -89,7 +80,7 @@ class JavaHiveQLSuite extends FunSuite {
TestHive.reset()
}

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

Expand Down