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

以下内容整理来源于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 的图


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值