T - the type of the elements of the input PCollection, and the type of the keys
of the output PCollectionpublic static class Count.PerElement<T> extends PTransform<PCollection<T>,PCollection<KV<T,Long>>>
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. Each key in the
output PCollection is unique.
This transform compares two values of type T by first encoding each element using
the input PCollection's Coder, then comparing the encoded bytes. Because of
this, the input coder must be deterministic.
(See Coder.verifyDeterministic() for more detail).
Performing the comparison in this manner 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.
Example of use:
PCollection<String> words = ...;
PCollection<KV<String, Long>> wordCounts =
words.apply(Count.<String>perElement());
name| Constructor and Description |
|---|
PerElement() |
| Modifier and Type | Method and Description |
|---|---|
PCollection<KV<T,Long>> |
apply(PCollection<T> input)
Applies this
PTransform on the given InputT, and returns its
Output. |
getDefaultOutputCoder, getDefaultOutputCoder, getDefaultOutputCoder, getKindString, getName, populateDisplayData, toString, validatepublic PCollection<KV<T,Long>> apply(PCollection<T> input)
PTransformPTransform on the given InputT, and returns its
Output.
Composite transforms, which are defined in terms of other transforms, should return the output of one of the composed transforms. Non-composite transforms, which do not apply any transforms internally, should return a new unbound output and register evaluators (via backend-specific registration methods).
apply in class PTransform<PCollection<T>,PCollection<KV<T,Long>>>