Skip to content

Commit 884dd6b

Browse files
committed
Merge pull request #87 from mbautin/csd-1.4_fix_union_nullability
Fix nullability computation in union output
2 parents 65ce53f + 01ac19f commit 884dd6b

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,10 @@ case class Filter(condition: Expression, child: LogicalPlan) extends UnaryNode {
8888
}
8989

9090
case class Union(left: LogicalPlan, right: LogicalPlan) extends BinaryNode {
91-
// TODO: These aren't really the same attributes as nullability etc might change.
92-
override def output: Seq[Attribute] = left.output
91+
override def output: Seq[Attribute] =
92+
left.output.zip(right.output).map { case (leftAttr, rightAttr) =>
93+
leftAttr.withNullability(leftAttr.nullable || rightAttr.nullable)
94+
}
9395

9496
override lazy val resolved: Boolean =
9597
childrenResolved &&

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,13 @@ case class Sample(
9797
*/
9898
@DeveloperApi
9999
case class Union(children: Seq[SparkPlan]) extends SparkPlan {
100-
// TODO: attributes output by union should be distinct for nullability purposes
101-
override def output: Seq[Attribute] = children.head.output
100+
override def output: Seq[Attribute] = {
101+
children.tail.foldLeft(children.head.output) { case (currentOutput, child) =>
102+
currentOutput.zip(child.output).map { case (a1, a2) =>
103+
a1.withNullability(a1.nullable || a2.nullable)
104+
}
105+
}
106+
}
102107
protected override def doExecute(): RDD[Row] = sparkContext.union(children.map(_.execute()))
103108
}
104109

0 commit comments

Comments
 (0)