标签:apr 测试的 master ram top string arp ref main
初识 Spark 大数据处理,目前还只是小白阶段,初步搭建起运行环境,慢慢学习之。
本文熟悉下 Spark 数据处理的几个经典案例。
import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
object WordCount {
def main(args: Array[String]) {
if (args.length < 1) {
System.err.println("Usage: <file>")
System.exit(1)
}
// 创建 SparkConf
val conf = new SparkConf()
conf.setAppName("WordCount")
.setMaster("local[2]")
// 创建 SparkContext
val sc = new SparkContext(conf)
// 数据处理
val line = sc.textFile(args(0))
line.flatMap(_.split("\\s+"))
.map((_, 1))
.reduceByKey(_+_)
.collect.foreach(println)
// 关闭 SparkContext
sc.stop
}
}
注意其中的几个问题:
参考:
标签:apr 测试的 master ram top string arp ref main
原文地址:http://www.cnblogs.com/wjcx-sqh/p/6675293.html