Pydoc Pydoc

Combines all elements in a collection.

See more information in the Beam Programming Guide.


In the following examples, we create a pipeline with a PCollection of produce. Then, we apply CombineGlobally in multiple ways to combine all the elements in the PCollection.

CombineGlobally accepts a function that takes an iterable of elements as an input, and combines them to return a single element.

Example 1: Combining with a function

We define a function get_common_items which takes an iterable of sets as an input, and calculates the intersection (common items) of those sets.

Example 2: Combining with a lambda function

We can also use lambda functions to simplify Example 1.

Example 3: Combining with multiple arguments

You can pass functions with multiple arguments to CombineGlobally. They are passed as additional positional arguments or keyword arguments to the function.

In this example, the lambda function takes sets and exclude as arguments.

Example 4: Combining with a CombineFn

The more general way to combine elements, and the most flexible, is with a class that inherits from CombineFn.

You can use the following combiner transforms:

Pydoc Pydoc