Google Cloud Dataflow SDK for Java, version 1.9.1
com.google.cloud.dataflow.sdk.transforms
Class Mean
- java.lang.Object
-
- com.google.cloud.dataflow.sdk.transforms.Mean
-
public class Mean extends Object
PTransform
s for computing the arithmetic mean (a.k.a. average) of the elements in aPCollection
, or the mean of the values associated with each key in aPCollection
ofKV
s.Example 1: get the mean of a
PCollection
ofLong
s.PCollection<Long> input = ...; PCollection<Double> mean = input.apply(Mean.<Long>globally());
Example 2: calculate the mean of the
Integer
s associated with each unique key (which is of typeString
).PCollection<KV<String, Integer>> input = ...; PCollection<KV<String, Double>> meanPerKey = input.apply(Mean.<String, Integer>perKey());
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static <NumT extends Number>
Combine.Globally<NumT,Double>globally()
Returns aPTransform
that takes an inputPCollection<NumT>
and returns aPCollection<Double>
whose contents is the mean of the inputPCollection
's elements, or0
if there are no elements.static <K,NumT extends Number>
Combine.PerKey<K,NumT,Double>perKey()
Returns aPTransform
that takes an inputPCollection<KV<K, N>>
and returns aPCollection<KV<K, Double>>
that contains an output element mapping each distinct key in the inputPCollection
to the mean of the values associated with that key in the inputPCollection
.
-
-
-
Method Detail
-
globally
public static <NumT extends Number> Combine.Globally<NumT,Double> globally()
Returns aPTransform
that takes an inputPCollection<NumT>
and returns aPCollection<Double>
whose contents is the mean of the inputPCollection
's elements, or0
if there are no elements.- Type Parameters:
NumT
- the type of theNumber
s being combined
-
perKey
public static <K,NumT extends Number> Combine.PerKey<K,NumT,Double> perKey()
Returns aPTransform
that takes an inputPCollection<KV<K, N>>
and returns aPCollection<KV<K, Double>>
that contains an output element mapping each distinct key in the inputPCollection
to the mean of the values associated with that key in the inputPCollection
.See
Combine.PerKey
for how this affects timestamps and bucketing.- Type Parameters:
K
- the type of the keysNumT
- the type of theNumber
s being combined
-
-