-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-6694][SQL]SparkSQL CLI must be able to specify an option --database on the command line. #5345
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
[SPARK-6694][SQL]SparkSQL CLI must be able to specify an option --database on the command line. #5345
Changes from all commits
c804c03
ee09fa5
db56122
c581d06
7b58f42
dbe8c63
846f83e
df81086
0301eb9
8659084
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: " | ||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new line here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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;"))( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same, use braces rather than parenthesis for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @liancheng It is same with the queriesAndExpectedAnswers argument. |
||
| "" | ||
| -> "OK", | ||
| "" | ||
| -> "hive_test" | ||
| ) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
But the runCliWithin method will delete schema information.
I modified to delete schema information in before/after of the test method.