public class Mean
extends java.lang.Object
PTransforms for computing the arithmetic mean
(a.k.a. average) of the elements in a PCollection, or the
mean of the values associated with each key in a
PCollection of KVs.
Example 1: get the mean of a PCollection of Longs.
PCollection<Long> input = ...;
PCollection<Double> mean = input.apply(Mean.<Long>globally());
Example 2: calculate the mean of the Integers
associated with each unique key (which is of type String).
PCollection<KV<String, Integer>> input = ...;
PCollection<KV<String, Double>> meanPerKey =
input.apply(Mean.<String, Integer>perKey());
| Modifier and Type | Class and Description |
|---|---|
static class |
Mean.MeanFn<N extends java.lang.Number>
A
Combine.CombineFn that computes the arithmetic mean
(a.k.a. |
| Constructor and Description |
|---|
Mean() |
| Modifier and Type | Method and Description |
|---|---|
static <N extends java.lang.Number> |
globally()
Returns a
PTransform that takes an input
PCollection<N> and returns a
PCollection<Double> whose contents is the mean of the
input PCollection's elements, or
0 if there are no elements. |
static <K,N extends java.lang.Number> |
perKey()
Returns a
PTransform that takes an input
PCollection<KV<K, N>> and returns a
PCollection<KV<K, Double>> that contains an output
element mapping each distinct key in the input
PCollection to the mean of the values associated with
that key in the input PCollection. |
public static <N extends java.lang.Number> Combine.Globally<N,java.lang.Double> globally()
PTransform that takes an input
PCollection<N> and returns a
PCollection<Double> whose contents is the mean of the
input PCollection's elements, or
0 if there are no elements.N - the type of the Numbers being combinedpublic static <K,N extends java.lang.Number> Combine.PerKey<K,N,java.lang.Double> perKey()
PTransform that takes an input
PCollection<KV<K, N>> and returns a
PCollection<KV<K, Double>> that contains an output
element mapping each distinct key in the input
PCollection to the mean of the values associated with
that key in the input PCollection.
See Combine.PerKey for how this affects timestamps and bucketing.K - the type of the keysN - the type of the Numbers being combined