本文簡要介紹 python 語言中 pyflink.datastream.KeyedStream.sum
的用法。
用法:
sum(position_to_sum: Union[int, str] = 0) → pyflink.datastream.data_stream.DataStream
應用一個聚合,該聚合給出在給定位置按給定鍵分組的數據流的滾動總和。每個鍵都保留一個獨立的聚合。
示例(要求和的元組數據):
>>> ds = env.from_collection([('a', 1), ('a', 2), ('b', 1), ('b', 5)]) >>> ds.key_by(lambda x: x[0]).sum(1)
示例(要匯總的行數據):
>>> 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]).sum(1)
示例(具有要匯總的字段名稱的行數據):
>>> 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]).sum("value")
參數:
position_to_sum - 數據中的字段位置指向求和,類型可以是int,表示要操作的列的索引或str,表示要操作的列的名稱。
返回:
轉換後的 DataStream。
版本 1.16.0 中的新函數。
相關用法
- Python pyflink KeyedStream.max用法及代碼示例
- Python pyflink KeyedStream.min用法及代碼示例
- Python pyflink KeyedStream.min_by用法及代碼示例
- Python pyflink KeyedStream.max_by用法及代碼示例
- Python pyflink KeyedStream.reduce用法及代碼示例
- 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 WatermarkStrategy.with_timestamp_assigner用法及代碼示例
- 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用法及代碼示例
注:本文由純淨天空篩選整理自apache.org大神的英文原創作品 pyflink.datastream.KeyedStream.sum。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。