0
在Scala中,我試圖通過一個巨大的全局變量到地圖操作,火花提示我的信息:如何在地圖操作中添加全局變量?
ERROR yarn.ApplicationMaster: User class threw exception: java.lang.StackOverflowError
at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1509)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)
at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)
代碼如下:
val data = sc.textFile(inputPath).cache()
val map = Map[String, Int]()
for (i <- 0 to 9) {
map(i.toString) = i
}
data.map(sample => {
if (map.contains(sample)) {
("Found")
}
else {
("Not found")
}
})
我認爲你需要廣播地圖。 嘗試val broadcastcastedMap = sc.broadcast(地圖) 並訪問它with broadcastcastedMap.value –
嘗試過,仍然遇到同樣的錯誤... –
爲什麼你序列化*巨大的*對象? –