cloud-fan commented on code in PR #57323:
URL: https://github.com/apache/spark/pull/57323#discussion_r3600839572


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/LastAttemptAggregatingAccumulator.scala:
##########
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.execution
+
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.Expression
+import org.apache.spark.sql.catalyst.expressions.aggregate.ImperativeAggregate
+import 
org.apache.spark.sql.catalyst.expressions.aggregate.TypedImperativeAggregate
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.types.DataType
+import org.apache.spark.util.{AccumulatorV2, LastAttemptAccumulator, Utils}
+
+class LastAttemptAggregatingAccumulator private[execution](
+    bufferSchema: Seq[DataType],
+    initialValues: Seq[Expression],
+    updateExpressions: Seq[Expression],
+    mergeExpressions: Seq[Expression],
+    resultExpressions: Seq[Expression],
+    imperatives: Array[ImperativeAggregate],
+    typedImperatives: Array[TypedImperativeAggregate[_]],
+    conf: SQLConf)
+  extends AggregatingAccumulator(
+    bufferSchema,
+    initialValues,
+    updateExpressions,
+    mergeExpressions,
+    resultExpressions,
+    imperatives,
+    typedImperatives,
+    conf)
+  with LastAttemptAccumulator[InternalRow, InternalRow, InternalRow] {
+
+  // Snapshot the schema before task serialization drops transient result 
expressions. On the driver,
+  // the last-attempt merge path compares this accumulator with copies 
returned from tasks; those
+  // task-side copies may no longer be able to lazily rebuild 
AggregatingAccumulator.schema.
+  private val outputSchema = schema

Review Comment:
   This `outputSchema = schema` snapshot is correct and load-bearing, but it 
works via a subtlety worth a comment. The base declares 
`resultExpressions`/`conf` `@transient`; here they're re-declared as bare ctor 
params and referenced in the body (`copyAndReset()` and this line), so Scala 
generates *non-transient* subclass fields for them. That's exactly what keeps 
the schema reconstructable after task serialization — on an executor-side 
`copyAndReset()`, the base's transient copies are null, but the subclass's 
duplicates survive.
   
   The risk is that this is implicit: a future "these fields look redundant / 
should be transient" cleanup would silently break executor-side 
`copyAndReset()`/`outputSchema`. The comment at lines 47-49 explains *why* the 
snapshot is taken, but not that the field duplication is deliberate. Consider a 
one-line note here (or at the ctor) that `resultExpressions`/`conf` are 
intentionally re-materialized non-transient in the subclass.
   
   (Secondary, informational: this also means the Catalyst result expressions + 
`SQLConf` now serialize to every observed task, where the plain accumulator 
dropped them as transient — a modest, bounded cost, not a correctness issue.)



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/LastAttemptAggregatingAccumulator.scala:
##########
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.execution
+
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.Expression
+import org.apache.spark.sql.catalyst.expressions.aggregate.ImperativeAggregate
+import 
org.apache.spark.sql.catalyst.expressions.aggregate.TypedImperativeAggregate
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.types.DataType
+import org.apache.spark.util.{AccumulatorV2, LastAttemptAccumulator, Utils}
+
+class LastAttemptAggregatingAccumulator private[execution](
+    bufferSchema: Seq[DataType],
+    initialValues: Seq[Expression],
+    updateExpressions: Seq[Expression],
+    mergeExpressions: Seq[Expression],
+    resultExpressions: Seq[Expression],
+    imperatives: Array[ImperativeAggregate],
+    typedImperatives: Array[TypedImperativeAggregate[_]],
+    conf: SQLConf)
+  extends AggregatingAccumulator(
+    bufferSchema,
+    initialValues,
+    updateExpressions,
+    mergeExpressions,
+    resultExpressions,
+    imperatives,
+    typedImperatives,
+    conf)
+  with LastAttemptAccumulator[InternalRow, InternalRow, InternalRow] {
+
+  // Snapshot the schema before task serialization drops transient result 
expressions. On the driver,

Review Comment:
   This comment line is 101 chars, over the 100-char limit — will fail the 
Scala linter in CI.
   ```suggestion
     // Snapshot the schema before task serialization drops transient result 
expressions. On
     // the driver,
   ```



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