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/03/16 22:38:02 UTC

[GitHub] [spark] sigmod commented on a change in pull request #35864: [SPARK-38531][SQL] Fix the condition of "Prune unrequired child index" branch of ColumnPruning

sigmod commented on a change in pull request #35864:
URL: https://github.com/apache/spark/pull/35864#discussion_r828505854



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -831,8 +831,16 @@ object ColumnPruning extends Rule[LogicalPlan] {
       e.copy(child = prunedChild(child, e.references))
 
     // prune unrequired references
-    case p @ Project(_, g: Generate) if p.references != g.outputSet =>
-      val requiredAttrs = p.references -- g.producedAttributes ++ g.generator.references
+    // There are 2 types of pruning here:
+    // 1. For attributes in g.child.outputSet that is not used by the generator nor the project,
+    //    we directly remove it from the output list of g.child.
+    // 2. For attributes that is not used by the project but it is used by the generator, we put
+    //    it in g.unrequiredChildIndex to save memory usage.
+    case p @ Project(_, g: Generate) if g.child.output.zipWithIndex.exists(
+      pair =>
+      !p.references.contains(pair._1) &&
+        (!g.generator.references.contains(pair._1) || !g.unrequiredChildIndex.contains(pair._2))) =>

Review comment:
       Does it work if we switch the order case branches? Since the rule is a fix-point batch, it can hit `GeneratorNestedColumnAliasing` in the first iteration and Project(_, g: Generate) in the next?
   
   ```
       // prune unrequired nested fields from `Generate`.
       // prioritize this case branch over  Project(_, g: Generate) for SPARK-38531
       case GeneratorNestedColumnAliasing(rewrittenPlan) => rewrittenPlan
       
      // prune unrequired references
       case p @ Project(_, g: Generate) if p.references != g.outputSet => ...
   ```




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