我们有一个流数据,我在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,这是不可序列化的。 –