You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by sr...@apache.org on 2016/08/10 15:49:16 UTC
spark git commit: Revert "[SPARK-15899][SQL] Fix the construction of
the file path with hadoop Path"
Repository: spark
Updated Branches:
refs/heads/branch-2.0 719ac5f37 -> 15637f735
Revert "[SPARK-15899][SQL] Fix the construction of the file path with hadoop Path"
This reverts commit 719ac5f37ccf32c34c70524b8cf9a2699c71a353.
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/15637f73
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/15637f73
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/15637f73
Branch: refs/heads/branch-2.0
Commit: 15637f735f4b27b291f40bbeadb98c5e0318bf70
Parents: 719ac5f
Author: Sean Owen <so...@cloudera.com>
Authored: Wed Aug 10 16:48:57 2016 +0100
Committer: Sean Owen <so...@cloudera.com>
Committed: Wed Aug 10 16:48:57 2016 +0100
----------------------------------------------------------------------
.../org/apache/spark/sql/internal/SQLConf.scala | 7 ++--
.../spark/sql/execution/command/DDLSuite.scala | 44 ++++++++++----------
.../spark/sql/internal/SQLConfSuite.scala | 4 +-
3 files changed, 26 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/15637f73/sql/core/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala b/sql/core/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala
index 1d30f71..1a9bb6a 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala
@@ -23,7 +23,6 @@ import java.util.concurrent.TimeUnit
import scala.collection.JavaConverters._
import scala.collection.immutable
-import org.apache.hadoop.fs.Path
import org.apache.parquet.hadoop.ParquetOutputCommitter
import org.apache.spark.internal.Logging
@@ -56,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()
@@ -691,7 +690,9 @@ private[sql] class SQLConf extends Serializable with CatalystConf with Logging {
def variableSubstituteDepth: Int = getConf(VARIABLE_SUBSTITUTE_DEPTH)
- def warehousePath: String = new Path(getConf(WAREHOUSE_PATH)).toString
+ def warehousePath: String = {
+ getConf(WAREHOUSE_PATH).replace("${system:user.dir}", System.getProperty("user.dir"))
+ }
override def orderByOrdinal: Boolean = getConf(ORDER_BY_ORDINAL)
http://git-wip-us.apache.org/repos/asf/spark/blob/15637f73/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
index 1652c4d..b276e2d 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala
@@ -111,6 +111,10 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
catalog.createPartitions(tableName, Seq(part), ignoreIfExists = false)
}
+ private def appendTrailingSlash(path: String): String = {
+ if (!path.endsWith(File.separator)) path + File.separator else path
+ }
+
test("the qualified path of a database is stored in the catalog") {
val catalog = spark.sessionState.catalog
@@ -118,19 +122,18 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
val path = tmpDir.toString
// The generated temp path is not qualified.
assert(!path.startsWith("file:/"))
- val uri = tmpDir.toURI
- sql(s"CREATE DATABASE db1 LOCATION '$uri'")
+ sql(s"CREATE DATABASE db1 LOCATION '$path'")
val pathInCatalog = new Path(catalog.getDatabaseMetadata("db1").locationUri).toUri
assert("file" === pathInCatalog.getScheme)
- val expectedPath = new Path(path).toUri
- assert(expectedPath.getPath === pathInCatalog.getPath)
+ val expectedPath = if (path.endsWith(File.separator)) path.dropRight(1) else path
+ assert(expectedPath === pathInCatalog.getPath)
withSQLConf(SQLConf.WAREHOUSE_PATH.key -> path) {
sql(s"CREATE DATABASE db2")
- val pathInCatalog2 = new Path(catalog.getDatabaseMetadata("db2").locationUri).toUri
- assert("file" === pathInCatalog2.getScheme)
- val expectedPath2 = new Path(spark.sessionState.conf.warehousePath + "/" + "db2.db").toUri
- assert(expectedPath2.getPath === pathInCatalog2.getPath)
+ val pathInCatalog = new Path(catalog.getDatabaseMetadata("db2").locationUri).toUri
+ assert("file" === pathInCatalog.getScheme)
+ val expectedPath = appendTrailingSlash(spark.sessionState.conf.warehousePath) + "db2.db"
+ assert(expectedPath === pathInCatalog.getPath)
}
sql("DROP DATABASE db1")
@@ -138,13 +141,6 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
}
}
- private def makeQualifiedPath(path: String): String = {
- // copy-paste from SessionCatalog
- val hadoopPath = new Path(path)
- val fs = hadoopPath.getFileSystem(sparkContext.hadoopConfiguration)
- fs.makeQualified(hadoopPath).toString
- }
-
test("Create/Drop Database") {
withTempDir { tmpDir =>
val path = tmpDir.toString
@@ -158,7 +154,8 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
sql(s"CREATE DATABASE $dbName")
val db1 = catalog.getDatabaseMetadata(dbNameWithoutBackTicks)
- val expectedLocation = makeQualifiedPath(path + "/" + s"$dbNameWithoutBackTicks.db")
+ val expectedLocation =
+ "file:" + appendTrailingSlash(path) + s"$dbNameWithoutBackTicks.db"
assert(db1 == CatalogDatabase(
dbNameWithoutBackTicks,
"",
@@ -184,8 +181,8 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
sql(s"CREATE DATABASE $dbName")
val db1 = catalog.getDatabaseMetadata(dbName)
val expectedLocation =
- makeQualifiedPath(s"${System.getProperty("user.dir")}/spark-warehouse" +
- "/" + s"$dbName.db")
+ "file:" + appendTrailingSlash(System.getProperty("user.dir")) +
+ s"spark-warehouse/$dbName.db"
assert(db1 == CatalogDatabase(
dbName,
"",
@@ -203,17 +200,17 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
val catalog = spark.sessionState.catalog
val databaseNames = Seq("db1", "`database`")
withTempDir { tmpDir =>
- val path = new Path(tmpDir.toString).toUri.toString
+ val path = tmpDir.toString
+ val dbPath = "file:" + path
databaseNames.foreach { dbName =>
try {
val dbNameWithoutBackTicks = cleanIdentifier(dbName)
sql(s"CREATE DATABASE $dbName Location '$path'")
val db1 = catalog.getDatabaseMetadata(dbNameWithoutBackTicks)
- val expPath = makeQualifiedPath(tmpDir.toString)
assert(db1 == CatalogDatabase(
dbNameWithoutBackTicks,
"",
- expPath,
+ if (dbPath.endsWith(File.separator)) dbPath.dropRight(1) else dbPath,
Map.empty))
sql(s"DROP DATABASE $dbName CASCADE")
assert(!catalog.databaseExists(dbNameWithoutBackTicks))
@@ -236,7 +233,8 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
val dbNameWithoutBackTicks = cleanIdentifier(dbName)
sql(s"CREATE DATABASE $dbName")
val db1 = catalog.getDatabaseMetadata(dbNameWithoutBackTicks)
- val expectedLocation = makeQualifiedPath(path + "/" + s"$dbNameWithoutBackTicks.db")
+ val expectedLocation =
+ "file:" + appendTrailingSlash(path) + s"$dbNameWithoutBackTicks.db"
assert(db1 == CatalogDatabase(
dbNameWithoutBackTicks,
"",
@@ -277,7 +275,7 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
databaseNames.foreach { dbName =>
try {
val dbNameWithoutBackTicks = cleanIdentifier(dbName)
- val location = makeQualifiedPath(path + "/" + s"$dbNameWithoutBackTicks.db")
+ val location = "file:" + appendTrailingSlash(path) + s"$dbNameWithoutBackTicks.db"
sql(s"CREATE DATABASE $dbName")
http://git-wip-us.apache.org/repos/asf/spark/blob/15637f73/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfSuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfSuite.scala
index 761bbe3..5d34804 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/internal/SQLConfSuite.scala
@@ -17,8 +17,6 @@
package org.apache.spark.sql.internal
-import org.apache.hadoop.fs.Path
-
import org.apache.spark.sql.{QueryTest, Row, SparkSession, SQLContext}
import org.apache.spark.sql.execution.WholeStageCodegenExec
import org.apache.spark.sql.test.{SharedSQLContext, TestSQLContext}
@@ -216,7 +214,7 @@ class SQLConfSuite extends QueryTest with SharedSQLContext {
// to get the default value, always unset it
spark.conf.unset(SQLConf.WAREHOUSE_PATH.key)
assert(spark.sessionState.conf.warehousePath
- === new Path(s"${System.getProperty("user.dir")}/spark-warehouse").toString)
+ === s"file:${System.getProperty("user.dir")}/spark-warehouse")
} finally {
sql(s"set ${SQLConf.WAREHOUSE_PATH}=$original")
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org