Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/12081#discussion_r62105072
--- Diff:
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
---
@@ -365,4 +381,113 @@ class HiveDDLSuite extends QueryTest with
SQLTestUtils with TestHiveSingleton {
.exists(_.getString(0) == "# Detailed Table Information"))
}
}
+
+ private def createDatabaseWithLocation(tmpDir: File, dirExists:
Boolean): Unit = {
+ val catalog = sqlContext.sessionState.catalog
+ val dbName = "db1"
+ val tabName = "tab1"
+ val path = "file:" + catalog.createDatabasePath(dbName,
Option(tmpDir.toString))
+ val fs = new
Path(path).getFileSystem(hiveContext.sessionState.newHadoopConf())
+ withTable(tabName) {
+ if (dirExists) {
+ assert(tmpDir.listFiles.isEmpty)
+ } else {
+ assert(!fs.exists(new Path(tmpDir.toString)))
+ }
+ sql(s"CREATE DATABASE $dbName Location '$tmpDir'")
+ val db1 = catalog.getDatabaseMetadata(dbName)
+ assert(db1 == CatalogDatabase(
+ dbName,
+ "",
+ path,
+ Map.empty))
+ sql("USE db1")
+
+ sql(s"CREATE TABLE $tabName as SELECT 1")
+ assert(tableDirectoryExists(TableIdentifier(tabName),
Option(tmpDir.toString)))
+
+ assert(tmpDir.listFiles.nonEmpty)
+ sql(s"DROP TABLE $tabName")
+
+ assert(tmpDir.listFiles.isEmpty)
+ sql(s"DROP DATABASE $dbName")
+ assert(!fs.exists(new Path(tmpDir.toString)))
+ }
+ }
+
+ test("create/drop database - location without pre-created directory") {
+ withTempPath { tmpDir =>
+ createDatabaseWithLocation(tmpDir, dirExists = false)
+ }
+ }
+
+ test("create/drop database - location with pre-created directory") {
+ withTempDir { tmpDir =>
+ createDatabaseWithLocation(tmpDir, dirExists = true)
+ }
+ }
+
+ test("create/drop database - RESTRICT") {
+ val catalog = sqlContext.sessionState.catalog
+ val dbName = "db1"
+ val path = "file:" + catalog.createDatabasePath(dbName, None)
+ val dbPath = new Path(path)
+ val fs = dbPath.getFileSystem(hiveContext.sessionState.newHadoopConf())
+ // the database directory does not exist
+ assert(!fs.exists(dbPath))
+
+ sql(s"CREATE DATABASE $dbName")
+ val db1 = catalog.getDatabaseMetadata(dbName)
+ assert(db1 == CatalogDatabase(
+ dbName,
+ "",
+ path,
+ Map.empty))
+ // the database directory was created
+ assert(fs.exists(dbPath) && fs.isDirectory(dbPath))
+ sql("USE db1")
+
+ val tabName = "tab1"
+ assert(!tableDirectoryExists(TableIdentifier(tabName), Option(path)))
+ sql(s"CREATE TABLE $tabName as SELECT 1")
+ assert(tableDirectoryExists(TableIdentifier(tabName), Option(path)))
+ sql(s"DROP TABLE $tabName")
+ assert(!tableDirectoryExists(TableIdentifier(tabName), Option(path)))
+
+ sql(s"DROP DATABASE $dbName")
+ // the database directory was removed
+ assert(!fs.exists(dbPath))
+ }
--- End diff --
Sure, will do it.
---
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]