layout: section title: “Sum” permalink: /documentation/transforms/java/aggregation/sum/ section_menu: section-menu/documentation.html

Sum

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]({{ site.baseurl }}/documentation/transforms/java/aggregation/count) counts the number of elements within each aggregation