Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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
Pyspark TypeError:类型为'的对象;管道DRDD';没有len()_Pyspark - Fatal编程技术网

Pyspark TypeError:类型为'的对象;管道DRDD';没有len()

Pyspark TypeError:类型为'的对象;管道DRDD';没有len(),pyspark,Pyspark,各位!!我在spark中运行python代码时遇到此错误日志 代码: main.py sc = SparkContext(appName="newsCluster") sc.addPyFile("/home/warrior/gitDir/pysparkCode/clusterNews/wordSeg.py") sc.addPyFile("/home/warrior/gitDir/pysparkCode/clusterNews/sparkClusterAlgorithm.py") wordseg

各位!!我在spark中运行python代码时遇到此错误日志

代码:

main.py

sc = SparkContext(appName="newsCluster")
sc.addPyFile("/home/warrior/gitDir/pysparkCode/clusterNews/wordSeg.py")
sc.addPyFile("/home/warrior/gitDir/pysparkCode/clusterNews/sparkClusterAlgorithm.py")
wordseg = wordSeg()
clustermanage = sparkClusterAlgorithm()
files = sc.wholeTextFiles("hdfs://warrior:9000/testData/skynews")
file_list = files.map(lambda item: item[1])
file_wc_dict_list = file_list.map(lambda file_content:wordseg.GetWordCountTable(file_content))
file_wc_dict_list.persist()
all_word_dict = wordseg.updateAllWordList(file_wc_dict_list)
wordSeg.py

def updateAllWordList(self, newWordCountDictList):
    '''
        description: input an new file then update the all word list
        input:
            newWordCountDict: new input string word count dict
        output:
            all_word_dict
    '''
    n = len(newWordCountDictList)
    all_word_list = []
    all_word_dict = {}
    for i in range(0,n):
        all_word_list = list(set(all_word_list + newWordCountDictList[i].keys()))
    for i in range(0,len(all_word_list)):
        all_word_dict[all_word_list[i]]=0
    return all_word_dict
。。。。。。。

当spark submitmain.py 输出错误日志:

Traceback (most recent call last):                                              
File "/home/warrior/gitDir/pysparkCode/clusterNews/__main__.py", line 31, in <module>
  all_word_dict =     wordseg.updateAllWordList(file_wc_dict_list)#file_wc_dict_list.map(lambda     file_wc_dict:wordseg.updateAllWordList(file_wc_dict))
File "/home/warrior/gitDir/pysparkCode/clusterNews/wordSeg.py", line 54, in updateAllWordList
  n = len(newWordCountDictList)
TypeError: object of type 'PipelinedRDD' has no len()
回溯(最近一次呼叫最后一次):
文件“/home/warrior/gitDir/pysparkCode/clusterNews/_main__.py”,第31行,在
all_word_dict=wordseg.updatealwordlist(file_wc_dict_list)#file_wc_dict_list.map(lambda file_wc_dict:wordseg.updatealwordlist(file_wc_dict))
文件“/home/warrior/gitDir/pysparkCode/clusterNews/wordSeg.py”,第54行,在updateAllWordList中
n=len(newWordCountDictList)
TypeError:类型为“PipelinedRDD”的对象没有len()
如何解决它!!
谢谢

newWordCountDictList是RDD(分布式对象,位于多个工作节点)对象,而不是驱动程序中的本地集合对象

你可以用任何一种

n = newWordCountDictList.count()


获取正确的结果。

newWordCountDictList是RDD(分布式对象,位于多个工作节点)对象,而不是驱动程序中的本地集合对象

你可以用任何一种

n = newWordCountDictList.count()


为了得到正确的结果。

请提供一些关于代码正在做什么以及它应该做什么的信息。我收集了一些新闻文本,我想使用k-means对它们进行聚类。我已经在我的本地代码中实现了它,但我想在spark中运行它。现在我可以用下面的代码来解决它。只需添加一行代码“file\u wc\u dict\u list\u result=file\u wc\u dict\u list.collect()”。但我现在想知道为什么?请编辑你的问题。你提供的信息越好,有人可以帮助你解决问题的可能性就越高。请提供一些关于你的代码正在做什么以及它应该做什么的信息。我收集了一些新闻文本,我想用k-means对它们进行聚类。我已经在我的本地代码中实现了它,但我想在spark中运行它。现在我可以用下面的代码来解决它。只需添加一行代码“file\u wc\u dict\u list\u result=file\u wc\u dict\u list.collect()”。但我现在想知道为什么?请编辑你的问题。你提供的信息越好,有人能帮助你解决问题的机会就越大。