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

  

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章