Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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 @@ -49,6 +49,8 @@ class SessionCatalog(
hadoopConf: Configuration) extends Logging {
import CatalogTypes.TablePartitionSpec

val DEFAULT_DATABASE = "default"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this should be in an object SessionCatalog?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right. object is the best to keep this one. Thank you for review, @srowen .

@dongjoon-hyun dongjoon-hyun Jul 10, 2016

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I remember why I didn't do that. In fact, we don't have object SessionCatalog, yet.
So, I was not sure I could introduce new object for just one constant variable. Is it enough valuable, @srowen and @rxin ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I'll make that first.
It's easy to revert one commit.
And, if possible, I prefer to have object SessionCatalog for the future


// For testing only.
def this(
externalCatalog: ExternalCatalog,
Expand Down Expand Up @@ -77,7 +79,7 @@ class SessionCatalog(
// the corresponding item in the current database.
@GuardedBy("this")
protected var currentDb = {
val defaultName = "default"
val defaultName = DEFAULT_DATABASE
val defaultDbDefinition =
CatalogDatabase(defaultName, "default database", conf.warehousePath, Map())
// Initialize default database if it doesn't already exist
Expand Down Expand Up @@ -146,8 +148,10 @@ class SessionCatalog(

def dropDatabase(db: String, ignoreIfNotExists: Boolean, cascade: Boolean): Unit = {
val dbName = formatDatabaseName(db)
if (dbName == "default") {
if (dbName == DEFAULT_DATABASE) {
throw new AnalysisException(s"Can not drop default database")
} else if (dbName == getCurrentDatabase) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to check case sensitivity?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. formatDatabaseName returns the raw string for case sensitive case.
Hm. That is the same situation with "default" database, isn't?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add two testcases for both and fix this.

@dongjoon-hyun dongjoon-hyun Jul 9, 2016

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I was confused. For case sensitive case, we don't need to handle that.
Dropping with different names will fails due to lookup failure.

throw new AnalysisException(s"Can not drop current database `${dbName}`")
}
externalCatalog.dropDatabase(dbName, ignoreIfNotExists, cascade)
}
Expand Down Expand Up @@ -878,7 +882,8 @@ class SessionCatalog(
* This is mainly used for tests.
*/
private[sql] def reset(): Unit = synchronized {
val default = "default"
val default = DEFAULT_DATABASE

@hvanhovell hvanhovell Jul 11, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: Shouldn't we just replace the val default by DEFAULT_DATABASE?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sure!

setCurrentDatabase(default)
listDatabases().filter(_ != default).foreach { db =>
dropDatabase(db, ignoreIfNotExists = false, cascade = true)
}
Expand All @@ -902,7 +907,6 @@ class SessionCatalog(
require(functionBuilder.isDefined, s"built-in function '$f' is missing function builder")
functionRegistry.registerFunction(f, expressionInfo.get, functionBuilder.get)
}
setCurrentDatabase(default)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,15 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
"WITH SERDEPROPERTIES ('spark.sql.sources.me'='anything')")
}

test("drop current database") {
sql("CREATE DATABASE temp")
sql("USE temp")
val m = intercept[AnalysisException] {
sql("DROP DATABASE temp")
}.getMessage
assert(m.contains("Can not drop current database `temp`"))
}

test("drop default database") {
Seq("true", "false").foreach { caseSensitive =>
withSQLConf(SQLConf.CASE_SENSITIVE.key -> caseSensitive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ class HiveDDLSuite
sql(s"DROP TABLE $tabName")

assert(tmpDir.listFiles.isEmpty)
sql("USE default")
sql(s"DROP DATABASE $dbName")
assert(!fs.exists(new Path(tmpDir.toString)))
}
Expand Down Expand Up @@ -526,6 +527,7 @@ class HiveDDLSuite
assert(!tableDirectoryExists(TableIdentifier(tabName), Option(expectedDBLocation)))
}

sql(s"USE default")
val sqlDropDatabase = s"DROP DATABASE $dbName ${if (cascade) "CASCADE" else "RESTRICT"}"
if (tableExists && !cascade) {
val message = intercept[AnalysisException] {
Expand Down