com.google.cloud.dataflow.sdk.transforms

## Class Sum

- java.lang.Object
- - com.google.cloud.dataflow.sdk.transforms.Sum

    public class Sum
    extends Object

`PTransform`s for computing the sum of the elements in a `PCollection`, or the sum of the values associated with each key in a `PCollection` of `KV`s.

Example 1: get the sum of a `PCollection` of `Double`s.

     PCollection<Double> input = ...;
     PCollection<Double> sum = input.apply(Sum.doublesGlobally());

Example 2: calculate the sum of the `Integer`s associated with each unique key (which is of type `String`).

     PCollection<KV<String, Integer>> input = ...;
     PCollection<KV<String, Integer>> sumPerKey = input
         .apply(Sum.<String>integersPerKey());

### Nested Class Summary

Nested Classes
`static class` `Sum.SumDoubleFn` A `SerializableFunction` that computes the sum of an `Iterable` of `Double`s, useful as an argument to `Combine.globally(com.google.cloud.dataflow.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)` or `Combine.perKey(com.google.cloud.dataflow.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)`.
`static class` `Sum.SumIntegerFn` A `SerializableFunction` that computes the sum of an `Iterable` of `Integer`s, useful as an argument to `Combine.globally(com.google.cloud.dataflow.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)` or `Combine.perKey(com.google.cloud.dataflow.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)`.
`static class` `Sum.SumLongFn` A `SerializableFunction` that computes the sum of an `Iterable` of `Long`s, useful as an argument to `Combine.globally(com.google.cloud.dataflow.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)` or `Combine.perKey(com.google.cloud.dataflow.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)`.

### Method Summary

All Methods Static Methods Concrete Methods
`static Combine.Globally<Double,Double>` `doublesGlobally()` Returns a `PTransform` that takes an input `PCollection<Double>` and returns a `PCollection<Double>` whose contents is the sum of the input `PCollection`'s elements, or `0` if there are no elements.
`static <K> Combine.PerKey<K,Double,Double>` `doublesPerKey()` Returns a `PTransform` that takes an input `PCollection<KV<K, Double>>` and returns a `PCollection<KV<K, Double>>` that contains an output element mapping each distinct key in the input `PCollection` to the sum of the values associated with that key in the input `PCollection`.
`static Combine.Globally<Integer,Integer>` `integersGlobally()` Returns a `PTransform` that takes an input `PCollection<Integer>` and returns a `PCollection<Integer>` whose contents is the sum of the input `PCollection`'s elements, or `0` if there are no elements.
`static <K> Combine.PerKey<K,Integer,Integer>` `integersPerKey()` Returns a `PTransform` that takes an input `PCollection<KV<K, Integer>>` and returns a `PCollection<KV<K, Integer>>` that contains an output element mapping each distinct key in the input `PCollection` to the sum of the values associated with that key in the input `PCollection`.
`static Combine.Globally<Long,Long>` `longsGlobally()` Returns a `PTransform` that takes an input `PCollection<Long>` and returns a `PCollection<Long>` whose contents is the sum of the input `PCollection`'s elements, or `0` if there are no elements.
`static <K> Combine.PerKey<K,Long,Long>` `longsPerKey()` Returns a `PTransform` that takes an input `PCollection<KV<K, Long>>` and returns a `PCollection<KV<K, Long>>` that contains an output element mapping each distinct key in the input `PCollection` to the sum of the values associated with that key in the input `PCollection`.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### integersGlobally

    public static Combine.Globally<Integer,Integer> integersGlobally()

Returns a `PTransform` that takes an input `PCollection<Integer>` and returns a `PCollection<Integer>` whose contents is the sum of the input `PCollection`'s elements, or `0` if there are no elements.

#### integersPerKey

    public static <K> Combine.PerKey<K,Integer,Integer> integersPerKey()

Returns a `PTransform` that takes an input `PCollection<KV<K, Integer>>` and returns a `PCollection<KV<K, Integer>>` that contains an output element mapping each distinct key in the input `PCollection` to the sum of the values associated with that key in the input `PCollection`.

#### longsGlobally

    public static Combine.Globally<Long,Long> longsGlobally()

Returns a `PTransform` that takes an input `PCollection<Long>` and returns a `PCollection<Long>` whose contents is the sum of the input `PCollection`'s elements, or `0` if there are no elements.

#### longsPerKey

    public static <K> Combine.PerKey<K,Long,Long> longsPerKey()

Returns a `PTransform` that takes an input `PCollection<KV<K, Long>>` and returns a `PCollection<KV<K, Long>>` that contains an output element mapping each distinct key in the input `PCollection` to the sum of the values associated with that key in the input `PCollection`.

#### doublesGlobally

    public static Combine.Globally<Double,Double> doublesGlobally()

Returns a `PTransform` that takes an input `PCollection<Double>` and returns a `PCollection<Double>` whose contents is the sum of the input `PCollection`'s elements, or `0` if there are no elements.

#### doublesPerKey

    public static <K> Combine.PerKey<K,Double,Double> doublesPerKey()

Returns a `PTransform` that takes an input `PCollection<KV<K, Double>>` and returns a `PCollection<KV<K, Double>>` that contains an output element mapping each distinct key in the input `PCollection` to the sum of the values associated with that key in the input `PCollection`.