sunchao commented on a change in pull request #32082:
URL: https://github.com/apache/spark/pull/32082#discussion_r618116254
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
##########
@@ -2021,88 +2032,218 @@ class Analyzer(override val catalogManager:
CatalogManager)
name, other.getClass.getCanonicalName)
}
}
- case u @ UnresolvedFunction(funcId, arguments, isDistinct, filter,
ignoreNulls) =>
+
+ case u @ UnresolvedFunction(AsFunctionIdentifier(ident), arguments,
+ isDistinct, filter, ignoreNulls) =>
withPosition(u) {
- v1SessionCatalog.lookupFunction(funcId, arguments) match {
- // AggregateWindowFunctions are AggregateFunctions that can
only be evaluated within
- // the context of a Window clause. They do not need to be
wrapped in an
- // AggregateExpression.
- case wf: AggregateWindowFunction =>
- if (isDistinct) {
- throw
QueryCompilationErrors.functionWithUnsupportedSyntaxError(
- wf.prettyName, "DISTINCT")
- } else if (filter.isDefined) {
- throw
QueryCompilationErrors.functionWithUnsupportedSyntaxError(
- wf.prettyName, "FILTER clause")
- } else if (ignoreNulls) {
- wf match {
- case nthValue: NthValue =>
- nthValue.copy(ignoreNulls = ignoreNulls)
- case _ =>
- throw
QueryCompilationErrors.functionWithUnsupportedSyntaxError(
- wf.prettyName, "IGNORE NULLS")
- }
- } else {
- wf
- }
- case owf: FrameLessOffsetWindowFunction =>
- if (isDistinct) {
- throw
QueryCompilationErrors.functionWithUnsupportedSyntaxError(
- owf.prettyName, "DISTINCT")
- } else if (filter.isDefined) {
- throw
QueryCompilationErrors.functionWithUnsupportedSyntaxError(
- owf.prettyName, "FILTER clause")
- } else if (ignoreNulls) {
- owf match {
- case lead: Lead =>
- lead.copy(ignoreNulls = ignoreNulls)
- case lag: Lag =>
- lag.copy(ignoreNulls = ignoreNulls)
- }
- } else {
- owf
- }
- // We get an aggregate function, we need to wrap it in an
AggregateExpression.
- case agg: AggregateFunction =>
- if (filter.isDefined && !filter.get.deterministic) {
- throw
QueryCompilationErrors.nonDeterministicFilterInAggregateError
- }
- if (ignoreNulls) {
- val aggFunc = agg match {
- case first: First => first.copy(ignoreNulls =
ignoreNulls)
- case last: Last => last.copy(ignoreNulls = ignoreNulls)
- case _ =>
- throw
QueryCompilationErrors.functionWithUnsupportedSyntaxError(
- agg.prettyName, "IGNORE NULLS")
- }
- AggregateExpression(aggFunc, Complete, isDistinct, filter)
- } else {
- AggregateExpression(agg, Complete, isDistinct, filter)
- }
- // This function is not an aggregate function, just return the
resolved one.
- case other if isDistinct =>
- throw
QueryCompilationErrors.functionWithUnsupportedSyntaxError(
- other.prettyName, "DISTINCT")
- case other if filter.isDefined =>
- throw
QueryCompilationErrors.functionWithUnsupportedSyntaxError(
- other.prettyName, "FILTER clause")
- case other if ignoreNulls =>
- throw
QueryCompilationErrors.functionWithUnsupportedSyntaxError(
- other.prettyName, "IGNORE NULLS")
- case e: String2TrimExpression if arguments.size == 2 =>
- if (trimWarningEnabled.get) {
- log.warn("Two-parameter TRIM/LTRIM/RTRIM function
signatures are deprecated." +
- " Use SQL syntax `TRIM((BOTH | LEADING | TRAILING)?
trimStr FROM str)`" +
- " instead.")
- trimWarningEnabled.set(false)
- }
- e
- case other =>
- other
+ processFunctionExpr(v1SessionCatalog.lookupFunction(ident,
arguments),
+ arguments, isDistinct, filter, ignoreNulls)
+ }
+
+ case u @ UnresolvedFunction(parts, arguments, isDistinct, filter,
ignoreNulls) =>
+ withPosition(u) {
+ // resolve built-in or temporary functions with v2 catalog
+ val resultExpression = if (parts.length == 1) {
Review comment:
I tried, but there is a dependency between this and the following case
where we lookup the V2 function catalog. If we make them two separate cases, I
think we won't be able to express the dependency and the control flow will
always hit the first match.
--
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]