Flink实例(三十四):状态管理(五)自定义键控状态(四)ReducingState与AggregatingState

ReducingStateAggregatingState在注册StateDescriptor时,还需要实现一个ReduceFunctionAggregationFunction。下面的代码注册ReducingStateDescriptor时实现一个YourReduceFunctionYourReduceFunction实现了ReduceFunction。我们在ReducingState中使用add(in: T)方法向状态里增加一个元素,新元素和状态中已有数据通过ReduceFunction两两聚合。AggregatingState的使用方法与之类似。

val reducingStateDescriptor = new ReducingStateDescriptor[UserBehavior]("reducing", new YourReduceFunction, classOf[UserBehavior])

本文来自博客园,作者:秋华,转载请注明原文链接:https://www.cnblogs.com/qiu-hua/p/13794960.html

原文地址:https://www.cnblogs.com/qiu-hua/p/13794960.html