rdd

7. RDD 窄依赖&宽依赖

我是研究僧i 提交于 2019-12-27 22:18:56
窄依赖和宽依赖 RDD之间 有一系列 的依赖关系 ,依赖关系又分为窄依赖和宽依赖。 窄依赖 ---- 减少或不变 父RDD和子RDD partition之间的关系是一对一的。或者父RDD和子RDD partition关系是多对一的。不会有shuffle的产生。 宽依赖 ---- 增多 父RDD与子RDD partition之间的关系是一对多。会 有shuffle的产生 。 宽窄依赖图理解 来源: CSDN 作者: BF-LoneSilverWind 链接: https://blog.csdn.net/digua930126/article/details/103738597

Spark笔记:RDD基本操作(上)

旧街凉风 提交于 2019-12-27 14:04:11
  本文主要是讲解spark里RDD的基础操作。RDD是spark特有的数据模型,谈到RDD就会提到什么弹性分布式数据集,什么有向无环图,本文暂时不去展开这些高深概念,在阅读本文时候,大家可以就把RDD当作一个数组,这样的理解对我们学习RDD的API是非常有帮助的。本文所有示例代码都是使用scala语言编写的。   Spark里的计算都是操作RDD进行,那么学习RDD的第一个问题就是如何构建RDD,构建RDD从数据来源角度分为两类:第一类是从内存里直接读取数据,第二类就是从文件系统里读取,当然这里的文件系统种类很多常见的就是HDFS以及本地文件系统了。   第一类方式从内存里构造RDD,使用的方法:makeRDD和parallelize方法,如下代码所示: /* 使用makeRDD创建RDD */ /* List */ val rdd01 = sc.makeRDD(List(1,2,3,4,5,6)) val r01 = rdd01.map { x => x * x } println(r01.collect().mkString(",")) /* Array */ val rdd02 = sc.makeRDD(Array(1,2,3,4,5,6)) val r02 = rdd02.filter { x => x < 5} println(r02.collect()

Scala实现wordcount

我怕爱的太早我们不能终老 提交于 2019-12-26 23:21:26
import org . apache . spark . rdd . RDD import org . apache . spark . { SparkConf , SparkContext } object WordCount { def main ( args : Array [ String ] ) : Unit = { val config : SparkConf = new SparkConf ( ) . setMaster ( "local[*]" ) . setAppName ( "WordCount" ) val sc = new SparkContext ( config ) // println(sc) val lines : RDD [ String ] = sc . textFile ( "in/word.txt" ) val words : RDD [ String ] = lines . flatMap ( x = > x . split ( " " ) ) val wordToOne : RDD [ ( String , Int ) ] = words . map ( x = > ( x , 1 ) ) val wordToSum : RDD [ ( String , Int ) ] = wordToOne . reduceByKey ( ( x ,

[spark]RDD合并

会有一股神秘感。 提交于 2019-12-26 17:23:58
将spark的两个rdd合并成一个rdd scala > val rdd1 = sc . parallelize ( 1 to 10 ) rdd1 : org . apache . spark . rdd . RDD [ Int ] = ParallelCollectionRDD [ 0 ] at parallelize at < console > : 24 scala > rdd1 . collect res0 : Array [ Int ] = Array ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ) scala > val rdd2 = sc . parallelize ( 101 to 110 ) rdd2 : org . apache . spark . rdd . RDD [ Int ] = ParallelCollectionRDD [ 1 ] at parallelize at < console > : 24 scala > rdd1 . collect res1 : Array [ Int ] = Array ( 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ) scala > val rdd3 = rdd1 . union ( rdd2 ) rdd3 : org . apache .

Spark RDD 概念以及核心原理

倖福魔咒の 提交于 2019-12-26 07:15:56
2、依赖关系下的数据流视图         在spark中,会根据RDD之间的依赖关系将DAG图划分为不同的阶段,对于窄依赖,由于partition依赖关系的确定性,partition的转换处理就可以在同一个线程里完成,窄依赖就被spark划分到同一个stage中,而对于宽依赖,只能等父RDD shuffle处理完成后,下一个stage才能开始接下来的计算。   因此spark划分stage的整体思路是:从后往前推,遇到宽依赖就断开,划分为一个stage;遇到窄依赖就将这个RDD加入该stage中。因此在图2中RDD C,RDD D,RDD E,RDDF被构建在一个stage中,RDD A被构建在一个单独的Stage中,而RDD B和RDD G又被构建在同一个stage中。   在spark中,Task的类型分为2种:ShuffleMapTask和ResultTask;   简单来说,DAG的最后一个阶段会为每个结果的partition生成一个ResultTask,即每个Stage里面的Task的数量是由该Stage中最后一个RDD的Partition的数量所决定的!而其余所有阶段都会生成ShuffleMapTask; 已经为大家精心准备了大数据的系统学习资料,从Linux-Hadoop-spark-......,需要的小伙伴可以点击

spark主要核心笔记

佐手、 提交于 2019-12-25 20:47:53
spark主要用来做数据的分析,必须要把分析的数据存放到rdd-----------弹性分布式数据集 弹性:可以随着work的变化而变化 分布式:同一个数据集在多台服务器中存放,每一台服务器只存放整个rdd的一部分,一般都是平均分配 rdd:就是一个集合/数组,这样来理解:看成一个数据库 数据集:数据的集合,很多很多的数据 rdd中有许多的分区,相当于数据库的表----数据存放在rdd的分区中 rdd中的数据是只读的,目前来说任何情况下都不能修改 rdd没有分区是无法存放数据的 一.创建rdd的方式“: 1.parallize,makerdd:参数是一个序列 parallize和makerdd的作用基本一致 2.通过读取一个文件创建rdd典型的textfile 3.通过其他的rdd来创建一个新的rdd rdd的传递性 二.rdd的操作,transformation和action统称为算子,算子说白了就是方法 transformation: 1.不会立即执行,直到遇到action,只是保存了要进行的操作, 2.都会创建一个新的rdd action: 1.会立即执行,这样的话就会迫使前面的所有的transformation执行,前面的所有的transformation执行完后action才会执行 2.一般action没有返回值,或者返回一个简单类型数据,肯定不会是rdd的 常用的算子:

Filtering out nested array entries in a DataFrame (JSON) by passing in a list of values to match against

只谈情不闲聊 提交于 2019-12-25 19:02:36
问题 I read in a DataFrame with a huge file holding on each line of it a JSON object as follows: { "userId": "12345", "vars": { "test_group": "group1", "brand": "xband" }, "modules": [ { "id": "New" }, { "id": "Default" }, { "id": "BestValue" }, { "id": "Rating" }, { "id": "DeliveryMin" }, { "id": "Distance" } ] } I would like to pass in to a method a list of module id-s and clear out all items, which don't make part of that list of module id-s. It should remove all other modules, which's id is

How to Sum a part of a list in RDD

自闭症网瘾萝莉.ら 提交于 2019-12-25 18:34:28
问题 I have an RDD, and I would like to sum a part of the list. (key, element2 + element3) (1, List(2.0, 3.0, 4.0, 5.0)), (2, List(1.0, -1.0, -2.0, -3.0)) output should look like this, (1, 7.0), (2, -3.0) Thanks 回答1: You can map and indexing on the second part: yourRddOfTuples.map(tuple => {val list = tuple._2; list(1) + list(2)}) Update after your comment, convert it to Vector : yourRddOfTuples.map(tuple => {val vs = tuple._2.toVector; vs(1) + vs(2)}) Or if you do not want to use conversions:

efficiently using union in spark

百般思念 提交于 2019-12-25 15:16:38
问题 I am new to scala and spark and now I have two RDD like A is [(1,2),(2,3)] and B is [(4,5),(5,6)] and I want to get RDD like [(1,2),(2,3),(4,5),(5,6)]. But thing is my data is large, suppose both A and B is 10GB. I use sc.union(A,B) but it is slow. I saw in spark UI there are 28308 tasks in this stage. Is there more efficient way to do this? 回答1: Why don't you convert the two RDDs to dataframes and use union function. Converting to dataframe is easy you just need to import sqlContext

efficiently using union in spark

和自甴很熟 提交于 2019-12-25 15:16:25
问题 I am new to scala and spark and now I have two RDD like A is [(1,2),(2,3)] and B is [(4,5),(5,6)] and I want to get RDD like [(1,2),(2,3),(4,5),(5,6)]. But thing is my data is large, suppose both A and B is 10GB. I use sc.union(A,B) but it is slow. I saw in spark UI there are 28308 tasks in this stage. Is there more efficient way to do this? 回答1: Why don't you convert the two RDDs to dataframes and use union function. Converting to dataframe is easy you just need to import sqlContext