rdd

How to share data from Spark RDD between two applications

▼魔方 西西 提交于 2019-12-01 06:55:02
问题 What is the best way to share spark RDD data between two spark jobs. I have a case where job 1: Spark Sliding window Streaming App, will be consuming data at regular intervals and creating RDD. This we do not want to persist to storage. Job 2: Query job that will access the same RDD created in job 1 and generate reports. I have seen few queries where they were suggesting SPARK Job Server, but as it is a open source not sure if it a possible solution, but any pointers will be of great help.

Check Type: How to check if something is a RDD or a dataframe?

笑着哭i 提交于 2019-12-01 06:29:21
I'm using python, and this is Spark Rdd/dataframes. I tried isinstance(thing, RDD) but RDD wasn't recognized. The reason I need to do this: I'm writing a function where both RDD and dataframes could be passed in, so I'll need to do input.rdd to get the underlying rdd if a dataframe is passed in. isinstance will work just fine: from pyspark.sql import DataFrame from pyspark.rdd import RDD def foo(x): if isinstance(x, RDD): return "RDD" if isinstance(x, DataFrame): return "DataFrame" foo(sc.parallelize([])) ## 'RDD' foo(sc.parallelize([("foo", 1)]).toDF()) ## 'DataFrame' but single dispatch is

If the one partition is lost, we can use lineage to reconstruct it. Will the base RDD be loaded again?

本秂侑毒 提交于 2019-12-01 05:49:19
I read the paper "Resilient Distributed Datasets A Fault-Tolerant Abstraction for In-Memory Cluster Computing". The author said that if the one partition is lost, we can use lineage to reconstruct it. However, the origin RDD didn't exist in memory now. So will the base RDD be loaded again to rebuild the lost RDD partition? Yes, as you mentioned if the RDD that was used to create the partition is not in memory anymore it has to be loaded again from disk and recomputed. If the original RDD that was used to create your current partition also isn't there (neither in memory or on disk) then Spark

小记---------sparkRDD的Transformation 和 Action

僤鯓⒐⒋嵵緔 提交于 2019-12-01 05:33:07
RDD :弹性分布式数据集;是一个容错的、并行的数据结构,可以让用户显式地将数据存储到磁盘或内存中,并控制数据的分区 RDD是Spark的核心数据结构,通过RDD的依赖关系形成Spark的调度顺序。所谓Spark应用程序,本质是一组对RDD的操作 RDD的两种创建方式 从文件系统输入(如HDFS)创建 从已存在的RDD转换得到新的RDD RDD的两种操作算子 Transformation(变换)Transformation类型的算子不是立刻执行,而是延迟执行。也就是说从一个RDD变换为另一个RDD的操作需要等到Action操作触发时,才会真正执行。 ·Action(行动)Action类型的算子会触发Spark提交作业,并将数据输出到Spark系统。 Transformation Transformation(转换) Meaning(含义) map(func) 返回一个新的 distributed dataset(分布式数据集),它由每个 source(数据源)中的元素应用一个函数 func 来生成. 一对一的关系 filter(func) 返回一个新的 distributed dataset(分布式数据集),它由每个 source(数据源)中应用一个函数 func 且返回值为 true 的元素来生成. 过滤器(使用之后会过滤掉你不想要的) flatMap(func) 与 map

value reduceByKey is not a member of org.apache.spark.rdd.RDD

点点圈 提交于 2019-12-01 05:14:40
It's very sad.My spark version is 2.1.1,Scala version is 2.11 import org.apache.spark.SparkContext._ import com.mufu.wcsa.component.dimension.{DimensionKey, KeyTrait} import com.mufu.wcsa.log.LogRecord import org.apache.spark.rdd.RDD object PV { // def stat[C <: LogRecord,K <:DimensionKey](statTrait: KeyTrait[C ,K],logRecords: RDD[C]): RDD[(K,Int)] = { val t = logRecords.map(record =>(statTrait.getKey(record),1)).reduceByKey((x,y) => x + y) I got this error at 1502387780429 [ERROR] /Users/lemanli/work/project/newcma/wcsa/wcsa_my/wcsavistor/src/main/scala/com/mufu/wcsa/component/stat/PV.scala

spark每日进步

别来无恙 提交于 2019-12-01 05:07:34
写wiki感觉不太好,直接写个人博客。其中掺杂了太多个人理解,不保证正确性。但是感觉网上的都是官样文章,而且都是抄来抄去,真真叫没意思。 新手村 推荐一个 极好的博客 ,最好是一边看能够一遍动手验证,看看scala的函数是怎样转化成不同的stage和task的,看看spark-sql是怎么划分的,理解比较深入 相关原理 job划分和stage划分 凡是有action的地方会划分为一个job,个人理解action就是一种”落地“,之前做的所有计算都只是生成dag,都是空中楼阁,没有真正进行计算,而action会真正得到一个结果,真正的scala的数据结构array,可以进行普通的非spark的计算 宽依赖和窄依赖 凡是遇到shuffleDependency都会划分为两个stage,shuffleDependency大白话讲就是要计算下一个rdd的任何一个partition,都必须把上一个rdd的所有partition都计算出来,这个时候把两个rdd划分在同一个stage是不合适的,因为必须先把上一个rdd完全计算出来以后才能进行下一步的计算,所以就不必计较分区了。 所谓划分在一个stage,就是说下一个rdd的分区永远只依赖上一个rdd的部分分区,所以一直往前推,最后一个rdd的分区都只依赖这一个stage最早的rdd的部分分区,所以可以按照这个依赖关系

Check Type: How to check if something is a RDD or a dataframe?

江枫思渺然 提交于 2019-12-01 04:56:56
问题 I'm using python, and this is Spark Rdd/dataframes. I tried isinstance(thing, RDD) but RDD wasn't recognized. The reason I need to do this: I'm writing a function where both RDD and dataframes could be passed in, so I'll need to do input.rdd to get the underlying rdd if a dataframe is passed in. 回答1: isinstance will work just fine: from pyspark.sql import DataFrame from pyspark.rdd import RDD def foo(x): if isinstance(x, RDD): return "RDD" if isinstance(x, DataFrame): return "DataFrame" foo

Converting RDD[org.apache.spark.sql.Row] to RDD[org.apache.spark.mllib.linalg.Vector]

无人久伴 提交于 2019-12-01 03:47:41
I am relatively new to Spark and Scala. I am starting with the following dataframe (single column made out of a dense Vector of Doubles): scala> val scaledDataOnly_pruned = scaledDataOnly.select("features") scaledDataOnly_pruned: org.apache.spark.sql.DataFrame = [features: vector] scala> scaledDataOnly_pruned.show(5) +--------------------+ | features| +--------------------+ |[-0.0948337274182...| |[-0.0948337274182...| |[-0.0948337274182...| |[-0.0948337274182...| |[-0.0948337274182...| +--------------------+ A straight conversion to RDD yields an instance of org.apache.spark.rdd.RDD[org

Spark reading python3 pickle as input

自闭症网瘾萝莉.ら 提交于 2019-12-01 03:45:35
My data are available as sets of Python 3 pickled files. Most of them are serialization of Pandas DataFrames . I'd like to start using Spark because I need more memory and CPU that one computer can have. Also, I'll use HDFS for distributed storage. As a beginner, I didn't found relevant information explaining how to use pickle files as input file. Does it exists? If not, are there any workaround? Thanks a lot A lot depends on the data itself. Generally speaking Spark doesn't perform particularly well when it has to read large, not splittable files. Nevertheless you can try to use binaryFiles

value reduceByKey is not a member of org.apache.spark.rdd.RDD

烂漫一生 提交于 2019-12-01 02:37:19
问题 It's very sad.My spark version is 2.1.1,Scala version is 2.11 import org.apache.spark.SparkContext._ import com.mufu.wcsa.component.dimension.{DimensionKey, KeyTrait} import com.mufu.wcsa.log.LogRecord import org.apache.spark.rdd.RDD object PV { // def stat[C <: LogRecord,K <:DimensionKey](statTrait: KeyTrait[C ,K],logRecords: RDD[C]): RDD[(K,Int)] = { val t = logRecords.map(record =>(statTrait.getKey(record),1)).reduceByKey((x,y) => x + y) I got this error at 1502387780429 [ERROR] /Users