Flink实现WordCount
来源:互联网 发布:java写入txt文件 编辑:程序博客网 时间:2024/06/08 19:38
import org.apache.flink.api.common.functions.FlatMapFunction;import org.apache.flink.api.java.DataSet;import org.apache.flink.api.java.ExecutionEnvironment;import org.apache.flink.api.java.tuple.Tuple2;import org.apache.flink.util.Collector;public class WordCount { public static void main(String[] args) throws Exception { final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment(); DataSet<String> text = env.fromElements("To be, or not to be,--that is the question:--", "Whether 'tis nobler in the mind to suffer", "The slings and arrows of outrageous fortune", "Or to take arms against a sea of troubles,"); DataSet<Tuple2<String, Integer>> counts = text.flatMap(new FlatMapFunction<String, Tuple2<String, Integer>>() { @Override public void flatMap(String s, Collector<Tuple2<String, Integer>> collector) throws Exception { String[] tokens = s.toLowerCase().split("\\s+"); for (String token : tokens) { if (token.length() > 0) { collector.collect(new Tuple2<String, Integer>(token, 1)); } } } }).groupBy(0).sum(1); counts.print(); }}
0 0
- Flink实现WordCount
- Flink WordCount实例讲解
- Flink学习笔记 --- scala实现Flink的DataSet Source进行WordCount
- Flink学习笔记 --- 理解DataStream WordCount
- Flink学习笔记 --- 理解DataSet WordCount
- Flink sql的实现
- Flink
- RHadoop实现wordcount
- 用scala实现wordcount
- Scala实现WordCount功能
- MapReduce实现WordCount
- Hive实现wordCount程序
- python实现wordcount程序
- scala 实现WordCount
- scala实现wordcount
- Windows7下实现wordcount
- Eclipse实现Hadoop WordCount
- awk脚本实现wordcount
- Android动画-View动画的使用场景
- lua之基本函数
- 实现web启动时加载指定方法
- 【OpenGL】OpenGL系列——07帧缓存操作
- 学习Javascript闭包(Closure)
- Flink实现WordCount
- 归并排序
- 多线程基础部分小结
- 笔试面试算法经典--数组partition调整使数组的左部分单调有序
- 使用java理解程序逻辑第十一章
- UVA11582 Colossal Fibonacci
- Android异步----重新认识Android(6)
- 【OpenGL】OpenGL系列——08绘制曲面与查询函数
- git制作和提交patch