cloud-fan commented on code in PR #53570:
URL: https://github.com/apache/spark/pull/53570#discussion_r2870505997
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionResolution.scala:
##########
@@ -73,70 +257,119 @@ class FunctionResolution(
}
def lookupBuiltinOrTempFunction(
- name: Seq[String],
- u: Option[UnresolvedFunction]): Option[ExpressionInfo] = {
- if (name.size == 1 && u.exists(_.isInternal)) {
- FunctionRegistry.internal.lookupFunction(FunctionIdentifier(name.head))
- } else if (name.size == 1) {
- v1SessionCatalog.lookupBuiltinOrTempFunction(name.head)
+ nameParts: Seq[String],
+ unresolvedFunc: Option[UnresolvedFunction]): Option[ExpressionInfo] = {
+ if (nameParts.size == 1 && unresolvedFunc.exists(_.isInternal)) {
+
FunctionRegistry.internal.lookupFunction(FunctionIdentifier(nameParts.head))
} else {
- None
+ FunctionResolution.sessionNamespaceKind(nameParts) match {
+ case Some(kind) =>
+ v1SessionCatalog.lookupFunctionInfo(kind, nameParts.last,
tableFunction = false)
+ case None =>
+ if (nameParts.size == 1) {
+ v1SessionCatalog.lookupBuiltinOrTempFunction(nameParts.head)
+ } else {
+ None
+ }
+ }
}
}
- def lookupBuiltinOrTempTableFunction(name: Seq[String]):
Option[ExpressionInfo] = {
- if (name.length == 1) {
- v1SessionCatalog.lookupBuiltinOrTempTableFunction(name.head)
- } else {
- None
+ def lookupBuiltinOrTempTableFunction(nameParts: Seq[String]):
Option[ExpressionInfo] = {
+ FunctionResolution.sessionNamespaceKind(nameParts) match {
+ case Some(kind) =>
+ v1SessionCatalog.lookupFunctionInfo(kind, nameParts.last,
tableFunction = true)
+ case None =>
+ if (nameParts.length == 1) {
+ v1SessionCatalog.lookupBuiltinOrTempTableFunction(nameParts.head)
+ } else {
+ None
+ }
}
}
- def resolveBuiltinOrTempFunction(
- name: Seq[String],
- arguments: Seq[Expression],
- u: UnresolvedFunction): Option[Expression] = {
- val expression = if (name.size == 1 && u.isInternal) {
-
Option(FunctionRegistry.internal.lookupFunction(FunctionIdentifier(name.head),
arguments))
- } else if (name.size == 1) {
- v1SessionCatalog.resolveBuiltinOrTempFunction(name.head, arguments)
- } else {
- None
+ /**
+ * Determines the type/location of a function (builtin, temporary,
persistent, etc.).
+ * This is used by the LookupFunctions analyzer rule for early validation
and optimization.
+ * This method only performs the lookup and classification - it does not
throw errors.
+ *
+ * @param nameParts The function name parts.
+ * @param unresolvedFunc Optional UnresolvedFunction node for lookups that
may need it.
+ * @return The type of the function (Builtin, Temporary, Persistent,
TableOnly, or NotFound).
+ */
+ def lookupFunctionType(
+ nameParts: Seq[String],
+ unresolvedFunc: Option[UnresolvedFunction] = None): FunctionType = {
+
+ // Check if it's explicitly qualified as extension, builtin, or temp
+ FunctionResolution.sessionNamespaceKind(nameParts) match {
+ case Some(SessionCatalog.Extension) | Some(SessionCatalog.Builtin) =>
+ if (lookupBuiltinOrTempFunction(nameParts, unresolvedFunc).isDefined) {
Review Comment:
do we need to check existence when determining the `FunctionType`? The
search path resolution will try next one if can't find the function with the
current type.
--
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]