databricks-david-lewis commented on a change in pull request #27377:
[WIP][SPARK-30666][Core] Reliable single-stage accumulators
URL: https://github.com/apache/spark/pull/27377#discussion_r373068144
##########
File path: core/src/main/scala/org/apache/spark/util/AccumulatorV2.scala
##########
@@ -350,10 +359,38 @@ class LongAccumulator extends AccumulatorV2[jl.Long,
jl.Long] {
*/
def avg: Double = _sum.toDouble / _count
- override def merge(other: AccumulatorV2[jl.Long, jl.Long]): Unit = other
match {
+ override def merge(other: AccumulatorV2[jl.Long, jl.Long],
+ fragmentId: Option[Int] = None): Unit = other match {
case o: LongAccumulator =>
- _sum += o.sum
- _count += o.count
+ metadata.mode match {
+ case AccumulatorMode.All =>
+ _sum += o.sum
+ _count += o.count
+ case AccumulatorMode.Max =>
+ val (fragmentSum, fragmentCount) =
+ fragmentId
+ .flatMap(_fragments.remove)
+ .getOrElse((0L, 0L))
+ val (maxSum, maxCount) =
+ if (o.sum > fragmentSum || (o.sum == fragmentSum && o.count <
fragmentCount)) {
+ (o.sum, o.count)
+ } else {
+ (fragmentSum, fragmentCount)
+ }
+ _sum += maxSum - fragmentSum
+ _count += maxCount - fragmentCount
+ fragmentId.foreach(_fragments(_) = (maxSum, maxCount))
+ case AccumulatorMode.Last =>
+ val (fragmentSum, fragmentCount) =
+ fragmentId
Review comment:
When is the `fragmentId` None?
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]