我是 scala 的超級新手,并試圖撰寫一個小火花流程式,其中包含文本檔案的行,它們被剝離任何非字母數字字符,然后映射、減少和列印出來。
我已經撰寫了下面的代碼并使用以下命令運行它:
spark-submit --classgroup.WordCount --master yarn --deploy-mode client bdpAssignmentFour.jar hdfs:///user/s3797303'
import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}
object WordCount {
def main(args: Array[String]): Unit = {
val sconf = new SparkConf().setAppName("SparkWordCount")
val ssc = new StreamingContext(sconf, Seconds(5))
val pat = "^[a-zA-Z0-9]*$".r
val lines = ssc.textFileStream(args(0))
val lines_map = lines.map(line => pat.findAllIn(line))
lines_map.print()
val wordCounts = lines_map.map((_, 1)).reduceByKey(_ _)
wordCounts.print()
ssc.start()
ssc.awaitTermination()
}
}
這似乎只是運行 find 但隨后回傳有關以下行的錯誤: val lines_map = lines.map(line => pat.findAllIn(line))
它給出的錯誤如下:object not serializable (class: scala.util.matching.Regex$MatchIterator, value: empty iterator
我該怎么做才能使物件可序列化并希望最終得到一些運行的代碼?
uj5u.com熱心網友回復:
快速解決:
- 將
pat值行內:lines.map(line => "...".r.findAllIn(line)) - 或將其移動到
object現有方法和物件的外部
您將無法使正則運算式可序列化,您的目標是將其移動到 Spark 不需要對其進行序列化的地方。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/529606.html
標籤:斯卡拉阿帕奇火花
