Skip to content

Commit aaad66a

Browse files
committed
improve
1 parent 8a22e1d commit aaad66a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/QueryPlanConstraints.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,15 @@ trait QueryPlanConstraints { self: LogicalPlan =>
9797
// Collect aliases from expressions of the whole tree rooted by the current QueryPlan node, so
9898
// we may avoid producing recursive constraints.
9999
private lazy val aliasMap: AttributeMap[Expression] = {
100-
val aliases = expressions.collect {
100+
val childrenAliases = children.flatMap { child =>
101+
val childOutputSet = child.outputSet
102+
child.asInstanceOf[QueryPlanConstraints].aliasMap.filter {
103+
case (_, c) => c.references.nonEmpty && c.references.subsetOf(childOutputSet)
104+
}
105+
}
106+
AttributeMap(expressions.collect {
101107
case a: Alias if !a.child.isInstanceOf[Literal] => (a.toAttribute, a.child)
102-
} ++ children.flatMap(_.asInstanceOf[QueryPlanConstraints].aliasMap)
103-
AttributeMap(aliases.filter {
104-
case (_, child) => child.references.nonEmpty && child.references.subsetOf(outputSet)
105-
})
108+
} ++ childrenAliases)
106109
}
107110

108111
// Note: the explicit cast is necessary, since Scala compiler fails to infer the type.

0 commit comments

Comments
 (0)