Class

org.apache.spark

Accumulator

Related Doc: package spark

Permalink

class Accumulator[T] extends Accumulable[T, T]

A simpler value of Accumulable where the result type being accumulated is the same as the types of elements being merged, i.e. variables that are only "added" to through an associative and commutative operation and can therefore be efficiently supported in parallel. They can be used to implement counters (as in MapReduce) or sums. Spark natively supports accumulators of numeric value types, and programmers can add support for new types.

An accumulator is created from an initial value v by calling SparkContext.accumulator. Tasks running on the cluster can then add to it using the += operator. However, they cannot read its value. Only the driver program can read the accumulator's value, using its #value method.

The interpreter session below shows an accumulator being used to add up the elements of an array:

scala> val accum = sc.accumulator(0)
accum: org.apache.spark.Accumulator[Int] = 0

scala> sc.parallelize(Array(1, 2, 3, 4)).foreach(x => accum += x)
...
10/09/29 18:41:08 INFO SparkContext: Tasks finished in 0.317106 s

scala> accum.value
res2: Int = 10
T

result type

Annotations
@deprecated
Deprecated

(Since version 2.0.0) use AccumulatorV2

Source
Accumulator.scala
Linear Supertypes
Accumulable[T, T], Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Accumulator
  2. Accumulable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. def ++=(term: T): Unit

    Permalink

    Merge two accumulable objects together

    Merge two accumulable objects together

    Normally, a user will not want to use this version, but will instead call +=.

    term

    the other R that will get merged with this

    Definition Classes
    Accumulable
  4. def +=(term: T): Unit

    Permalink

    Add more data to this accumulator / accumulable

    Add more data to this accumulator / accumulable

    term

    the data to add

    Definition Classes
    Accumulable
  5. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  6. def add(term: T): Unit

    Permalink

    Add more data to this accumulator / accumulable

    Add more data to this accumulator / accumulable

    term

    the data to add

    Definition Classes
    Accumulable
  7. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  8. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  12. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  13. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  14. val id: Long

    Permalink

    ID of this accumulator; for internal use only.

    ID of this accumulator; for internal use only.

    Definition Classes
    Accumulable
  15. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  16. def localValue: T

    Permalink

    Get the current value of this accumulator from within a task.

    Get the current value of this accumulator from within a task.

    This is NOT the global value of the accumulator. To get the global value after a completed operation on the dataset, call value.

    The typical use of this method is to directly mutate the local value, eg., to add an element to a Set.

    Definition Classes
    Accumulable
  17. def merge(term: T): Unit

    Permalink

    Merge two accumulable objects together

    Merge two accumulable objects together

    Normally, a user will not want to use this version, but will instead call add.

    term

    the other R that will get merged with this

    Definition Classes
    Accumulable
  18. val name: Option[String]

    Permalink

    human-readable name for use in Spark's web UI

    human-readable name for use in Spark's web UI

    Definition Classes
    Accumulable
  19. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  20. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  21. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  22. def setValue(newValue: T): Unit

    Permalink

    Set the accumulator's value.

    Set the accumulator's value. For internal use only.

    Definition Classes
    Accumulable
  23. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  24. def toString(): String

    Permalink
    Definition Classes
    Accumulable → AnyRef → Any
  25. def value: T

    Permalink

    Access the accumulator's current value; only allowed on driver.

    Access the accumulator's current value; only allowed on driver.

    Definition Classes
    Accumulable
  26. def value_=(newValue: T): Unit

    Permalink

    Set the accumulator's value; only allowed on driver.

    Set the accumulator's value; only allowed on driver.

    Definition Classes
    Accumulable
  27. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  28. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  29. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. val zero: T

    Permalink
    Definition Classes
    Accumulable

Inherited from Accumulable[T, T]

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped