Skip to content
Snippets Groups Projects
Commit 3ae37b93 authored by Jin Adachi's avatar Jin Adachi Committed by Cheng Lian
Browse files

[SPARK-6694][SQL]SparkSQL CLI must be able to specify an option --database on the command line.

SparkSQL CLI has an option --database as follows.
But, the option --database is ignored.

```
$ spark-sql --help
:
CLI options:
    :
    --database <databasename>     Specify the database to use
```

Author: Jin Adachi <adachij2002@yahoo.co.jp>
Author: adachij <adachij@nttdata.co.jp>

Closes #5345 from adachij2002/SPARK-6694 and squashes the following commits:

8659084 [Jin Adachi] Merge branch 'master' of https://github.com/apache/spark into SPARK-6694
0301eb9 [Jin Adachi] Merge branch 'master' of https://github.com/apache/spark into SPARK-6694
df81086 [Jin Adachi] Modify code style.
846f83e [Jin Adachi] Merge branch 'master' of https://github.com/apache/spark into SPARK-6694
dbe8c63 [Jin Adachi] Change file permission to 644.
7b58f42 [Jin Adachi] Merge branch 'master' of https://github.com/apache/spark into SPARK-6694
c581d06 [Jin Adachi] Add an option --database test
db56122 [Jin Adachi] Merge branch 'SPARK-6694' of https://github.com/adachij2002/spark into SPARK-6694
ee09fa5 [adachij] Merge branch 'master' into SPARK-6694
c804c03 [adachij] SparkSQL CLI must be able to specify an option --database on the command line.
parent de4fa6b6
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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()
}
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 = {
......@@ -95,8 +104,6 @@ class CliSuite extends FunSuite with BeforeAndAfterAll with Logging {
""".stripMargin, cause)
throw cause
} finally {
warehousePath.delete()
metastorePath.delete()
process.destroy()
}
}
......@@ -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)(
"CREATE DATABASE hive_test_db;"
-> "OK",
"USE hive_test_db;"
-> "OK",
"CREATE TABLE hive_test(key INT, val STRING);"
-> "OK",
"SHOW TABLES;"
-> "Time taken: "
)
runCliWithin(1.minute, Seq("--database", "hive_test_db", "-e", "SHOW TABLES;"))(
""
-> "OK",
""
-> "hive_test"
)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment