cloud-fan commented on code in PR #36977:
URL: https://github.com/apache/spark/pull/36977#discussion_r911576859
##########
sql/core/src/main/scala/org/apache/spark/sql/internal/CatalogImpl.scala:
##########
@@ -191,21 +192,77 @@ class CatalogImpl(sparkSession: SparkSession) extends
Catalog {
*/
@throws[AnalysisException]("database does not exist")
override def listFunctions(dbName: String): Dataset[Function] = {
- requireDatabaseExists(dbName)
- val functions = sessionCatalog.listFunctions(dbName).map { case
(functIdent, _) =>
- makeFunction(functIdent)
+ // `dbName` could be either a single database name (behavior in Spark 3.3
and prior) or
+ // a qualified namespace with catalog name. We assume it's a single
database name
+ // and check if we can find the dbName in sessionCatalog. If so we
listFunctions under
+ // that database. Otherwise we try 3-part name parsing and locate the
database.
+ if (sessionCatalog.databaseExists(dbName) ||
sessionCatalog.isGlobalTempViewDB(dbName)) {
+ val functions = sessionCatalog.listFunctions(dbName)
+ .map { case (functIdent, _) => makeFunction(functIdent) }
+ CatalogImpl.makeDataset(functions, sparkSession)
+ } else {
+ val ident =
sparkSession.sessionState.sqlParser.parseMultipartIdentifier(dbName)
+ val plan = ShowFunctions(UnresolvedNamespace(ident), true, true, None)
+ val results = sparkSession.sessionState.executePlan(plan).toRdd.collect()
+ val functions = results.map { row =>
+ val name = row.getString(0).split("\\.").last
+ makeFunction(ident :+ name)
+ }
+ CatalogImpl.makeDataset(functions, sparkSession)
}
- CatalogImpl.makeDataset(functions, sparkSession)
}
private def makeFunction(funcIdent: FunctionIdentifier): Function = {
- val metadata = sessionCatalog.lookupFunctionInfo(funcIdent)
+ val metadata = try {
+ Some(sessionCatalog.getFunctionMetadata(funcIdent))
Review Comment:
why do we make this change?
--
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]