public class Count
extends java.lang.Object
Count<T> takes a PCollection<T> and returns a
PCollection<KV<T, Long>> representing a map from each
distinct element of the input PCollection to the number of times
that element occurs in the input. Each of the keys in the output
PCollection is unique.
Two values of type T are compared for equality not by
regular Java Object.equals(java.lang.Object), but instead by first encoding
each of the elements using the PCollection's Coder, and then
comparing the encoded bytes. This admits efficient parallel
evaluation.
By default, the Coder of the keys of the output
PCollection is the same as the Coder of the
elements of the input PCollection.
Each output element is in the window by which its corresponding input
was grouped, and has the timestamp of the end of that window. The output
PCollection has the same
WindowFn
as the input.
Example of use:
PCollection<String> words = ...;
PCollection<KV<String, Long>> wordCounts =
words.apply(Count.<String>perElement());
| Modifier and Type | Class and Description |
|---|---|
static class |
Count.Globally<T>
Count.Globally<T> takes a PCollection<T> and returns a
PCollection<Long> containing a single element which is the total
number of elements in the PCollection. |
static class |
Count.PerElement<T>
Count.PerElement<T> takes a PCollection<T> and returns a
PCollection<KV<T, Long>> representing a map from each
distinct element of the input PCollection to the number of times
that element occurs in the input. |
| Constructor and Description |
|---|
Count() |
| Modifier and Type | Method and Description |
|---|---|
static <T> Count.Globally<T> |
globally()
|
static <T> Count.PerElement<T> |
perElement()
Returns a
Count.PerElement PTransform
that counts the number of occurrences of each element in its
input PCollection. |
public static <T> Count.Globally<T> globally()
Count.Globally PTransform
that counts the number of elements in its input PCollection.
See Count.Globally for more details.
public static <T> Count.PerElement<T> perElement()
Count.PerElement PTransform
that counts the number of occurrences of each element in its
input PCollection.
See Count.PerElement for more details.