1
下面是我使用Scala在spark.streaming
中獲得Flume事件和程序的代碼。使用Flume + Spark Streaming的示例字數統計應用程序
當嘗試使用reduceBykey
功能我得到以下編譯錯誤:
value reduceByKey is not a member of org.apache.spark.streaming.dstream.DStream[(String, Int)]
爲什麼?
我們是否需要以其他任何特定方式處理Flume流?
我不認爲這是一個依賴性問題,我有其他簡單的應用程序在相同的Eclipse IDE中使用reduceBykey
正在使用。
package com.deloitte.spark.learning
import org.apache.spark.streaming.{Seconds, StreamingContext}
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
import org.apache.spark.streaming.flume._
object Wordcount {
def main(args: Array[String]) {
if (args.length < 2) {
System.err.println("Usage: NetworkWordCount <hostname> <port>")
System.exit(1)
}
val sparkConf = new Sparkconf().setMaster("local[2]").setAppName("aa")
val ssc = new StreamingContext(sparkConf, Seconds(200))
val stream = FlumeUtils.createStream(ssc, args(0), args(1).toInt)
stream.count().map(cnt => "Received " + cnt + " flume events.").print()
val lines = stream.map {
e => new String(e.event.getBody().array(), "UTF-8")
}
val words = lines.flatMap(_.split(" "))
val wordCounts = words.map(x => (x, 1))
ssc.start()
ssc.awaitTermination(1000)
}
}
有通過Eclipse IDE中沒有建議,我已經導入它按你的advice.Its工作現在,謝謝 – Techiyyy
@Techiyyy如果您希望導入的類中存在隱式函數,Eclipse仍然不適用於scala通配符導入。這就是爲什麼我沒有向你建議。 – eliasah