You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/05/19 04:12:28 UTC

[GitHub] [spark] wangyum commented on a diff in pull request #36595: [SPARK-39216][SQL] Do not collapse projects in CombineUnions if it hasCorrelatedSubquery

wangyum commented on code in PR #36595:
URL: https://github.com/apache/spark/pull/36595#discussion_r876577315


##########
sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala:
##########
@@ -4427,6 +4427,31 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
         ))
     }
   }
+
+  test("SPARK-39216: Don't collapse projects in CombineUnions if it hasCorrelatedSubquery") {
+    checkAnswer(
+      sql(
+        """
+          |SELECT (SELECT IF(x, 1, 0)) AS a
+          |FROM (SELECT true) t(x)
+          |UNION
+          |SELECT 1 AS a
+        """.stripMargin),
+      Seq(Row(1)))
+
+    checkAnswer(
+      sql(
+        """
+          |SELECT x + 1
+          |FROM   (SELECT id
+          |               + (SELECT Max(id)
+          |                  FROM   range(2)) AS x
+          |        FROM   range(1)) t
+          |UNION
+          |SELECT 1 AS a
+        """.stripMargin),
+      Seq(Row(2), Row(1)))

Review Comment:
   ```
   === Applying Rule org.apache.spark.sql.catalyst.optimizer.CombineUnions ===
    Distinct                                                          Distinct
    +- Union false, false                                             +- Union false, false
   !   :- Project [(x#219L + cast(1 as bigint)) AS (x + 1)#225L]         :- Project [((id#221L + scalar-subquery#218 []) + cast(1 as bigint)) AS (x + 1)#225L]
   !   :  +- Project [(id#221L + scalar-subquery#218 []) AS x#219L]      :  :  +- Aggregate [max(id#222L) AS max(id)#224L]
   !   :     :  +- Aggregate [max(id#222L) AS max(id)#224L]              :  :     +- Range (0, 2, step=1, splits=None)
   !   :     :     +- Range (0, 2, step=1, splits=None)                  :  +- Range (0, 1, step=1, splits=None)
   !   :     +- Range (0, 1, step=1, splits=None)                        +- Project [cast(1 as bigint) AS a#226L]
   !   +- Project [cast(a#220 as bigint) AS a#226L]                         +- OneRowRelation
   !      +- Project [1 AS a#220]                                     
   !         +- OneRowRelation    
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org