tonglin0325的个人主页

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

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

Ref

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

  1. 实现 MapFunction接口
1
2
3
4
5
class MyMapFunction implements MapFunction<String, Integer> {
public Integer map(String value) { return Integer.parseInt(value); }
};
data.map(new MyMapFunction());

  1. 继承 RichMapFunction
1
2
3
4
class MyMapFunction extends RichMapFunction<String, Integer> {
public Integer map(String value) { return Integer.parseInt(value); }
};

 

累加器和计数器

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

1
2
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