Skip to content
Closed
Show file tree
Hide file tree
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 @@ -145,6 +145,9 @@ private[hive] object SparkSQLCLIDriver {
case e: UnsupportedEncodingException => System.exit(3)
}

// use the specified database if specified
cli.processSelectDatabase(sessionState);

// Execute -i init files (always in silent mode)
cli.processInitFiles(sessionState)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,31 @@ import scala.concurrent.{Await, Promise}
import scala.sys.process.{Process, ProcessLogger}

import org.apache.hadoop.hive.conf.HiveConf.ConfVars
import org.scalatest.{BeforeAndAfterAll, FunSuite}
import org.scalatest.{BeforeAndAfter, BeforeAndAfterAll, FunSuite}

import org.apache.spark.Logging
import org.apache.spark.util.Utils

class CliSuite extends FunSuite with BeforeAndAfterAll with Logging {
class CliSuite extends FunSuite with BeforeAndAfter with Logging {
val warehousePath = Utils.createTempDir()
val metastorePath = Utils.createTempDir()

before {
warehousePath.delete()
metastorePath.delete()
}

after {
warehousePath.delete()
metastorePath.delete()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this need to be moved out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need this test transactional.

  1. create database for test db by SparkSQL CLI.
  2. test --database option by SparkSQL command line.
    But the runCliWithin method will delete schema information.
    I modified to delete schema information in before/after of the test method.


def runCliWithin(
timeout: FiniteDuration,
extraArgs: Seq[String] = Seq.empty)(
queriesAndExpectedAnswers: (String, String)*) {
queriesAndExpectedAnswers: (String, String)*): Unit = {

val (queries, expectedAnswers) = queriesAndExpectedAnswers.unzip
val warehousePath = Utils.createTempDir()
warehousePath.delete()
val metastorePath = Utils.createTempDir()
metastorePath.delete()
val cliScript = "../../bin/spark-sql".split("/").mkString(File.separator)

val command = {
Expand Down Expand Up @@ -95,8 +104,6 @@ class CliSuite extends FunSuite with BeforeAndAfterAll with Logging {
""".stripMargin, cause)
throw cause
} finally {
warehousePath.delete()
metastorePath.delete()
process.destroy()
}
}
Expand Down Expand Up @@ -124,4 +131,24 @@ class CliSuite extends FunSuite with BeforeAndAfterAll with Logging {
test("Single command with -e") {
runCliWithin(1.minute, Seq("-e", "SHOW DATABASES;"))("" -> "OK")
}

test("Single command with --database") {
runCliWithin(1.minute)(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use { ... } rather than ( ... ) for the queriesAndExpectedAnswers argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liancheng I have to pass multiple tuples like (a, b), (c, d),... for the queriesAndExpectedAnswers argument.
Thus, it should be used ( ... ), not { ... }.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, sorry, you're right.

"CREATE DATABASE hive_test_db;"
-> "OK",
"USE hive_test_db;"
-> "OK",
"CREATE TABLE hive_test(key INT, val STRING);"
-> "OK",
"SHOW TABLES;"
-> "Time taken: "
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new line here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liancheng I fixed it.


runCliWithin(1.minute, Seq("--database", "hive_test_db", "-e", "SHOW TABLES;"))(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same, use braces rather than parenthesis for queriesAndExpectedAnswers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@liancheng It is same with the queriesAndExpectedAnswers argument.

""
-> "OK",
""
-> "hive_test"
)
}
}