@@ -25,22 +25,31 @@ import scala.concurrent.{Await, Promise}
2525import scala .sys .process .{Process , ProcessLogger }
2626
2727import org .apache .hadoop .hive .conf .HiveConf .ConfVars
28- import org .scalatest .{BeforeAndAfterAll , FunSuite }
28+ import org .scalatest .{BeforeAndAfter , BeforeAndAfterAll , FunSuite }
2929
3030import org .apache .spark .Logging
3131import org .apache .spark .util .Utils
3232
33- class CliSuite extends FunSuite with BeforeAndAfterAll with Logging {
33+ class CliSuite extends FunSuite with BeforeAndAfter with Logging {
34+ val warehousePath = Utils .createTempDir()
35+ val metastorePath = Utils .createTempDir()
36+
37+ before {
38+ warehousePath.delete()
39+ metastorePath.delete()
40+ }
41+
42+ after {
43+ warehousePath.delete()
44+ metastorePath.delete()
45+ }
46+
3447 def runCliWithin (
3548 timeout : FiniteDuration ,
3649 extraArgs : Seq [String ] = Seq .empty)(
37- queriesAndExpectedAnswers : (String , String )* ) {
50+ queriesAndExpectedAnswers : (String , String )* ): Unit = {
3851
3952 val (queries, expectedAnswers) = queriesAndExpectedAnswers.unzip
40- val warehousePath = Utils .createTempDir()
41- warehousePath.delete()
42- val metastorePath = Utils .createTempDir()
43- metastorePath.delete()
4453 val cliScript = " ../../bin/spark-sql" .split(" /" ).mkString(File .separator)
4554
4655 val command = {
@@ -95,8 +104,6 @@ class CliSuite extends FunSuite with BeforeAndAfterAll with Logging {
95104 """ .stripMargin, cause)
96105 throw cause
97106 } finally {
98- warehousePath.delete()
99- metastorePath.delete()
100107 process.destroy()
101108 }
102109 }
@@ -124,4 +131,24 @@ class CliSuite extends FunSuite with BeforeAndAfterAll with Logging {
124131 test(" Single command with -e" ) {
125132 runCliWithin(1 .minute, Seq (" -e" , " SHOW DATABASES;" ))(" " -> " OK" )
126133 }
134+
135+ test(" Single command with --database" ) {
136+ runCliWithin(1 .minute)(
137+ " CREATE DATABASE hive_test_db;"
138+ -> " OK" ,
139+ " USE hive_test_db;"
140+ -> " OK" ,
141+ " CREATE TABLE hive_test(key INT, val STRING);"
142+ -> " OK" ,
143+ " SHOW TABLES;"
144+ -> " Time taken: "
145+ )
146+
147+ runCliWithin(1 .minute, Seq (" --database" , " hive_test_db" , " -e" , " SHOW TABLES;" ))(
148+ " "
149+ -> " OK" ,
150+ " "
151+ -> " hive_test"
152+ )
153+ }
127154}
0 commit comments