rdd

Understanding treeReduce() in Spark

情到浓时终转凉″ 提交于 2019-11-28 03:42:52
问题 You can see the implementation here: https://github.com/apache/spark/blob/ffa05c84fe75663fc33f3d954d1cb1e084ab3280/python/pyspark/rdd.py#L804 How does it different from the 'normal' reduce function? What does it mean depth = 2 ? I don't want that the reducer function will pass linearly on the partitions, but reduce each available pairs first, and then will iterate like that until i have only one pair and reduce it to 1, as shown in the picture: Does treeReduce achieve that? 回答1: Standard

第二天入职

时光怂恿深爱的人放手 提交于 2019-11-28 03:18:16
2019/8/20 10:11 我收回我昨天说很闲的话,昨天可是把我累死了,今天早上终于搞出来了,使用的是rdd和集合,rdd的每一项并发去匹配,集合中的hash中的集合的每一项 如果存在就将hash中的key给rdd的每一项 之后返回了一个utils我觉得很有趣,现在我想做的就是把目前的utils更新到mysql数据库中。但是我太高兴了,我就找他给 我安排任务,有点后悔,他让我 导入excel的表格里的数据到mysql里(我打算使用kettle,第二次用,很好用),另外,继续做与刚才同样的操作。 所以我给自己上午定了个目标,就是把数据写好,更新到mysql中并且弄张新表出来,新表就是我刚刚映射完成的数据。 最后搞了一下午,搞定了。 有个问题就是,while中,可以用scala的集合添加数据 但是在spark的rdd的foreach里添加的数据都会被无效化。 所以有2种解决方案,1.使用map           2.使用while 来源: https://www.cnblogs.com/BigDataBugKing/p/11381391.html

reduceByKey method not being found in Scala Spark

喜你入骨 提交于 2019-11-28 02:27:07
问题 Attempting to run http://spark.apache.org/docs/latest/quick-start.html#a-standalone-app-in-scala from source. This line: val wordCounts = textFile.flatMap(line => line.split(" ")).map(word => (word, 1)).reduceByKey((a, b) => a + b) is throwing error value reduceByKey is not a member of org.apache.spark.rdd.RDD[(String, Int)] val wordCounts = logData.flatMap(line => line.split(" ")).map(word => (word, 1)).reduceByKey((a, b) => a + b) logData.flatMap(line => line.split(" ")).map(word => (word,

【spark】SparkSession的API

泪湿孤枕 提交于 2019-11-28 01:56:12
SparkSession是一个比较重要的类,它的功能的实现,肯定包含比较多的函数,这里介绍下它包含哪些函数。 builder函数 public static SparkSession.Builder builder() 创建 SparkSession.Builder,初始化SparkSession. setActiveSession函数 public static void setActiveSession(SparkSession session) 当SparkSession.GetOrCreate()被调用,SparkSession发生变化,将会返回一个线程和它的子线程。这将会确定给定的线程接受带有隔离会话的SparkSession,而不是全局的context。 clearActiveSession函数 public static void clearActiveSession() 清除当前线程的Active SparkSession。然后调用GetOrCreate将会返回第一次创建的context代替本地线程重写 setDefaultSession函数 public static void setDefaultSession(SparkSession session) 设置默认的SparkSession,返回builder clearDefaultSession函数

Spark fastest way for creating RDD of numpy arrays

人走茶凉 提交于 2019-11-28 01:51:37
问题 My spark application is using RDD's of numpy arrays. At the moment, I'm reading my data from AWS S3, and its represented as a simple text file where each line is a vector and each element is seperated by space, for example: 1 2 3 5.1 3.6 2.1 3 0.24 1.333 I'm using numpy's function loadtxt() in order to create a numpy array from it. However, this method seems to be very slow and my app is spending too much time(I think) for converting my dataset to a numpy array. Can you suggest me a better

Serializing RDD

人盡茶涼 提交于 2019-11-28 01:29:23
I have an RDD which I am trying to serialize and then reconstruct by deserializing. I am trying to see if this is possible in Apache Spark. static JavaSparkContext sc = new JavaSparkContext(conf); static SerializerInstance si = SparkEnv.get().closureSerializer().newInstance(); static ClassTag<JavaRDD<String>> tag = scala.reflect.ClassTag$.MODULE$.apply(JavaRDD.class); .. .. JavaRDD<String> rdd = sc.textFile(logFile, 4); System.out.println("Element 1 " + rdd.first()); ByteBuffer bb= si.serialize(rdd, tag); JavaRDD<String> rdd2 = si.deserialize(bb, Thread.currentThread().getContextClassLoader()

pyspark: 'PipelinedRDD' object is not iterable

雨燕双飞 提交于 2019-11-28 01:18:45
问题 I am getting this error but i do not know why. Basically I am erroring from this code: a = data.mapPartitions(helper(locations)) where data is an RDD and my helper is defined as: def helper(iterator, locations): for x in iterator: c = locations[x] yield c (locations is just an array of data points) I do not see what the problem is but I am also not the best at pyspark so can someone please tell me why I am getting 'PipelinedRDD' object is not iterable from this code? 回答1: RDD can iterated by

Spark when union a lot of RDD throws stack overflow error

Deadly 提交于 2019-11-28 00:44:33
When I use "++" to combine a lot of RDDs, I got error stack over flow error. Spark version 1.3.1 Environment: yarn-client. --driver-memory 8G The number of RDDs is more than 4000. Each RDD is read from a text file with size of 1 GB. It is generated in this way val collection = (for ( path <- files ) yield sc.textFile(path)).reduce(_ union _) It works fine when files has small size. And there is the error The error repeats itself. I guess it is a recursion function which is called too many time? Exception at org.apache.spark.rdd.RDD.partitions(RDD.scala:217) at org.apache.spark.rdd.UnionRDD$

Is it possible to create nested RDDs in Apache Spark?

别来无恙 提交于 2019-11-28 00:28:01
I am trying to implement K-nearest neighbor algorithm in Spark. I was wondering if it is possible to work with nested RDD's. This will make my life a lot easier. Consider the following code snippet. public static void main (String[] args){ //blah blah code JavaRDD<Double> temp1 = testData.map( new Function<Vector,Double>(){ public Double call(final Vector z) throws Exception{ JavaRDD<Double> temp2 = trainData.map( new Function<Vector, Double>() { public Double call(Vector vector) throws Exception { return (double) vector.length(); } } ); return (double)z.length(); } } ); } Currently I am

Apache Spark RDD filter into two RDDs

大憨熊 提交于 2019-11-27 23:32:01
I need to split an RDD into 2 parts: 1 part which satisfies a condition; another part which does not. I can do filter twice on the original RDD but it seems inefficient. Is there a way that can do what I'm after? I can't find anything in the API nor in the literature. Marius Soutier Spark doesn't support this by default. Filtering on the same data twice isn't that bad if you cache it beforehand, and the filtering itself is quick. If it's really just two different types, you can use a helper method: implicit class RDDOps[T](rdd: RDD[T]) { def partitionBy(f: T => Boolean): (RDD[T], RDD[T]) = {