Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/17001#discussion_r105565256
--- Diff:
sql/hive/src/test/scala/org/apache/spark/sql/hive/HiveSparkSubmitSuite.scala ---
@@ -907,3 +936,97 @@ object SPARK_18989_DESC_TABLE {
}
}
}
+
+object SPARK_19667_CREATE_TABLE {
+ def main(args: Array[String]): Unit = {
+ val spark = SparkSession.builder().enableHiveSupport().getOrCreate()
+ try {
+ val warehousePath = new Path(spark.sharedState.warehousePath)
+ val fs =
warehousePath.getFileSystem(spark.sessionState.newHadoopConf())
+ val defaultDB =
spark.sessionState.catalog.getDatabaseMetadata("default")
+ // default database use warehouse path as its location
+ assert(new Path(defaultDB.locationUri) ==
fs.makeQualified(warehousePath))
+ spark.sql("CREATE TABLE t(a string)")
+
+ val table =
spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
+ // table in default database use the location of default database
which is also warehouse path
+ assert(new Path(table.location) == fs.makeQualified(new
Path(warehousePath, "t")))
+ spark.sql("INSERT INTO TABLE t SELECT 1")
+ assert(spark.sql("SELECT * FROM t").count == 1)
+
+ spark.sql("CREATE DATABASE not_default")
+ spark.sql("USE not_default")
+ spark.sql("CREATE TABLE t1(b string)")
+ val table1 =
spark.sessionState.catalog.getTableMetadata(TableIdentifier("t1"))
+ // table in not default database use the location of its own database
+ assert(new Path(table1.location) == fs.makeQualified(
+ new Path(warehousePath, "not_default.db/t1")))
+ } finally {
+ spark.sql("USE default")
+ }
+ }
+}
+
+object SPARK_19667_VERIFY_TABLE_PATH {
+ def main(args: Array[String]): Unit = {
+ val spark = SparkSession.builder().enableHiveSupport().getOrCreate()
+ try {
+ val warehousePath = new Path(spark.sharedState.warehousePath)
+ val fs =
warehousePath.getFileSystem(spark.sessionState.newHadoopConf())
+ val defaultDB =
spark.sessionState.catalog.getDatabaseMetadata("default")
+ // default database use warehouse path as its location
+ assert(new Path(defaultDB.locationUri) ==
fs.makeQualified(warehousePath))
+
+ val table =
spark.sessionState.catalog.getTableMetadata(TableIdentifier("t"))
+ // the table in default database created in
job(SPARK_19667_CREATE_TABLE) above,
+ // which has different warehouse path from this job, its location
still equals to
+ // the location when it's created.
+ assert(new Path(table.location) != fs.makeQualified(new
Path(warehousePath, "t")))
+ assert(spark.sql("SELECT * FROM t").count == 1)
+
+ spark.sql("CREATE TABLE t3(d string)")
+ val table3 =
spark.sessionState.catalog.getTableMetadata(TableIdentifier("t3"))
+ // the table in default database created here in this job, it will
use the warehouse path
+ // of this job as its location
--- End diff --
->
```
When a job creates a table in the default database, the table location is
under the warehouse path
that is configured for the local job.
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]