Package org.apache.beam.sdk.transforms
Class Sum
java.lang.Object
org.apache.beam.sdk.transforms.Sum
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());
-
Method Summary
Modifier and TypeMethodDescriptionstatic Combine.Globally
<Double, Double> Returns aPTransform
that takes an inputPCollection<Double>
and returns aPCollection<Double>
whose contents is the sum of the inputPCollection
's elements, or0
if there are no elements.static <K> Combine.PerKey
<K, Double, Double> Returns aPTransform
that takes an inputPCollection<KV<K, Double>>
and returns aPCollection<KV<K, Double>>
that contains an output element mapping each distinct key in the inputPCollection
to the sum of the values associated with that key in the inputPCollection
.static Combine.Globally
<Integer, Integer> Returns aPTransform
that takes an inputPCollection<Integer>
and returns aPCollection<Integer>
whose contents is the sum of the inputPCollection
's elements, or0
if there are no elements.static <K> Combine.PerKey
<K, Integer, Integer> Returns aPTransform
that takes an inputPCollection<KV<K, Integer>>
and returns aPCollection<KV<K, Integer>>
that contains an output element mapping each distinct key in the inputPCollection
to the sum of the values associated with that key in the inputPCollection
.static Combine.Globally
<Long, Long> Returns aPTransform
that takes an inputPCollection<Long>
and returns aPCollection<Long>
whose contents is the sum of the inputPCollection
's elements, or0
if there are no elements.static <K> Combine.PerKey
<K, Long, Long> Returns aPTransform
that takes an inputPCollection<KV<K, Long>>
and returns aPCollection<KV<K, Long>>
that contains an output element mapping each distinct key in the inputPCollection
to the sum of the values associated with that key in the inputPCollection
.ASerializableFunction
that computes the sum of anIterable
ofDouble
s, 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>)
.ASerializableFunction
that computes the sum of anIterable
ofInteger
s, 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.BinaryCombineLongFn
ofLongs()
ASerializableFunction
that computes the sum of anIterable
ofLong
s, 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 aPTransform
that takes an inputPCollection<Integer>
and returns aPCollection<Integer>
whose contents is the sum of the inputPCollection
's elements, or0
if there are no elements. -
integersPerKey
Returns aPTransform
that takes an inputPCollection<KV<K, Integer>>
and returns aPCollection<KV<K, Integer>>
that contains an output element mapping each distinct key in the inputPCollection
to the sum of the values associated with that key in the inputPCollection
. -
longsGlobally
Returns aPTransform
that takes an inputPCollection<Long>
and returns aPCollection<Long>
whose contents is the sum of the inputPCollection
's elements, or0
if there are no elements. -
longsPerKey
Returns aPTransform
that takes an inputPCollection<KV<K, Long>>
and returns aPCollection<KV<K, Long>>
that contains an output element mapping each distinct key in the inputPCollection
to the sum of the values associated with that key in the inputPCollection
. -
doublesGlobally
Returns aPTransform
that takes an inputPCollection<Double>
and returns aPCollection<Double>
whose contents is the sum of the inputPCollection
's elements, or0
if there are no elements. -
doublesPerKey
Returns aPTransform
that takes an inputPCollection<KV<K, Double>>
and returns aPCollection<KV<K, Double>>
that contains an output element mapping each distinct key in the inputPCollection
to the sum of the values associated with that key in the inputPCollection
. -
ofIntegers
ASerializableFunction
that computes the sum of anIterable
ofInteger
s, 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
ASerializableFunction
that computes the sum of anIterable
ofDouble
s, 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
ASerializableFunction
that computes the sum of anIterable
ofLong
s, 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>)
.
-