Package org.apache.spark.sql.util
Class PartitionKeyedAccumulator<T>
Object
org.apache.spark.util.AccumulatorV2<scala.Tuple2<Object,T>,Map<Object,T>>
org.apache.spark.sql.util.PartitionKeyedAccumulator<T>
- Type Parameters:
T- the per-partition value type. Must be non-null (ConcurrentHashMapforbids nulls).
- All Implemented Interfaces:
Serializable
public class PartitionKeyedAccumulator<T>
extends AccumulatorV2<scala.Tuple2<Object,T>,Map<Object,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 <A>foldValues(A,scala.Function2<A,T,A>)) 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. All access is synchronized so a caller can atomically verify
that every partition completed and read its statistics from the same stable snapshot.
Framework-facing reads remain safe, weakly consistent views.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongNumber of distinct partitions that have been recorded.voidTakes the inputs and accumulates.copy()Creates a new copy of this accumulator.Creates a new copy of this accumulator, which is zero value.<A> AfoldValues(A zero, scala.Function2<A, T, A> op) Folds the per-partition values (each partition counted once) into a single aggregate.<A> scala.Option<A>foldValuesIfComplete(int expectedNumPartitions, A zero, scala.Function2<A, T, A> op) Atomically checks that all partitions completed and folds their statistics.booleanisZero()Returns if this accumulator is zero value or not.voidMerges another same-type accumulator into this one and update its state, i.e.voidreset()Resets this accumulator, which is zero value.value()Defines the current value of this accumulatorMethods inherited from class org.apache.spark.util.AccumulatorV2
excludeFromHeartbeat, id, isRegistered, name, toString
-
Constructor Details
-
PartitionKeyedAccumulator
public PartitionKeyedAccumulator()
-
-
Method Details
-
accumulatedNumPartitions
public long accumulatedNumPartitions()Number of distinct partitions that have been recorded. -
add
Description copied from class:AccumulatorV2Takes the inputs and accumulates. -
copy
Description copied from class:AccumulatorV2Creates a new copy of this accumulator. -
copyAndReset
Description copied from class:AccumulatorV2Creates a new copy of this accumulator, which is zero value. i.e. callisZeroon the copy must return true.- Overrides:
copyAndResetin classAccumulatorV2<scala.Tuple2<Object,T>, Map<Object, T>> - Returns:
- (undocumented)
-
foldValues
Folds the per-partition values (each partition counted once) into a single aggregate. -
foldValuesIfComplete
public <A> scala.Option<A> foldValuesIfComplete(int expectedNumPartitions, A zero, scala.Function2<A, T, A> op) Atomically checks that all partitions completed and folds their statistics. -
isZero
public boolean isZero()Description copied from class:AccumulatorV2Returns 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. -
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. -
reset
public void reset()Description copied from class:AccumulatorV2Resets this accumulator, which is zero value. i.e. callisZeromust return true. -
value
Description copied from class:AccumulatorV2Defines the current value of this accumulator
-