当前位置:   article > 正文

Flink 累加器 实例_flink map获取累加值

flink map获取累加值

每个并行的任务实例下有各自的累加器,获取最终值时会把各个并行任务的累加器的值求和。(一个并行度对应一个累加器)

版本: flink1.9.2    java1.8

map并行度1:

  1. package Counter;
  2. import org.apache.flink.api.common.JobExecutionResult;
  3. import org.apache.flink.api.common.accumulators.IntCounter;
  4. import org.apache.flink.api.common.functions.RichMapFunction;
  5. import org.apache.flink.configuration.Configuration;
  6. import org.apache.flink.streaming.api.datastream.DataStream;
  7. import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
  8. /**
  9. * @Author you guess
  10. * @Date 2020/6/25 12:30
  11. * @Version 1.0
  12. * @Desc
  13. */
  14. public class CounterTest1 {
  15. public static void main(String[] args) throws Exception {
  16. //获取执行环境
  17. final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
  18. //数据来源
  19. DataStream<String> source1 = env.fromElements("a", "b&#
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/696193
推荐阅读
相关标签
  

闽ICP备14008679号