我們有一個流數據,我在HBase表中有一些主信息。對於每一行我都需要查找HBase主表並獲取一些配置文件信息。我的代碼是這樣的foreach中的Spark Streaming過濾條件--NullPointerException
val con = new setContext(hadoopHome,sparkMaster)
val l_sparkcontext = con.getSparkContext
val l_hivecontext = con.getHiveContext
val topicname = "events"
val ssc = new StreamingContext(l_sparkcontext, Seconds(30))
val eventsStream = KafkaUtils.createStream(ssc,"xxx.xxx.142.xxx:2181","receive_rest_events",Map(topicname.toString -> 10))
println("Kafka Stream for receiving Events..")
val profile_data = l_hivecontext.sql("select gender, income, age, riid from hbase_customer_profile")
profile_data.foreach(println)
val tabBC = l_sparkcontext.broadcast(profile_data)
eventsStream.foreachRDD(rdd => {
rdd.foreach(record => {
val subs_profile_rows = tabBC.value
val Rows = record._2.split(rowDelim)
Rows.foreach(row => {
val values = row.split(colDelim)
val riid = values(1).toInt
val cond = "riid = " + riid
println("Condition : ", cond)
val enriched_events = subs_profile_rows.filter(cond)
}) // End of Rows
}) // End of RDD
}) // End of Events Stream
不幸的是,我總是打在過濾器上的NPE。我在這裏接受了幾個問題和答案,以跨工作節點廣播價值觀,但沒有任何幫助。有人可以幫忙嗎?
問候
巴拉
檢查您是否使用無法序列化的值。 – cchantep
我不知道是否應在foreach內創建profile_data,這是不可序列化的。 –