Sum
Transforms for computing the sum of the elements in a collection, or the sum of the values associated with each key in a collection of key-value pairs.
Examples
Example 1: get the sum of a PCollection
of Doubles
.
PCollection<Double> input = ...;
PCollection<Double> sum = input.apply(Sum.doublesGlobally());
Example 2: calculate the sum of the Integers
associated with each unique key (which is of type String
).
PCollection<KV<String, Integer>> input = ...;
PCollection<KV<String, Integer>> sumPerKey = input
.apply(Sum.integersPerKey());
Related transforms
- Count counts the number of elements within each aggregation