cloud-fan commented on a change in pull request #30662:
URL: https://github.com/apache/spark/pull/30662#discussion_r539854029



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
##########
@@ -1488,12 +1488,32 @@ class SessionCatalog(
     // We probably shouldn't use a single FunctionRegistry to register all 
three kinds of functions
     // (built-in, temp, and external).
     if (name.database.isEmpty && functionRegistry.functionExists(name)) {
-      // This function has been already loaded into the function registry.
-      return functionRegistry.lookupFunction(name, children)
+      val referredTempFunctionNames = 
AnalysisContext.get.referredTempFunctionNames
+      val isResolvingView = AnalysisContext.get.catalogAndNamespace.nonEmpty
+      // We lookup function without database in three cases:
+      // 1. the function is not a temporary function
+      // 2. the function is a temporary function but we are not resolving view
+      // 3. we are resolving a view and the function is a temporary function 
referred by this view
+      if (!isTemporaryFunction(name) ||
+        !isResolvingView ||
+        referredTempFunctionNames.contains(name.funcName)) {
+        // This function has been already loaded into the function registry.
+        return functionRegistry.lookupFunction(name, children)
+      }
+    }
+
+    // Get the database from AnalysisContext if it's defined, otherwise, use 
current database
+    val currentDatabase = AnalysisContext.get.catalogAndNamespace match {
+      case Seq() => getCurrentDatabase
+      case Seq(_, db) => db
+      case Seq(catalog, namespace @ _*) =>
+        throw new AnalysisException(
+          s"V2 catalog does not support functions yet. " +
+            s"catalog: ${catalog}, namespace '${namespace.mkString("[", ".", 
"]")}'")

Review comment:
       nit: `namespace.quoted`. We need to import `CatalogV2Implicits._` first.




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

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