sunchao commented on a change in pull request #32082:
URL: https://github.com/apache/spark/pull/32082#discussion_r621538744
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -2095,9 +2104,101 @@ class Analyzer(override val catalogManager:
CatalogManager)
case other =>
other
}
+ }
+
+ case u @ UnresolvedFunction(nameParts, arguments, isDistinct,
filter, ignoreNulls) =>
+ withPosition(u) {
+ expandIdentifier(nameParts) match {
+ case NonSessionCatalogAndIdentifier(catalog, ident) =>
+ if (!catalog.isFunctionCatalog) {
+ throw new AnalysisException(s"Trying to lookup function
'$ident' in " +
+ s"catalog '${catalog.name()}', but it is not a
FunctionCatalog.")
+ }
+
+ val unbound = catalog.asFunctionCatalog.loadFunction(ident)
+ val inputType = StructType(arguments.zipWithIndex.map {
+ case (exp, pos) => StructField(s"_$pos", exp.dataType,
exp.nullable)
+ })
+ val bound = try {
+ unbound.bind(inputType)
+ } catch {
+ case unsupported: UnsupportedOperationException =>
+ throw new AnalysisException(s"Function '${unbound.name}'
cannot process " +
+ s"input:
(${arguments.map(_.dataType.simpleString).mkString(", ")}): " +
+ unsupported.getMessage, cause = Some(unsupported))
+ }
+
+ bound match {
+ case scalarFunc: ScalarFunction[_] =>
+ if (isDistinct) {
Review comment:
Sure, done. I think we can also consider moving the big chunk of
handling of V1 and V2 functions separately into two functions like what I used
to have:
```scala
case u @ UnresolvedFunction(AsFunctionIdentifier(ident), arguments,
isDistinct,
filter, ignoreNulls) => withPosition(u) {
processV1Function(...)
}
case u @ UnresolvedFunction(nameParts, arguments, isDistinct, filter,
ignoreNulls) =>
withPosition(u) {
processV2Function(...)
}
```
to keep the main logic of pattern matching on unresolved functions clearer.
Let me know if you prefer this way too.
--
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]