-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-16459][SQL] Prevent dropping current database #14115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
48c19c8
ac5f3ea
8aa1c2d
805b2f7
1702c7e
19a3160
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,8 @@ class SessionCatalog( | |
| hadoopConf: Configuration) extends Logging { | ||
| import CatalogTypes.TablePartitionSpec | ||
|
|
||
| val DEFAULT_DATABASE = "default" | ||
|
|
||
| // For testing only. | ||
| def this( | ||
| externalCatalog: ExternalCatalog, | ||
|
|
@@ -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 | ||
|
|
@@ -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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need to check case sensitivity?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add two testcases for both and fix this.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| throw new AnalysisException(s"Can not drop current database `${dbName}`") | ||
| } | ||
| externalCatalog.dropDatabase(dbName, ignoreIfNotExists, cascade) | ||
| } | ||
|
|
@@ -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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: Shouldn't we just replace the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| } | ||
|
|
@@ -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) | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you're right.
objectis the best to keep this one. Thank you for review, @srowen .Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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 SessionCatalogfor the future