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 方法分析:
forech
测试数据:
9 8
8 3
8 3
9 8
hadoop
spark
flume
spark
hadoop
hadoop
redis
spark
redis
redis
作业:动手画出Spark RDD TrasFormation 的图
(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 的图
相关文章推荐
- MVC————添加视图时没有模型可用
- 腾讯视频真实下载地址获取教程(一段代码即可搞定)
- 产品经理和程序员的爱恨情仇
- 细说产品经理
- EXCEL所有单元格加减乘除一个数 -- 选择性粘贴的用法
- Linux入门常用指令
- *[Lintcode]O(1) Check Power of 2
- Substring with Concatenation of All Words
- [python爬虫] Selenium爬取新浪微博内容及用户信息
- 悲观的人更容易获得好的感觉
- [Lintcode]Number of Islands
- 黑客教程
- 51Nod 1163 最高的奖励(贪心+优先队列/并查集合)
- [Lintcode]Nth to Last Node in List
- PyCUDA 学习笔记 -- pagelocked memory
- *[Lintcode]Minimum Subarray
- json字符串和json对象异同和互相转换
- 品牌人格的树立
- Struts2 pojo类中包含Date类型属性使用自定类型转换器
- 心理的疼痛和肉体的疼痛可能共享同一个神经