ganeshashree commented on code in PR #60214:
URL: https://github.com/apache/spark/pull/60214#discussion_r4640987563


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/command/CreateSQLFunctionCommand.scala:
##########
@@ -387,6 +390,41 @@ case class CreateSQLFunctionCommand(
     (collectTempViews(child), tempFunctions)
   }
 
+  // Whether `nameParts` (unqualified, or `session.` / 
`system.session.`-qualified) names a temp
+  // function.
+  private def isTemporaryFunctionName(catalog: SessionCatalog, nameParts: 
Seq[String]): Boolean =
+    nameParts match {
+      case Seq(funcName) => 
catalog.isTemporaryFunction(FunctionIdentifier(funcName))
+      case _ => functionIdentifierForLookup(catalog, nameParts).exists {
+        case (ident, isSystem) => isSystem && 
catalog.isTemporaryFunction(ident)
+      }
+    }
+
+  // The identifier to look up `nameParts` by, and whether it is in a system 
namespace. A
+  // `builtin.` / `session.` name follows function resolution's candidate 
order. None for another
+  // catalog's function.
+  private def functionIdentifierForLookup(
+      catalog: SessionCatalog,
+      nameParts: Seq[String]): Option[(FunctionIdentifier, Boolean)] = {
+    lazy val persistentIdent = nameParts match {
+      case Seq(_) | Seq(_, _) => Some(nameParts.asFunctionIdentifier)
+      // Catalog names are case-insensitive regardless of 
spark.sql.caseSensitive.
+      case Seq(c, db, f) if 
c.equalsIgnoreCase(CatalogManager.SESSION_CATALOG_NAME) =>
+        Some(FunctionIdentifier(f, Some(db), 
Some(CatalogManager.SESSION_CATALOG_NAME)))
+      case _ => None
+    }
+    def systemFunctionExists(ident: FunctionIdentifier): Boolean =
+      catalog.lookupFunctionInfoByIdentifier(ident, tableFunction = 
false).isDefined ||
+        catalog.lookupFunctionInfoByIdentifier(ident, tableFunction = 
true).isDefined
+    catalog.identifierFromSystemNameParts(nameParts) match {
+      case Some(ident) if nameParts.length > 2 ||
+          (conf.prioritizeSystemCatalog && systemFunctionExists(ident)) ||
+          !catalog.isPersistentFunction(persistentIdent.get) =>

Review Comment:
   This only runs for a `builtin.`/`session.` call the system namespace lacks, 
i.e. a function in a schema named `builtin` or `session`, so I'd keep the 
single resolution-order helper rather than add a lookup-driven variant for it.



-- 
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]

Reply via email to