本文簡要介紹 python 語言中 pyflink.table.GroupedTable.flat_aggregate
的用法。
用法:
flat_aggregate(func: Union[pyflink.table.expression.Expression, pyflink.table.udf.UserDefinedAggregateFunctionWrapper]) → pyflink.table.table.FlatAggregateTable
對分組表執行flat_aggregate操作。 flat_aggregate 采用返回多行的
TableAggregateFunction
。在 flatAggregate 之後使用選擇。例子:
>>> table_agg = udtaf(MyTableAggregateFunction()) >>> tab.group_by(tab.c).flat_aggregate(table_agg(tab.a).alias("a")).select( ... col('c'), col('a')) >>> # take all the columns as inputs >>> class Top2(TableAggregateFunction): ... def emit_value(self, accumulator): ... yield Row(accumulator[0]) ... yield Row(accumulator[1]) ... ... def create_accumulator(self): ... return [None, None] ... ... def accumulate(self, accumulator, *args): ... args[0] # type: Row ... if args[0][0] is not None: ... if accumulator[0] is None or args[0][0] > accumulator[0]: ... accumulator[1] = accumulator[0] ... accumulator[0] = args[0][0] ... elif accumulator[1] is None or args[0][0] > accumulator[1]: ... accumulator[1] = args[0][0] ... ... def get_accumulator_type(self): ... return DataTypes.ARRAY(DataTypes.BIGINT()) ... ... def get_result_type(self): ... return DataTypes.ROW( ... [DataTypes.FIELD("a", DataTypes.BIGINT())]) >>> top2 = udtaf(Top2()) >>> tab.group_by(tab.c).flat_aggregate(top2.alias("a", "b")).select(col('a'), col('b'))
參數:
func- 用戶定義的表聚合函數。
返回:
結果表。
版本 1.13.0 中的新函數。
相關用法
- Python pyflink GroupedTable.select用法及代碼示例
- Python pyflink GroupedTable.aggregate用法及代碼示例
- Python pyflink GroupWindowedTable.group_by用法及代碼示例
- Python pyflink Table.intersect_all用法及代碼示例
- 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用法及代碼示例
- Python pyflink Table.execute用法及代碼示例
- Python pyflink StreamExecutionEnvironment.set_restart_strategy用法及代碼示例
- Python pyflink range_用法及代碼示例
注:本文由純淨天空篩選整理自apache.org大神的英文原創作品 pyflink.table.GroupedTable.flat_aggregate。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。