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 @@ -201,21 +201,20 @@ private[hive] object SparkSQLCLIDriver extends Logging {
case e: UnsupportedEncodingException => exit(ERROR_PATH_NOT_FOUND)
}

if (sessionState.database != null) {
SparkSQLEnv.sqlContext.sessionState.catalog.setCurrentDatabase(
s"${sessionState.database}")
}

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

// We don't propagate hive.metastore.warehouse.dir, because it might has been adjusted in
// [[SharedState.loadHiveConfFile]] based on the user specified or default values of
// spark.sql.warehouse.dir and hive.metastore.warehouse.dir.
for ((k, v) <- newHiveConf if k != "hive.metastore.warehouse.dir") {
SparkSQLEnv.sqlContext.setConf(k, v)
}

if (sessionState.database != null) {
SparkSQLEnv.sqlContext.sql(s"USE ${sessionState.database}")
}

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

cli.printMasterAndAppId

if (sessionState.execString != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.apache.hadoop.hive.ql.session.SessionState
import org.apache.spark.{ErrorMessageFormat, SparkConf, SparkContext, SparkFunSuite}
import org.apache.spark.ProcessTestUtils.ProcessOutputCapturer
import org.apache.spark.deploy.SparkHadoopUtil
import org.apache.spark.sql.execution.datasources.v2.jdbc.JDBCTableCatalog
import org.apache.spark.sql.hive.HiveUtils
import org.apache.spark.sql.hive.HiveUtils._
import org.apache.spark.sql.hive.client.HiveClientImpl
Expand Down Expand Up @@ -806,4 +807,29 @@ class CliSuite extends SparkFunSuite {
prompt = "spark-sql (spark_42448)>")(
"select current_database();" -> "spark_42448")
}

test("SPARK-42823: multipart identifier support for specify database by --database option") {
val catalogName = "testcat"
val catalogImpl = s"spark.sql.catalog.$catalogName=${classOf[JDBCTableCatalog].getName}"
val catalogUrl =
s"spark.sql.catalog.$catalogName.url=jdbc:derby:memory:$catalogName;create=true"
val catalogDriver =
s"spark.sql.catalog.$catalogName.driver=org.apache.derby.jdbc.AutoloadedDriver"
val database = s"-database $catalogName.SYS"
val catalogConfigs =
Seq(catalogImpl, catalogDriver, catalogUrl, "spark.sql.catalogImplementation=in-memory")
.flatMap(Seq("--conf", _))
runCliWithin(
2.minute,
catalogConfigs ++ Seq("--database", s"$catalogName.SYS"))(
"SELECT CURRENT_CATALOG();" -> catalogName,
"SELECT CURRENT_SCHEMA();" -> "SYS")

runCliWithin(
2.minute,
catalogConfigs ++
Seq("--conf", s"spark.sql.defaultCatalog=$catalogName", "--database", "SYS"))(
"SELECT CURRENT_CATALOG();" -> catalogName,
"SELECT CURRENT_SCHEMA();" -> "SYS")
}
}