Pydoc Pydoc

Counts the number of elements within each aggregation.


In the following example, we create a pipeline with two PCollections of produce. Then, we apply Count to get the total number of elements in different ways.

Example 1: Counting all elements in a PCollection

We use Count.Globally() to count all elements in a PCollection, even if there are duplicate elements.

Example 2: Counting elements for each key

We use Count.PerKey() to count the elements for each unique key in a PCollection of key-values.

Example 3: Counting all unique elements

We use Count.PerElement() to count the only the unique elements in a PCollection.


Pydoc Pydoc