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


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/command/CreateSQLFunctionCommand.scala:
##########
@@ -432,14 +470,23 @@ case class CreateSQLFunctionCommand(
       identifier: FunctionIdentifier,
       plan: LogicalPlan): Unit = {
 
+    // `functionIdentifierForLookup`, if `nameParts` names a SQL function.
+    def sqlFunctionIdentifier(
+        nameParts: Seq[String],
+        tableFunction: Boolean): Option[(FunctionIdentifier, Boolean)] =
+      functionIdentifierForLookup(catalog, nameParts).filter {
+        case (ident, true) => catalog.lookupFunctionInfoByIdentifier(ident, 
tableFunction)
+          .exists(info => isSQLFunction(info.getClassName))
+        case (ident, false) => 
isSQLFunction(catalog.lookupFunctionInfo(ident).getClassName)
+      }
+
     def checkPlan(plan: LogicalPlan, path: Seq[FunctionIdentifier]): Unit = {
       plan.foreach {
         case u @ UnresolvedTableValuedFunction(nameParts, arguments, _) =>
-          val funcId = nameParts.asFunctionIdentifier
-          val info = catalog.lookupFunctionInfo(funcId)
-          if (isSQLFunction(info.getClassName)) {
+          sqlFunctionIdentifier(nameParts, tableFunction = true).foreach { 
case (ident, isSystem) =>
             val f = withPosition(u) {
-              catalog.lookupTableFunction(funcId, 
arguments).asInstanceOf[SQLTableFunction]
+              (if (isSystem) catalog.resolveTableFunctionByIdentifier(ident, 
arguments).get

Review Comment:
   Done.



##########
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.

Review Comment:
   Done.



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