val sc = new SparkContext(arg(0),"WordCount", System.getenv("SPARK_HOME"),Seq(System.getenv("SPARK_TEST_JAR")))
val textFile=sc.textFile(arg(1))
val input FormatClass = classOf(SequenceFileInputFormat[text,text]]
var hadoopRdd=sc.hadoopRDD(conf,inputFormatClass, classOf[text],classOf[text])
val textFile=sc.textFile(arg(1))
val input FormatClass = classOf(SequenceFileInputFormat[text,text]]
var hadoopRdd=sc.hadoopRDD(conf,inputFormatClass, classOf[text],classOf[text])
val result = hadoopRdd.flatMap{case(key,value) => value.toString().split("\\s+");}.map(word => (word,1)).reduceByKey(_+_)
Spark 机器学习的数据集:
http://www.csie.ntu.edu.tw/~cjlin/libsvmtools/datasets/
本文介绍如何使用 Apache Spark 实现 WordCount 程序,并展示了关键代码片段。通过使用 SparkContext 和 RDD 操作来处理文本文件,实现了单词计数的功能。
1474

被折叠的 条评论
为什么被折叠?



