Skip to content

Commit

Permalink
[SPARK-48851][SQL] Attach full name for SCHEMA_NOT_FOUND
Browse files Browse the repository at this point in the history
  • Loading branch information
panbingkun committed Jul 10, 2024
1 parent 4c99c4d commit 1904634
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ class NoSuchDatabaseException private(
messageParameters = Map("schemaName" -> quoteIdentifier(db)),
cause = None)
}

def this(db: Seq[String]) = {
this(
errorClass = "SCHEMA_NOT_FOUND",
messageParameters = Map("schemaName" -> quoteNameParts(db)),
cause = None)
}
}

// any changes to this class should be backward compatible as it may be used by external connectors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ class SessionCatalog(
functionExpressionBuilder: FunctionExpressionBuilder,
cacheSize: Int = SQLConf.get.tableRelationCacheSize,
cacheTTL: Long = SQLConf.get.metadataCacheTTL,
defaultDatabase: String = SQLConf.get.defaultDatabase) extends SQLConfHelper with Logging {
defaultDatabase: String = SQLConf.get.defaultDatabase,
var catalogName: Option[String] = Some(CatalogManager.SESSION_CATALOG_NAME))
extends SQLConfHelper with Logging {
import SessionCatalog._
import CatalogTypes.TablePartitionSpec

Expand Down Expand Up @@ -250,7 +252,8 @@ class SessionCatalog(

private def requireDbExists(db: String): Unit = {
if (!databaseExists(db)) {
throw new NoSuchDatabaseException(db)
val nameParts = catalogName.map(Seq(_, db)).getOrElse(Seq(db))
throw new NoSuchDatabaseException(nameParts)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class InMemoryTableCatalog extends BasicInMemoryTableCatalog with SupportsNamesp
case _ if namespaceExists(namespace) =>
util.Collections.emptyMap[String, String]
case _ =>
throw new NoSuchNamespaceException(namespace)
throw new NoSuchNamespaceException(name +: namespace)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ class V2SessionCatalog(catalog: SessionCatalog)
override def name: String = CatalogManager.SESSION_CATALOG_NAME

// This class is instantiated by Spark, so `initialize` method will not be called.
override def initialize(name: String, options: CaseInsensitiveStringMap): Unit = {}
override def initialize(name: String, options: CaseInsensitiveStringMap): Unit = {
catalog.catalogName = Some(name)
}

override def capabilities(): util.Set[TableCatalogCapability] = {
Set(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ trait AlterNamespaceUnsetPropertiesSuiteBase extends QueryTest with DDLCommandTe
}
checkError(e,
errorClass = "SCHEMA_NOT_FOUND",
parameters = Map("schemaName" -> s"`$ns`"))
parameters = Map("schemaName" -> s"`$catalog`.`$ns`"))
}

test("basic test") {
Expand Down

0 comments on commit 1904634

Please sign in to comment.