szehon-ho commented on code in PR #57323:
URL: https://github.com/apache/spark/pull/57323#discussion_r3625744839
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/AggregatingAccumulator.scala:
##########
@@ -299,4 +314,57 @@ object AggregatingAccumulator {
typedImperatives.toArray,
SQLConf.get)
}
+
+ /**
+ * Create an aggregating accumulator for the given functions and input
schema.
+ */
+ def apply(functions: Seq[Expression], inputAttributes: Seq[Attribute]):
AggregatingAccumulator = {
+ val c = buildAccumulatorArgs(functions, inputAttributes)
+ new AggregatingAccumulator(
+ c.bufferSchema,
+ c.initialValues,
+ c.updateExpressions,
+ c.mergeExpressions,
+ c.resultExpressions,
+ c.imperatives,
+ c.typedImperatives,
+ c.conf)
+ }
+
+ def apply(
Review Comment:
Done — added scaladoc on the remaining factory overloads, noting which ones
register (and, for lastAttempt, initialize last-attempt tracking).
##########
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:
Follow-up: kept `conf` transient (executors already get SQL config from
TaskContext / local properties, matching the pre-existing
AggregatingAccumulator behavior). `resultExpressions` is now kept via an
explicit `serializedResultExpressions` field, and `serializedOutputSchema` is
an eager snapshot for `isMergeable()`.
--
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]