Package org.apache.beam.sdk.transforms
Class Sum
java.lang.Object
org.apache.beam.sdk.transforms.Sum
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());
-
Method Summary
Modifier and TypeMethodDescriptionstatic Combine.Globally<Double, Double> Returns aPTransformthat takes an inputPCollection<Double>and returns aPCollection<Double>whose contents is the sum of the inputPCollection's elements, or0if there are no elements.static <K> Combine.PerKey<K, Double, Double> Returns aPTransformthat takes an inputPCollection<KV<K, Double>>and returns aPCollection<KV<K, Double>>that contains an output element mapping each distinct key in the inputPCollectionto the sum of the values associated with that key in the inputPCollection.static Combine.Globally<Integer, Integer> Returns aPTransformthat takes an inputPCollection<Integer>and returns aPCollection<Integer>whose contents is the sum of the inputPCollection's elements, or0if there are no elements.static <K> Combine.PerKey<K, Integer, Integer> Returns aPTransformthat takes an inputPCollection<KV<K, Integer>>and returns aPCollection<KV<K, Integer>>that contains an output element mapping each distinct key in the inputPCollectionto the sum of the values associated with that key in the inputPCollection.static Combine.Globally<Long, Long> Returns aPTransformthat takes an inputPCollection<Long>and returns aPCollection<Long>whose contents is the sum of the inputPCollection's elements, or0if there are no elements.static <K> Combine.PerKey<K, Long, Long> Returns aPTransformthat takes an inputPCollection<KV<K, Long>>and returns aPCollection<KV<K, Long>>that contains an output element mapping each distinct key in the inputPCollectionto the sum of the values associated with that key in the inputPCollection.ASerializableFunctionthat computes the sum of anIterableofDoubles, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).ASerializableFunctionthat computes the sum of anIterableofIntegers, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).static Combine.BinaryCombineLongFnofLongs()ASerializableFunctionthat computes the sum of anIterableofLongs, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).
-
Method Details
-
integersGlobally
Returns aPTransformthat takes an inputPCollection<Integer>and returns aPCollection<Integer>whose contents is the sum of the inputPCollection's elements, or0if there are no elements. -
integersPerKey
Returns aPTransformthat takes an inputPCollection<KV<K, Integer>>and returns aPCollection<KV<K, Integer>>that contains an output element mapping each distinct key in the inputPCollectionto the sum of the values associated with that key in the inputPCollection. -
longsGlobally
Returns aPTransformthat takes an inputPCollection<Long>and returns aPCollection<Long>whose contents is the sum of the inputPCollection's elements, or0if there are no elements. -
longsPerKey
Returns aPTransformthat takes an inputPCollection<KV<K, Long>>and returns aPCollection<KV<K, Long>>that contains an output element mapping each distinct key in the inputPCollectionto the sum of the values associated with that key in the inputPCollection. -
doublesGlobally
Returns aPTransformthat takes an inputPCollection<Double>and returns aPCollection<Double>whose contents is the sum of the inputPCollection's elements, or0if there are no elements. -
doublesPerKey
Returns aPTransformthat takes an inputPCollection<KV<K, Double>>and returns aPCollection<KV<K, Double>>that contains an output element mapping each distinct key in the inputPCollectionto the sum of the values associated with that key in the inputPCollection. -
ofIntegers
ASerializableFunctionthat computes the sum of anIterableofIntegers, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>). -
ofDoubles
ASerializableFunctionthat computes the sum of anIterableofDoubles, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>). -
ofLongs
ASerializableFunctionthat computes the sum of anIterableofLongs, useful as an argument toCombine.globally(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>)orCombine.perKey(org.apache.beam.sdk.transforms.SerializableFunction<java.lang.Iterable<V>, V>).
-