您的位置:首页 > 其它

day16:RDD实战(RDD基本操作实战及Transformation流程图)

2016-02-23 06:42 531 查看
以下内容整理来源于DT大数据梦工厂:http://weibo.com/ilovepains

(f : T => U) 函数参数为f, 函数类型是T, 返回类型是 U

实现统计文件里面数据总和

object FileTextLines {
def main (args: Array[String]) {
val conf = new SparkConf()
conf.setAppName("name count").setMaster("local")
val sc = new SparkContext(conf)
val datas = sc.textFile("D://googledown//datas.txt")
val linedatas = datas.map(lines => (lines, 1))
val pairsDatas = linedatas.reduceByKey(_+_)
pairsDatas.collect.foreach(ds => println(ds._1 + "...."+ ds._2))
}
}collect 方法分析:

/**
* Return an array that contains all of the elements in this RDD.
*/
def collect(): Array[T] = withScope {
val results = sc.runJob(this, (iter: Iterator[T]) => iter.toArray)
Array.concat(results: _*)
}

forech

override def foreach[U](f : scala.Function1[A, U]) : scala.Unit = { /* compiled code */ }


测试数据:

9 8

8 3

8 3

9 8

 hadoop 

 spark

 flume

 spark 

 hadoop 

 hadoop 

 redis

 spark

 redis

 redis

作业:动手画出Spark RDD TrasFormation 的图
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: