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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -306,13 +309,20 @@ object AnalysisContext {
       // and must be recorded there. Sharing the caller's set records it; a 
nested view, by
       // contrast, stores its own and so is reset. The exception is a SQL 
function body under
       // creation, which must not inherit the dependencies of the functions it 
calls; see
-      // `shareIdentifierVariablesWithNestedSQLFunctions`.
+      // `shareTempReferencesWithNestedSQLFunctions`.
       referredTempVariableNamesUnderIdentifier =
-        if (originContext.shareIdentifierVariablesWithNestedSQLFunctions) {
+        if (originContext.shareTempReferencesWithNestedSQLFunctions) {
           originContext.referredTempVariableNamesUnderIdentifier
         } else {
           mutable.LinkedHashSet.empty
         },
+      // The same holds for the temporary functions the body binds.
+      referredTempFunctionNames =

Review Comment:
   Good catch, fixed in 099b81b2e4e. A default that a named-argument call fills 
in now counts as the called function's dependency, the same as with a 
positional call. Views still record it. Added tests for both, plus a table 
function.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionResolution.scala:
##########
@@ -390,6 +390,19 @@ class FunctionResolution(
     }
   }
 
+  /**
+   * Whether [[lookupBuiltinOrTempFunction]] finds the function. An 
unqualified name records no
+   * temp reference, see `SessionCatalog.builtinOrTempFunctionExists`.
+   */
+  def builtinOrTempFunctionExists(
+      nameParts: Seq[String],
+      unresolvedFunc: Option[UnresolvedFunction]): Boolean =
+    if (nameParts.length == 1 && !unresolvedFunc.exists(_.isInternal)) {
+      v1SessionCatalog.builtinOrTempFunctionExists(nameParts.head)
+    } else {
+      lookupBuiltinOrTempFunction(nameParts, unresolvedFunc).isDefined

Review Comment:
   Good catch, fixed in 099b81b2e4e. The early check no longer records 
`session.f`, so only the function the call actually resolves to counts. Added 
tests under `persistentCatalogFirst` (accepted) and the default order (still 
rejected).



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/command/CreateSQLFunctionCommand.scala:
##########
@@ -174,8 +175,8 @@ case class CreateSQLFunctionCommand(
         checkCyclicFunctionReference(catalog, name, plan)
 
         // Check the function body can be analyzed correctly.
-        val (analyzed, referredTempVarsUnderIdentifier) =
-          analyzer.executeWithReferredTempVariablesUnderIdentifier(plan)
+        val (analyzed, referredTempFuncs, referredTempVarsUnderIdentifier) =

Review Comment:
   Good catch, fixed in 099b81b2e4e. For an unqualified call, the cycle check 
now uses the function the call resolves to, so it follows `sessionOrder` and 
the SQL path. Added tests for scalar and table functions.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -163,7 +163,8 @@ case class AnalysisContext(
     // 1. If we are resolving a view, this field will be restored from the 
view metadata,
     //    by calling `AnalysisContext.withAnalysisContext(viewDesc)`.
     // 2. If we are not resolving a view, this field will be updated everytime 
the analyzer
-    //    lookup a temporary function. And export to the view metadata.
+    //    lookup a temporary function. And export to the view metadata, or 
checked by persistent

Review Comment:
   Done in 099b81b2e4e.



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala:
##########
@@ -603,25 +609,29 @@ class Analyzer(
   }
 
   /**
-   * Like [[execute]], but also returns the temporary variables recorded via 
IDENTIFIER clauses
-   * during this analysis 
(`AnalysisContext.referredTempVariableNamesUnderIdentifier`).
+   * Like [[execute]], but also returns the temporary functions the analysis 
bound
+   * (`AnalysisContext.referredTempFunctionNames`) and the temporary variables 
recorded via
+   * IDENTIFIER clauses 
(`AnalysisContext.referredTempVariableNamesUnderIdentifier`).
    *
    * SQL function creation analyzes the body, inspects it, and only then runs 
`checkAnalysis`, so
    * it cannot go through 
[[executeAndCheckReferredTempVariablesUnderIdentifier]]. It still needs
-   * the recorded variables, which [[execute]] discards with its analysis 
context: a persistent
-   * function must reject them and a temporary one stores them in its metadata.
+   * the recorded names, which [[execute]] discards with its analysis context: 
a persistent
+   * function must reject them and a temporary one stores the variables in its 
metadata.

Review Comment:
   Done in 099b81b2e4e.



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