public class Sum
extends java.lang.Object
PTransforms for computing the sum of the elements in a PCollection, or the sum of
the values associated with each key in a PCollection of KVs.
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.<String>integersPerKey());
| Modifier and Type | Method and Description |
|---|---|
static Combine.Globally<java.lang.Double,java.lang.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,java.lang.Double,java.lang.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<java.lang.Integer,java.lang.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,java.lang.Integer,java.lang.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<java.lang.Long,java.lang.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,java.lang.Long,java.lang.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. |
static Combine.BinaryCombineDoubleFn |
ofDoubles()
A
SerializableFunction that computes the sum of an Iterable of Doubles,
useful as an argument to Combine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>) or Combine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>). |
static Combine.BinaryCombineIntegerFn |
ofIntegers()
A
SerializableFunction that computes the sum of an Iterable of Integers, useful as an argument to Combine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>) or Combine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>). |
static Combine.BinaryCombineLongFn |
ofLongs()
A
SerializableFunction that computes the sum of an Iterable of Longs,
useful as an argument to Combine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>) or Combine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>). |
public static Combine.Globally<java.lang.Integer,java.lang.Integer> integersGlobally()
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.public static <K> Combine.PerKey<K,java.lang.Integer,java.lang.Integer> integersPerKey()
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.public static Combine.Globally<java.lang.Long,java.lang.Long> longsGlobally()
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.public static <K> Combine.PerKey<K,java.lang.Long,java.lang.Long> longsPerKey()
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.public static Combine.Globally<java.lang.Double,java.lang.Double> doublesGlobally()
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.public static <K> Combine.PerKey<K,java.lang.Double,java.lang.Double> doublesPerKey()
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.public static Combine.BinaryCombineIntegerFn ofIntegers()
SerializableFunction that computes the sum of an Iterable of Integers, useful as an argument to Combine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>) or Combine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).public static Combine.BinaryCombineDoubleFn ofDoubles()
SerializableFunction that computes the sum of an Iterable of Doubles,
useful as an argument to Combine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>) or Combine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).public static Combine.BinaryCombineLongFn ofLongs()
SerializableFunction that computes the sum of an Iterable of Longs,
useful as an argument to Combine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>) or Combine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).