pyflink.datastream.data_stream.KeyedStream.reduce#
- KeyedStream.reduce(func: Callable | ReduceFunction) DataStream[source]#
Applies a reduce transformation on the grouped data stream grouped on by the given key position. The ReduceFunction will receive input values based on the key value. Only input values with the same key will go to the same reducer.
Example:
>>> ds = env.from_collection([(1, 'a'), (2, 'a'), (3, 'a'), (4, 'b']) >>> ds.key_by(lambda x: x[1]).reduce(lambda a, b: a[0] + b[0], b[1])
- Parameters:
func – The ReduceFunction that is called for each element of the DataStream.
- Returns:
The transformed DataStream.