2016-03-21 21 views
0

herkese sahip değil!TypeError: 'PipelinedRDD' türündeki nesnenin hiçbiri len()

kod kıvılcım bir piton kodu çalıştırırken bu hata günlüğü karşılamak:

ana .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 

...... Kıvılcım olduğunda .......

ana .py çıkış hata günlüğü -submit:

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() 

nasıl çözüleceğini !! Teşekkürler!

+0

Lütfen kodunuzun ne yaptığını ve ne yapması gerektiğine dair biraz bilgi verin. – Oli

+0

Bazı haber metinleri topluyorum ve bunları k-aracı olarak kullanmak istiyorum. Yerel kodumda bunu fark ettim ama kıvılcım ile çalıştırmak istiyorum. –

+0

şimdi onu aşağıdaki kod ile çözebilirim. sadece bir satır kodu ekleyin "file_wc_dict_list_result = file_wc_dict_list.collect()". ama şimdi neden istiyorum? –

cevap

2

newWordCountDictList, sürücü programınızdaki yerel koleksiyon nesnesinin RDD'sidir (dağıtılmış nesne ve birden çok iş düğümlerinde bulunur) nesnesi değildir.

Sen

n = newWordCountDictList.count() 

veya

all_word_dict = wordseg.updateAllWordList(file_wc_dict_list.collect()) 

doğru sonuca ulaşmak için kullanabilirsiniz.

+0

Teşekkürler! işe yarıyor!! –

+0

eğer sakıncası yoksa lütfen yukarıdaki cevabı kabul edin :) –

İlgili konular