File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical
core/src/test/scala/org/apache/spark/sql Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -614,13 +614,20 @@ case class Union(
614
614
Some (sum.toLong)
615
615
}
616
616
617
+ def duplicateResolvedPerChild : Boolean =
618
+ children.forall(child => child.outputSet.size == child.output.size)
619
+
617
620
def duplicateResolved : Boolean = {
618
621
children.map(_.outputSet.size).sum ==
619
622
AttributeSet .fromAttributeSets(children.map(_.outputSet)).size
620
623
}
621
624
622
625
override lazy val resolved : Boolean = {
623
- children.length > 1 && ! (byName || allowMissingCol) && childrenResolved && allChildrenCompatible
626
+ children.length > 1 &&
627
+ ! (byName || allowMissingCol) &&
628
+ childrenResolved &&
629
+ allChildrenCompatible &&
630
+ duplicateResolvedPerChild
624
631
}
625
632
626
633
override protected def withNewChildrenInternal (newChildren : IndexedSeq [LogicalPlan ]): Union =
Original file line number Diff line number Diff line change @@ -4963,6 +4963,23 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
4963
4963
)
4964
4964
}
4965
4965
4966
+ test(" SPARK-52686: Union should be resolved only if there are no duplicates" ) {
4967
+ withTable(" t1" ) {
4968
+ withView(" v1" ) {
4969
+ sql(" CREATE TABLE t1(col1 STRING)" )
4970
+ sql(" CREATE VIEW v1 AS SELECT * FROM t1" )
4971
+ val analyzedPlan = sql(
4972
+ " SELECT * FROM (SELECT col1, col1 FROM v1 UNION SELECT col1, col1 FROM v1)"
4973
+ ).queryExecution.analyzed
4974
+
4975
+ // Resolving * should wait for Union output to be deduplicated, otherwise we are
4976
+ // left with duplicate ExprIds in the result.
4977
+ val exprIds = analyzedPlan.asInstanceOf [Project ].projectList.map(_.exprId)
4978
+ assert(exprIds.size == exprIds.distinct.size)
4979
+ }
4980
+ }
4981
+ }
4982
+
4966
4983
Seq (true , false ).foreach { codegenEnabled =>
4967
4984
test(s " SPARK-52060: one row relation with codegen enabled - $codegenEnabled" ) {
4968
4985
withSQLConf(SQLConf .WHOLESTAGE_CODEGEN_ENABLED .key -> codegenEnabled.toString) {
You can’t perform that action at this time.
0 commit comments