Flink使用MapFunction实现类编程
得到一个新的数据流: 新的流的元素是原来流的元素的平方
package com.mischen.it;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
/**
* @ClassName Flink01_TransForm_Map_Anonymous
* @Description 得到一个新的数据流: 新的流的元素是原来流的元素的平方
* @Author mischen
* @Date 2021/6/29 0029 9:36
* @Version 1.0
**/
public class Flink01_TransForm_Map_Anonymous {
public static void main(String[] args) throws Exception {
StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
env
.fromElements(4, 2, 3, 12, 16,8,1,6,90,14,17,4,9)
.map(new MapFunction<Integer, Integer>() {
@Override
public Integer map(Integer value) throws Exception {
return value * value;
}
})
.print();
env.execute();
}
}
运行结果:
上一篇:
JS实现多线程数据分片下载
