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 2021/02/23 04:27:56 UTC

[GitHub] [spark] c21 commented on a change in pull request #31595: [SPARK-34474][SQL] Remove unnecessary Union under Distinct/Deduplicate

c21 commented on a change in pull request #31595:
URL: https://github.com/apache/spark/pull/31595#discussion_r580761460



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -501,6 +502,42 @@ object RemoveNoopOperators extends Rule[LogicalPlan] {
   }
 }
 
+/**
+ * Remove no-op `Union` from the query plan that do not make any modifications.
+ */
+object RemoveNoopUnion extends Rule[LogicalPlan] {
+  private def removeAliasOnlyProject(plan: LogicalPlan): LogicalPlan = plan match {
+    case p @ Project(projectList, child) =>
+      val originalOutputs = projectList.collect {

Review comment:
       I feel `collect` is kind of dangerous here, we essentially ignore all expressions that are not attribute or alias of attribute here. How can it work correctly?
   
   I am thinking of example query like
   
   ```
   SELECT DISTINCT k, expr
   FROM
   (
     SELECT k, k + 1 AS expr
     FROM test_table
     UNION ALL
     SELECT k, k + 2 AS expr
     FROM test_table
   )
   ```




----------------------------------------------------------------
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.

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