Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/12131#discussion_r58294572
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
---
@@ -1475,7 +1438,94 @@ class Analyzer(
Project(projectList, Join(left, right, joinType, newCondition))
}
+ /**
+ * Replaces [[UnresolvedDeserializer]] with the deserialization
expression that has been resolved
+ * by the given input attributes.
+ */
+ object ResolveDeserializer extends Rule[LogicalPlan] {
+ def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators {
+ case p if !p.childrenResolved => p
+ case p if p.resolved => p
+ case p => p transformExpressions {
+ case UnresolvedDeserializer(deserializer, inputAttributes) =>
+ val inputs = if (inputAttributes.isEmpty) {
+ p.children.flatMap(_.output)
+ } else {
+ inputAttributes
+ }
+ val unbound = deserializer transform {
+ case b: BoundReference => inputs(b.ordinal)
+ }
+ resolveExpression(unbound, LocalRelation(inputs), throws = true)
+ }
+ }
+ }
+
+ /**
+ * Resolves [[NewInstance]] by finding and adding the outer scope to it
if the object being
+ * constructed is an inner class.
+ */
+ object ResolveNewInstance extends Rule[LogicalPlan] {
+ def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators {
+ case p if !p.childrenResolved => p
+ case p if p.resolved => p
+
+ case p => p transformExpressions {
+ case n: NewInstance if n.childrenResolved && !n.resolved =>
+ val outer = OuterScopes.getOuterScope(n.cls)
+ if (outer == null) {
+ throw new AnalysisException(
+ s"Unable to generate an encoder for inner class
`${n.cls.getName}` without " +
+ "access to the scope that this class was defined in.\n" +
+ "Try moving this class out of its parent class.")
+ }
+ n.copy(outerPointer = Some(outer))
+ }
+ }
+ }
+
+ /**
+ * Replace the [[UpCast]] expression by [[Cast]], and throw exceptions
if the cast may truncate.
+ */
+ object ResolveUpCast extends Rule[LogicalPlan] {
--- End diff --
Move rules related to deserializer expressions together.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]