Github user andrewor14 commented on a diff in the pull request: https://github.com/apache/spark/pull/12117#discussion_r58456181 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala --- @@ -524,7 +537,39 @@ class SessionCatalog( * Note: This is currently only used for temporary functions. */ def lookupFunction(name: String, children: Seq[Expression]): Expression = { - functionRegistry.lookupFunction(name, children) + // TODO: Right now, the name can be qualified or not qualified. + // It will be better to get a FunctionIdentifier. + // TODO: Right now, we assume that name is not qualified! + val qualifiedName = FunctionIdentifier(name, Some(currentDb)).unquotedString + if (functionRegistry.functionExists(name)) { + // This function has been already loaded into the function registry. + functionRegistry.lookupFunction(name, children) + } else if (functionRegistry.functionExists(qualifiedName)) { + // This function has been already loaded into the function registry. + // Unlike the above block, we find this function by using the qualified name. + functionRegistry.lookupFunction(qualifiedName, children) + } else { + // The function has not been loaded to the function registry, which means + // that the function is a permanent function (if it actually has been registered + // in the metastore). We need to first put the function in FunctionRegistry. + val catalogFunction = try { + externalCatalog.getFunction(currentDb, name) + } catch { + case e: AnalysisException => failFunctionLookup(name) + case e: NoSuchFunctionException => failFunctionLookup(name) + } + loadFunctionResources(catalogFunction.resources) + // Please note that qualifiedName is provided by the user. However, + // catalogFunction.identifier.unquotedString is returned by the underlying + // catalog. So, it is possible that qualifiedName is not exactly the same as + // catalogFunction.identifier.unquotedString (difference is on case-sensitivity). + // At here, we preserve the input from the user. + val info = new ExpressionInfo(catalogFunction.className, qualifiedName) + val builder = makeFunctionBuilder(qualifiedName, catalogFunction.className) + createTempFunction(qualifiedName, info, builder, ignoreIfExists = false) --- End diff -- the javadoc says nothing about this. We should add a sentence there to say we cache it in the registry.
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org