spark-test commented on code in PR #60468:
URL: https://github.com/apache/spark/pull/60468#discussion_r4571607886


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala:
##########
@@ -612,11 +499,14 @@ case class HashAggregateExec(
       case _ => conf.fastHashAggregateRowMaxCapacityBit
     }
 
-    val thisPlan = ctx.addReferenceObj("plan", this)
+    // The generated code calls into a helper rather than into this plan node: 
a reference to the
+    // node would serialize its whole child subtree into every task binary (see
+    // `HashAggregateCodegenHelper`).
+    val aggHelper = ctx.addReferenceObj("aggHelper", createCodegenHelper())

Review Comment:
   **Nit (P3):** SortExec, SortMergeJoinExec, SortMergeAsOfJoinExec and 
ShuffledHashJoinExec still call `ctx.addReferenceObj("plan", this)`, so a Spark 
stage that contains one of them, for example a local sort or a sort-merge join 
above this aggregate, still writes the aggregate's subtree into every task 
binary. The follow-ups (SPARK-61666, SPARK-61668) and the planned check over 
every whole-stage-codegen stage are recorded only in the review discussion, 
while this comment and the new test describe the problem and its check for the 
aggregate alone. A TODO here naming the four operators and their tickets, plus 
one in the new test saying it checks only aggregate stages until the all-stage 
check lands, would keep a later change from copying the old pattern and keep 
the follow-up from being lost.
   
   This extends an [existing 
discussion](https://github.com/apache/spark/pull/60468#discussion_r4569446100).
   
   **Verification:**
   - **Inspection:** Check that the comment at the aggregate's codegen helper 
registration names the four operators that still register their own plan node, 
together with SPARK-61666 and SPARK-61668. Also check that the 
plan-serialization test's comment says it checks only aggregate stages until 
the check over every whole-stage-codegen stage is added.



##########
sql/core/src/test/scala/org/apache/spark/sql/execution/WholeStageCodegenSuite.scala:
##########
@@ -381,6 +383,63 @@ class WholeStageCodegenSuite extends SharedSparkSession
     assert(df.collect() === Array(Row(0, 1), Row(2, 1), Row(4, 1)))
   }
 
+  test("SPARK-61661: HashAggregate codegen references do not serialize plan 
nodes") {
+    // What a codegen stage adds to the task binary (its closure, with the 
references of the
+    // generated code) is serialized into every task. A plan node in it would 
drag its whole child
+    // subtree along (for the final aggregate, the whole map-side plan through 
the exchange).
+    def serializedPlanNodes(stage: WholeStageCodegenExec): Seq[String] = {
+      // Serialize the RDD that the stage adds on top of its input RDDs, as 
the task binary does:
+      // its closure or evaluator factory with the generated code references. 
The input RDDs are
+      // not followed, since they belong to the operators below this stage.

Review Comment:
   **Nit (P3):** The reason given here holds only for the final stage, whose 
input RDD is the shuffle read. The suite disables AQE, so the partial stage is 
`*(1) HashAggregate <- Project <- Range`, and its only input RDD is the one 
`RangeExec.inputRDDs()` builds inside this stage. Skipping it is still right, 
since input RDDs hold none of the generated code references, but once the check 
is extended to every whole-stage-codegen stage, this wording suggests the skip 
drops only what lies below the stage, when it also drops whatever a codegen 
source such as a range or a scan ships.
   
   ```suggestion
         // its closure or evaluator factory with the generated code 
references. The input RDDs are
         // not followed: they come from the stage's codegen source (the range 
in the partial stage)
         // or from the stage below it (the shuffle read in the final stage), 
and hold none of the
         // generated code references.
   ```
   
   This extends an [existing 
discussion](https://github.com/apache/spark/pull/60468#discussion_r4569446121).
   
   **Verification:**
   - **Inspection:** Check that the comment explaining why the serialization 
check skips the input RDDs says they come from the stage's codegen source, such 
as the range in the partial stage, or from the stage below, and no longer says 
they belong only to operators below the stage.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to