-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
[SPARK-14410] [SQL] : SessionCatalog needs to check database/table/function existence #12183
Changes from all commits
e3677c9
106fd8e
0be142d
6c6ee12
b123c60
c73c32a
7dbf732
59c60a6
e040216
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 |
---|---|---|
|
@@ -84,15 +84,21 @@ class SessionCatalog( | |
// ---------------------------------------------------------------------------- | ||
|
||
def createDatabase(dbDefinition: CatalogDatabase, ignoreIfExists: Boolean): Unit = { | ||
externalCatalog.createDatabase(dbDefinition, ignoreIfExists) | ||
if (!databaseExists(dbDefinition.name)) { | ||
externalCatalog.createDatabase(dbDefinition, ignoreIfExists) | ||
} | ||
} | ||
|
||
def dropDatabase(db: String, ignoreIfNotExists: Boolean, cascade: Boolean): Unit = { | ||
externalCatalog.dropDatabase(db, ignoreIfNotExists, cascade) | ||
if (databaseExists(db)) { | ||
externalCatalog.dropDatabase(db, ignoreIfNotExists, cascade) | ||
} | ||
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. This is now wrong. We used to pass the flag |
||
} | ||
|
||
def alterDatabase(dbDefinition: CatalogDatabase): Unit = { | ||
externalCatalog.alterDatabase(dbDefinition) | ||
if (databaseExists(dbDefinition.name)) { | ||
externalCatalog.alterDatabase(dbDefinition) | ||
} | ||
} | ||
|
||
def getDatabase(db: String): CatalogDatabase = { | ||
|
@@ -460,8 +466,7 @@ class SessionCatalog( | |
* If a database is specified in `name`, this will return the function in that database. | ||
* If no database is specified, this will return the function in the current database. | ||
*/ | ||
// TODO: have a better name. This method is actually for fetching the metadata of a function. | ||
def getFunction(name: FunctionIdentifier): CatalogFunction = { | ||
def getMetadataOfFunction(name: FunctionIdentifier): CatalogFunction = { | ||
val db = name.database.getOrElse(currentDb) | ||
externalCatalog.getFunction(db, name.funcName) | ||
} | ||
|
@@ -474,15 +479,8 @@ class SessionCatalog( | |
// This function exists in the FunctionRegistry. | ||
true | ||
} else { | ||
// Need to check if this function exists in the metastore. | ||
try { | ||
// TODO: It's better to ask external catalog if this function exists. | ||
// So, we can avoid of having this hacky try/catch block. | ||
getFunction(name) != null | ||
} catch { | ||
case _: NoSuchFunctionException => false | ||
case _: AnalysisException => false // HiveExternalCatalog wraps all exceptions with it. | ||
} | ||
val db = name.database.getOrElse(currentDb) | ||
externalCatalog.listFunctions(db,name.unquotedString).size > 0 | ||
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. No, the right thing to do here is to implement |
||
} | ||
} | ||
|
||
|
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.
For createDatabase, we should throw an exception if db already exists and ignoreIfExists is false, right?