Skip to content

Commit 4896411

Browse files
cloud-fanmarmbrus
authored andcommitted
[SPARK-13694][SQL] QueryPlan.expressions should always include all expressions
## What changes were proposed in this pull request? It's weird that expressions don't always have all the expressions in it. This PR marks `QueryPlan.expressions` final to forbid sub classes overriding it to exclude some expressions. Currently only `Generate` override it, we can use `producedAttributes` to fix the unresolved attribute problem for it. Note that this PR doesn't fix the problem in #11497 ## How was this patch tested? existing tests. Author: Wenchen Fan <[email protected]> Closes #11532 from cloud-fan/generate.
1 parent d7eac9d commit 4896411

File tree

4 files changed

+3
-7
lines changed

4 files changed

+3
-7
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ abstract class QueryPlan[PlanType <: TreeNode[PlanType]] extends TreeNode[PlanTy
194194
}
195195

196196
/** Returns all of the expressions present in this query plan operator. */
197-
def expressions: Seq[Expression] = {
197+
final def expressions: Seq[Expression] = {
198198
// Recursively find all expressions from a traversable.
199199
def seqToExpressions(seq: Traversable[Any]): Traversable[Expression] = seq.flatMap {
200200
case e: Expression => e :: Nil

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ case class Generate(
8989
generatorOutput.forall(_.resolved)
9090
}
9191

92-
// we don't want the gOutput to be taken as part of the expressions
93-
// as that will cause exceptions like unresolved attributes etc.
94-
override def expressions: Seq[Expression] = generator :: Nil
92+
override def producedAttributes: AttributeSet = AttributeSet(generatorOutput)
9593

9694
def output: Seq[Attribute] = {
9795
val qualified = qualifier.map(q =>

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ case class CoGroup(
208208
left: LogicalPlan,
209209
right: LogicalPlan) extends BinaryNode with ObjectOperator {
210210

211-
override def producedAttributes: AttributeSet = outputSet
212-
213211
override def deserializers: Seq[(Expression, Seq[Attribute])] =
214212
// The `leftGroup` and `rightGroup` are guaranteed te be of same schema, so it's safe to resolve
215213
// the `keyDeserializer` based on either of them, here we pick the left one.

sql/core/src/main/scala/org/apache/spark/sql/execution/Generate.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ case class Generate(
5858
private[sql] override lazy val metrics = Map(
5959
"numOutputRows" -> SQLMetrics.createLongMetric(sparkContext, "number of output rows"))
6060

61-
override def expressions: Seq[Expression] = generator :: Nil
61+
override def producedAttributes: AttributeSet = AttributeSet(output)
6262

6363
val boundGenerator = BindReferences.bindReference(generator, child.output)
6464

0 commit comments

Comments
 (0)