Package org.apache.spark.util
Class LongAccumulator
- All Implemented Interfaces:
Serializable
An
accumulator for computing sum, count, and average of 64-bit integers.
- Since:
- 2.0.0
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(long v) Adds v to the accumulator, i.e.voidAdds v to the accumulator, i.e.doubleavg()Returns the average of elements added to the accumulator.copy()Creates a new copy of this accumulator.longcount()Returns the number of elements added to the accumulator.booleanisZero()Returns false if this accumulator has had any values added to it or the sum is non-zero.voidmerge(AccumulatorV2<Long, Long> other) Merges another same-type accumulator into this one and update its state, i.e.voidreset()Resets this accumulator, which is zero value.longsum()Returns the sum of elements added to the accumulator.value()Defines the current value of this accumulatorMethods inherited from class org.apache.spark.util.AccumulatorV2
copyAndReset, excludeFromHeartbeat, id, isRegistered, name, toString
-
Constructor Details
-
LongAccumulator
public LongAccumulator()
-
-
Method Details
-
add
Adds v to the accumulator, i.e. increment sum by v and count by 1.- Specified by:
addin classAccumulatorV2<Long,Long> - Parameters:
v- (undocumented)- Since:
- 2.0.0
-
add
public void add(long v) Adds v to the accumulator, i.e. increment sum by v and count by 1.- Parameters:
v- (undocumented)- Since:
- 2.0.0
-
avg
public double avg()Returns the average of elements added to the accumulator.- Returns:
- (undocumented)
- Since:
- 2.0.0
-
copy
Description copied from class:AccumulatorV2Creates a new copy of this accumulator.- Specified by:
copyin classAccumulatorV2<Long,Long> - Returns:
- (undocumented)
-
count
public long count()Returns the number of elements added to the accumulator.- Returns:
- (undocumented)
- Since:
- 2.0.0
-
isZero
public boolean isZero()Returns false if this accumulator has had any values added to it or the sum is non-zero.- Specified by:
isZeroin classAccumulatorV2<Long,Long> - Returns:
- (undocumented)
- Since:
- 2.0.0
-
merge
Description copied from class:AccumulatorV2Merges another same-type accumulator into this one and update its state, i.e. this should be merge-in-place.- Specified by:
mergein classAccumulatorV2<Long,Long> - Parameters:
other- (undocumented)
-
reset
public void reset()Description copied from class:AccumulatorV2Resets this accumulator, which is zero value. i.e. callisZeromust return true.- Specified by:
resetin classAccumulatorV2<Long,Long>
-
sum
public long sum()Returns the sum of elements added to the accumulator.- Returns:
- (undocumented)
- Since:
- 2.0.0
-
value
Description copied from class:AccumulatorV2Defines the current value of this accumulator- Specified by:
valuein classAccumulatorV2<Long,Long> - Returns:
- (undocumented)
-