Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache spark 不正确的RDD转换_Apache Spark_Pyspark - Fatal编程技术网

Apache spark 不正确的RDD转换

Apache spark 不正确的RDD转换,apache-spark,pyspark,Apache Spark,Pyspark,我无法重新使用通过mapPartition生成的新RDD。只有在mapPartition之后添加reduceByKey转换时,代码似乎才能正常工作(我不想执行reduceByKey)。由于reduceByKey和mapParition都是转换,我不确定是什么导致了错误 C = [x for x in xrange(2**20)] C = sc.parallelize(C) while True: C = C.repartition(1000)\ .mapPartition

我无法重新使用通过mapPartition生成的新RDD。只有在mapPartition之后添加
reduceByKey
转换时,代码似乎才能正常工作(我不想执行
reduceByKey
)。由于
reduceByKey
mapParition
都是转换,我不确定是什么导致了错误

C = [x for x in xrange(2**20)]
C = sc.parallelize(C)
while True:
    C = C.repartition(1000)\
        .mapPartitions(foo)\
        .persist()

    if C.take(1) == 0 :
        break
报告的错误:

TypeError: can't pickle listiterator objects

这个错误是由于您从mapPartitions返回的内容造成的,我相信这是正确的。如果返回新的RDD,我看不出代码引发异常的原因。下面是我使用您的代码开发的代码片段

def f(it):
    s = 0
    l = 0

    for x in it:
        s += x
        l += 1
        if l > 1:
             yield s

C = sc.parallelize([x for x in range(100)])

while True:
      C = C.repartition(10)\
          .mapPartitions(f)
      if C.isEmpty():
          break

最好使用
isEmpty()
over
take(1)
检查RDD是否为空

尝试range而不是xrange。Xrange生成生成器
C=[x代表范围内的x(2**20)]
,同时使用while true循环进行重新分区是非常糟糕的编码。@在此类应用中,Pushkr Xrange比range更受欢迎是的,但仅在python2中,python3范围与Xrange相同。对于并行化,您需要的是实际的列表,而不是生成器。