Flink学习笔记——用户自定义Functions

Flink支持用户自定义 Functions,方法有2个

Ref

https://ci.apache.org/projects/flink/flink-docs-release-1.12/zh/dev/user_defined_functions.html

1. 实现 MapFunction接口

class MyMapFunction implements MapFunction<String, Integer> {
  public Integer map(String value) { return Integer.parseInt(value); }
};
data.map(new MyMapFunction());

2. 继承 RichMapFunction

class MyMapFunction extends RichMapFunction<String, Integer> {
  public Integer map(String value) { return Integer.parseInt(value); }
};

 

累加器和计数器

这个应该和Hadoop和Spark的counter类似,参考

https://ci.apache.org/projects/flink/flink-docs-release-1.12/zh/dev/user_defined_functions.html#%E7%B4%AF%E5%8A%A0%E5%99%A8%E5%92%8C%E8%AE%A1%E6%95%B0%E5%99%A8

  

posted @ 2020-12-16 17:28  tonglin0325  阅读(377)  评论(0编辑  收藏  举报