Package org.apache.spark.util
Class AccumulatorV2<IN,OUT>
Object
org.apache.spark.util.AccumulatorV2<IN,OUT>
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
CollectionAccumulator,DoubleAccumulator,LongAccumulator,MapperRowCounter
The base class for accumulators, that can accumulate inputs of type
IN, and produce output of
type OUT.
OUT should be a type that can be read atomically (e.g., Int, Long), or thread-safely
(e.g., synchronized collections) because it will be read from other threads.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidTakes the inputs and accumulates.abstract AccumulatorV2<IN,OUT> copy()Creates a new copy of this accumulator.Creates a new copy of this accumulator, which is zero value.booleanfinal longid()Returns the id of this accumulator, can only be called after registration.final booleanReturns true if this accumulator has been registered.abstract booleanisZero()Returns if this accumulator is zero value or not.abstract voidmerge(AccumulatorV2<IN, OUT> other) Merges another same-type accumulator into this one and update its state, i.e.final scala.Option<String>name()Returns the name of this accumulator, can only be called after registration.abstract voidreset()Resets this accumulator, which is zero value.toString()abstract OUTvalue()Defines the current value of this accumulator
-
Constructor Details
-
AccumulatorV2
public AccumulatorV2()
-
-
Method Details
-
add
Takes the inputs and accumulates.- Parameters:
v- (undocumented)
-
copy
Creates a new copy of this accumulator.- Returns:
- (undocumented)
-
copyAndReset
Creates a new copy of this accumulator, which is zero value. i.e. callisZeroon the copy must return true.- Returns:
- (undocumented)
-
excludeFromHeartbeat
public boolean excludeFromHeartbeat() -
id
public final long id()Returns the id of this accumulator, can only be called after registration.- Returns:
- (undocumented)
-
isRegistered
public final boolean isRegistered()Returns true if this accumulator has been registered.- Returns:
- (undocumented)
- Note:
- All accumulators must be registered before use, or it will throw exception.
-
isZero
public abstract boolean isZero()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.- Returns:
- (undocumented)
-
merge
Merges another same-type accumulator into this one and update its state, i.e. this should be merge-in-place.- Parameters:
other- (undocumented)
-
name
Returns the name of this accumulator, can only be called after registration.- Returns:
- (undocumented)
-
reset
public abstract void reset()Resets this accumulator, which is zero value. i.e. callisZeromust return true. -
toString
-
value
Defines the current value of this accumulator- Returns:
- (undocumented)
-