Github user xuanyuanking commented on a diff in the pull request: https://github.com/apache/spark/pull/22899#discussion_r229609343 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala --- @@ -1051,30 +1034,65 @@ class Analyzer( func.map(wrapper) } + + /** + * Resolves the attribute, column ordinal and extract value expressions(s) by traversing the + * input expression in bottom up manner. This routine skips over the unbound lambda function + * expressions as the lambda variables are resolved in separate rule [[ResolveLambdaVariables]]. + */ protected[sql] def resolveExpression( expr: Expression, plan: LogicalPlan, - throws: Boolean = false): Expression = { - if (expr.resolved) return expr - // Resolve expression in one round. - // If throws == false or the desired attribute doesn't exist - // (like try to resolve `a.b` but `a` doesn't exist), fail and return the origin one. - // Else, throw exception. - try { - expr transformUp { + throws: Boolean = false, + resolvedFromChildAttributes: Boolean = false): Expression = { + + def resolveExpression( + expr: Expression, + plan: LogicalPlan, + resolveFromChildAttributes: Boolean): Expression = { + expr match { case GetColumnByOrdinal(ordinal, _) => plan.output(ordinal) - case u @ UnresolvedAttribute(nameParts) => - withPosition(u) { - plan.resolve(nameParts, resolver) - .orElse(resolveLiteralFunction(nameParts, u, plan)) - .getOrElse(u) - } + case u @ UnresolvedAttribute(nameParts) if resolveFromChildAttributes => + // Leave unchanged if resolution fails. Hopefully will be resolved next round. + val result = + withPosition(u) { + plan.resolveChildren(nameParts, resolver) --- End diff -- Is there any way to fully replace `resolveChildren` by `resolve`? Just from the logic, `resolve` is next step of `resolveChildren` in recursion.
--- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org