cloud-fan commented on code in PR #36641:
URL: https://github.com/apache/spark/pull/36641#discussion_r897682642
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -287,16 +298,37 @@ class CatalogImpl(sparkSession: SparkSession) extends
Catalog {
* Checks if the database with the specified name exists.
*/
override def databaseExists(dbName: String): Boolean = {
- sessionCatalog.databaseExists(dbName)
+ // To maintain backwards compatibility, we first treat the input is a
simple dbName and check
+ // if sessionCatalog contains it. If no, we try to parse it as 3 part
name. If the parased
+ // identifier contains both catalog name and database name, we then search
the database in the
+ // catalog.
+ if (!sessionCatalog.databaseExists(dbName)) {
+ val ident =
sparkSession.sessionState.sqlParser.parseMultipartIdentifier(dbName)
+ val plan =
sparkSession.sessionState.executePlan(UnresolvedNamespace(ident)).analyzed
+ plan match {
+ case ResolvedNamespace(catalog: InMemoryCatalog, _) =>
catalog.databaseExists(ident(1))
+ case _ => false
+ }
Review Comment:
If the `CatalogPlugin` is an instance of `SupportsNamespaces`, then we can
call its `namespaceExists` API. Otherwise, we can say the namespace always
exists.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]