1. 程式人生 > >pyspark報錯: invalid stream header

pyspark報錯: invalid stream header


當我對rdd進行map操作的時候,就是新增一個欄位,表示其中的兩個欄位是否相等,然後報這個錯誤。
Google後也沒找到確切的解決方案,因為是用python程式設計,對java不熟悉,估計是java物件讀寫資料的時候發生的問題. google的答案: I can tell you that this usually means somewhere something wrote 
objects to the same OutputStream with multiple ObjectOutputStreams. AC 

is a header value. 

I don't obviously see where/how that could happen, but maybe it rings 
a bell for someone. This could happen if an OutputStream is reused 
across object serializations but new ObjectOutputStreams are opened, 
for example. 
既然是這樣,就重啟pyspark看看能否解決,果然,重啟後就解決了。沒再報那個錯誤了。
但是後來又報這個錯誤,重啟不能解決,又百度:在一個檔案都有一個檔案的頭部和檔案體。由於對多次使用FileOutputStream構建的ObjectOutputStream物件向同一個檔案讀資料,在每次讀資料的時候他都會向這個檔案末尾先寫入header再寫入你要寫的物件資料,在讀取的時候遇到這個在檔案體中的header就會報錯。導致讀出時,出現streamcorrput異常
然後我就想,可能是比較rdd中兩個元素的時候,多次使用了FileOutputStream構建的ObjectOutputStream物件
如果哪位大神看到知道具體是什麼原因引起的,可以留下你的答案!!!