标签:lin 分享 txt 16px nbsp strong 图片 reduce img
在 Spark Shell 实现 Word Count
RDD (Resilient Distributed dataset), 弹性分布式数据集。
1.1 分步实现
# step 1 加载文档 val rdd1 = sc.textFile("file:///home/centos/wc1.txt") # step 2 压扁 val rdd2 = rdd1.flatMap(line=>{line.split(" ")}) # step 3 标1成对 val rdd3 = rdd2.map(word=>{(word , 1)}) # step 4 聚合 val rdd4 = rdd3.reduceByKey((a:Int,b:Int)=>{a + b}) # step 5 rdd4.collect()
标签:lin 分享 txt 16px nbsp strong 图片 reduce img
原文地址:https://www.cnblogs.com/share23/p/9756419.html