spark1.6从hdfs上读取文件运行wordcount

来源:互联网 发布:17年10美国非农数据 编辑:程序博客网 时间:2024/05/29 14:57

从hdfs上读取文件并运行wordcount

[root@hadoop14 app]# hadoop fs -put word.txt /yuhui



scala> val file=sc.textFile("hdfs://hadoop14:9000/yuhui/word.txt")


scala> val count=file.flatMap(line => line.split(" ")).map(word => (word,1)).reduceByKey(_+_)

scala> count.collect()

结果:

res1: Array[(String, Int)] = Array((cccc,2), (aaaa,2), (bbb,2), (ddd,1))


0 0
原创粉丝点击