本文簡要介紹 python 語言中 pyflink.datastream.WindowedStream.aggregate
的用法。
用法:
aggregate(aggregate_function: pyflink.datastream.functions.AggregateFunction, window_function: Union[pyflink.datastream.functions.WindowFunction, pyflink.datastream.functions.ProcessWindowFunction] = None, accumulator_type: pyflink.common.typeinfo.TypeInformation = None, output_type: pyflink.common.typeinfo.TypeInformation = None) → pyflink.datastream.data_stream.DataStream
將給定的窗口函數應用於每個窗口。每次對每個鍵的窗口進行評估時,都會調用窗口函數。窗口函數的輸出被解釋為常規的非窗口流。
使用給定的聚合函數對到達的數據進行增量聚合。這意味著窗口函數在調用時通常隻有一個值要處理。
例子:
>>> class AverageAggregate(AggregateFunction): ... def create_accumulator(self) -> Tuple[int, int]: ... return 0, 0 ... ... def add(self, value: Tuple[str, int], accumulator: Tuple[int, int]) \ ... -> Tuple[int, int]: ... return accumulator[0] + value[1], accumulator[1] + 1 ... ... def get_result(self, accumulator: Tuple[int, int]) -> float: ... return accumulator[0] / accumulator[1] ... ... def merge(self, a: Tuple[int, int], b: Tuple[int, int]) -> Tuple[int, int]: ... return a[0] + b[0], a[1] + b[1] >>> ds.key_by(lambda x: x[1]) \ ... .window(TumblingEventTimeWindows.of(Time.seconds(5))) \ ... .aggregate(AverageAggregate(), ... accumulator_type=Types.TUPLE([Types.LONG(), Types.LONG()]), ... output_type=Types.DOUBLE())
參數:
aggregate_function- 用於增量聚合的聚合函數。
window_function- 窗口函數。
accumulator_type- 聚合函數的內部累加器類型的類型信息。
output_type- 窗口函數的結果類型的類型信息。
返回:
將窗口函數應用於窗口的結果的數據流。
版本 1.16.0 中的新函數。
相關用法
- Python pyflink WindowedStream.reduce用法及代碼示例
- Python pyflink WindowedStream.side_output_late_data用法及代碼示例
- Python pyflink WindowGroupedTable.aggregate用法及代碼示例
- Python pyflink WindowGroupedTable.select用法及代碼示例
- Python pyflink WatermarkStrategy.with_timestamp_assigner用法及代碼示例
- Python pyflink Table.intersect_all用法及代碼示例
- Python pyflink GroupedTable.select用法及代碼示例
- Python pyflink StreamTableEnvironment.from_data_stream用法及代碼示例
- Python pyflink Expression.to_date用法及代碼示例
- Python pyflink Table.fetch用法及代碼示例
- Python pyflink PulsarSourceBuilder用法及代碼示例
- Python pyflink TableEnvironment.create_temporary_function用法及代碼示例
- Python pyflink Table.right_outer_join用法及代碼示例
- Python pyflink Expression.json_value用法及代碼示例
- Python pyflink Table.distinct用法及代碼示例
- Python pyflink TableEnvironment.register_table_source用法及代碼示例
- Python pyflink Table.where用法及代碼示例
- Python pyflink Expression.end用法及代碼示例
- Python pyflink lit用法及代碼示例
- Python pyflink TableEnvironment.create_java_temporary_function用法及代碼示例
- Python pyflink Row.as_dict用法及代碼示例
- Python pyflink StreamTableEnvironment.create用法及代碼示例
- Python pyflink Table.drop_columns用法及代碼示例
- Python pyflink Expression.over用法及代碼示例
- Python pyflink Table.execute用法及代碼示例
注:本文由純淨天空篩選整理自apache.org大神的英文原創作品 pyflink.datastream.WindowedStream.aggregate。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。