Skip to main content
Ctrl+K
PyFlink 1.20+vvr.11.7.dev0 documentation - Home PyFlink 1.20+vvr.11.7.dev0 documentation - Home
  • API Reference
  • Examples
  • API Reference
  • Examples

Section Navigation

  • PyFlink Table
  • PyFlink DataStream
    • StreamExecutionEnvironment
    • DataStream
    • Functions
    • State
    • Timer
    • Window
    • Checkpoint
    • Side Outputs
    • Asynchronous I/O
    • Connectors
    • Formats
  • PyFlink DataFrame
  • PyFlink Common
  • API Reference
  • PyFlink DataStream
  • DataStream
  • pyflink.datastream.data_stream.KeyedStream.max_by

pyflink.datastream.data_stream.KeyedStream.max_by#

KeyedStream.max_by(position_to_max_by: int | str = 0) → DataStream[source]#

Applies an aggregation that gives the current element with the maximize value at the given position by the given key. An independent aggregate is kept per key. If more elements have the maximize value at the given position, the operator returns the first one by default.

Example(Tuple data):

>>> ds = env.from_collection([('a', 1), ('a', 2), ('b', 1), ('b', 5)])
>>> ds.key_by(lambda x: x[0]).max_by(1)

Example(Row data):

>>> ds = env.from_collection([('a', 1), ('a', 2), ('a', 3), ('b', 1), ('b', 2)],
...                          type_info=Types.ROW([Types.STRING(), Types.INT()]))
>>> ds.key_by(lambda x: x[0]).max_by(1)

Example(Row data with fields name):

>>> ds = env.from_collection(
...     [('a', 1), ('a', 2), ('a', 3), ('b', 1), ('b', 2)],
...     type_info=Types.ROW_NAMED(["key", "value"], [Types.STRING(), Types.INT()])
... )
>>> ds.key_by(lambda x: x[0]).max_by("value")
Parameters:

position_to_max_by – The field position in the data points to maximize. The type can be int (field position) or str (field name). This is applicable to Tuple types, List types, Row types, and basic types (which is considered as having one field).

Returns:

The transformed DataStream.

Added in version 1.16.0.

previous

pyflink.datastream.data_stream.KeyedStream.min_by

next

pyflink.datastream.data_stream.KeyedStream.add_sink

On this page
  • KeyedStream.max_by()

This Page

  • Show Source

Created using Sphinx 7.4.7.

Built with the PyData Sphinx Theme 0.16.1.