Skip to content
Snippets Groups Projects
Commit c1727290 authored by gatorsmile's avatar gatorsmile Committed by Yin Huai
Browse files

[SPARK-15565][SQL] Add the File Scheme to the Default Value of WAREHOUSE_PATH

#### What changes were proposed in this pull request?
The default value of `spark.sql.warehouse.dir` is `System.getProperty("user.dir")/spark-warehouse`. Since `System.getProperty("user.dir")` is a local dir, we should explicitly set the scheme to local filesystem.

cc yhuai

#### How was this patch tested?
Added two test cases

Author: gatorsmile <gatorsmile@gmail.com>

Closes #13348 from gatorsmile/addSchemeToDefaultWarehousePath.
parent 6f95c6c0
No related branches found
No related tags found
No related merge requests found
......@@ -55,7 +55,7 @@ object SQLConf {
val WAREHOUSE_PATH = SQLConfigBuilder("spark.sql.warehouse.dir")
.doc("The default location for managed databases and tables.")
.stringConf
.createWithDefault("${system:user.dir}/spark-warehouse")
.createWithDefault("file:${system:user.dir}/spark-warehouse")
val OPTIMIZER_MAX_ITERATIONS = SQLConfigBuilder("spark.sql.optimizer.maxIterations")
.internal()
......
......@@ -171,6 +171,31 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
}
}
test("Create Database using Default Warehouse Path") {
withSQLConf(SQLConf.WAREHOUSE_PATH.key -> "") {
// Will use the default location if and only if we unset the conf
spark.conf.unset(SQLConf.WAREHOUSE_PATH.key)
val catalog = spark.sessionState.catalog
val dbName = "db1"
try {
sql(s"CREATE DATABASE $dbName")
val db1 = catalog.getDatabaseMetadata(dbName)
val expectedLocation =
"file:" + appendTrailingSlash(System.getProperty("user.dir")) +
s"spark-warehouse/$dbName.db"
assert(db1 == CatalogDatabase(
dbName,
"",
expectedLocation,
Map.empty))
sql(s"DROP DATABASE $dbName CASCADE")
assert(!catalog.databaseExists(dbName))
} finally {
catalog.reset()
}
}
}
test("Create/Drop Database - location") {
val catalog = spark.sessionState.catalog
val databaseNames = Seq("db1", "`database`")
......
......@@ -207,4 +207,16 @@ class SQLConfSuite extends QueryTest with SharedSQLContext {
}
}
test("default value of WAREHOUSE_PATH") {
val original = spark.conf.get(SQLConf.WAREHOUSE_PATH)
try {
// to get the default value, always unset it
spark.conf.unset(SQLConf.WAREHOUSE_PATH.key)
assert(spark.sessionState.conf.warehousePath
=== s"file:${System.getProperty("user.dir")}/spark-warehouse")
} finally {
sql(s"set ${SQLConf.WAREHOUSE_PATH}=$original")
}
}
}
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