Packages

c

org.apache.spark.sql.util

PartitionKeyedAccumulator

class PartitionKeyedAccumulator[T] extends AccumulatorV2[(Int, T), Map[Int, T]]

An AccumulatorV2 that records one value of type T per partition, keyed by partition id with LAST-WRITE-WINS merge. When the same partition is recorded more than once -- e.g. duplicate cross-executor computes, or speculative tasks -- the later value replaces the earlier one rather than aggregating, so each partition contributes exactly once. The key set is the set of recorded partitions, and callers fold the values (see foldValues) to derive de-duplicated aggregates; a plain summing accumulator would instead over-count under duplicate computes.

add is expected to be called once per task (e.g. from a task completion listener) with that partition's value, so a partition is recorded even when it produced nothing. Updates from failed/interrupted tasks are dropped by the accumulator framework (it is not countFailedValues), so only complete per-partition values are ever merged.

Backed by a ConcurrentHashMap, whose per-entry atomicity is sufficient here: add and the putAll in merge are last-write-wins per key, and the reads (value, accumulatedNumPartitions, foldValues) only require thread-safety and eventual consistency -- they are weakly consistent during concurrent updates but exact once all updates have been merged. This avoids any explicit locking (and the nested-lock pattern a two-map merge would otherwise need).

T

the per-partition value type. Must be non-null (ConcurrentHashMap forbids nulls).

Source
PartitionKeyedAccumulator.scala
Linear Supertypes
AccumulatorV2[(Int, T), Map[Int, T]], Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. PartitionKeyedAccumulator
  2. AccumulatorV2
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new PartitionKeyedAccumulator()

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def accumulatedNumPartitions: Long

    Number of distinct partitions that have been recorded.

  5. def add(v: (Int, T)): Unit

    Takes the inputs and accumulates.

    Takes the inputs and accumulates.

    Definition Classes
    PartitionKeyedAccumulatorAccumulatorV2
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @IntrinsicCandidate() @native()
  8. def copy(): PartitionKeyedAccumulator[T]

    Creates a new copy of this accumulator.

    Creates a new copy of this accumulator.

    Definition Classes
    PartitionKeyedAccumulatorAccumulatorV2
  9. def copyAndReset(): PartitionKeyedAccumulator[T]

    Creates a new copy of this accumulator, which is zero value.

    Creates a new copy of this accumulator, which is zero value. i.e. call isZero on the copy must return true.

    Definition Classes
    PartitionKeyedAccumulatorAccumulatorV2
  10. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  11. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  12. def excludeFromHeartbeat: Boolean
    Definition Classes
    AccumulatorV2
  13. def foldValues[A](zero: A)(op: (A, T) => A): A

    Folds the per-partition values (each partition counted once) into a single aggregate.

  14. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @IntrinsicCandidate() @native()
  15. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @IntrinsicCandidate() @native()
  16. final def id: Long

    Returns the id of this accumulator, can only be called after registration.

    Returns the id of this accumulator, can only be called after registration.

    Definition Classes
    AccumulatorV2
  17. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  18. final def isRegistered: Boolean

    Returns true if this accumulator has been registered.

    Returns true if this accumulator has been registered.

    Definition Classes
    AccumulatorV2
    Note

    All accumulators must be registered before use, or it will throw exception.

  19. def isZero: Boolean

    Returns if this accumulator is zero value or not.

    Returns if this accumulator is zero value or not. e.g. for a counter accumulator, 0 is zero value; for a list accumulator, Nil is zero value.

    Definition Classes
    PartitionKeyedAccumulatorAccumulatorV2
  20. def merge(other: AccumulatorV2[(Int, T), Map[Int, T]]): Unit

    Merges another same-type accumulator into this one and update its state, i.e.

    Merges another same-type accumulator into this one and update its state, i.e. this should be merge-in-place.

    Definition Classes
    PartitionKeyedAccumulatorAccumulatorV2
  21. final def name: Option[String]

    Returns the name of this accumulator, can only be called after registration.

    Returns the name of this accumulator, can only be called after registration.

    Definition Classes
    AccumulatorV2
  22. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  23. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  24. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @IntrinsicCandidate() @native()
  25. def reset(): Unit

    Resets this accumulator, which is zero value.

    Resets this accumulator, which is zero value. i.e. call isZero must return true.

    Definition Classes
    PartitionKeyedAccumulatorAccumulatorV2
  26. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  27. def toString(): String
    Definition Classes
    AccumulatorV2 → AnyRef → Any
  28. def value: Map[Int, T]

    Defines the current value of this accumulator

    Defines the current value of this accumulator

    Definition Classes
    PartitionKeyedAccumulatorAccumulatorV2
  29. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  30. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  31. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  32. def withBufferSerialized(): AccumulatorV2[(Int, T), Map[Int, T]]
    Attributes
    protected
    Definition Classes
    AccumulatorV2
  33. final def writeReplace(): Any
    Attributes
    protected
    Definition Classes
    AccumulatorV2

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

    (Since version 9)

Inherited from AccumulatorV2[(Int, T), Map[Int, T]]

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped