How to omit a null value exception in flink-kafka , Any help would do

血红的双手。 提交于 2019-12-01 12:16:38

问题


I'm trying to make a code that creates alert when temperature is above threshold temperature (as defined in the code), but keyed stream is creating problem. I'm new to flink and intermediate in scala. I need help in this code

I've tried almost everything

 def main(args: Array[String]): Unit = {
    val TEMPERATURE_THRESHOLD: Double = 50.00

    val see: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    val properties = new Properties()
    properties.setProperty("bootstrap.servers", "localhost:9092")
    properties.setProperty("zookeeper.connect", "localhost:2181")

    val src = see.addSource(new FlinkKafkaConsumer010("broadcast",
      new JSONKeyValueDeserializationSchema(true), properties))


    var data = src.map { v => {
      val loc = v.get("locationID").asInstanceOf[String]
      val temperature = v.get("temp").asDouble()
    //val json = Map("locationID" -> locationID, "temp" -> v.temp)
    //val jsonVal = JSONObject(json).toString()
      (loc, temperature)
    }}
 data = data
      .keyBy(
        v => v._1
      )
{"locationID": "ASK", "temp": 35} {"locationID": "BC", "temp": 45} {"locationID": "CHD", "temp": 55} {"locationID": "RAJ", "temp": 65} {"locationID": "EGY", "temp": 55}

I think my tuple is taking null value from somewhere , I need help omit that error

Error:-

Exception in thread "main" org.apache.flink.runtime.client.JobExecutionException: Job execution failed.
...

    at flinkBroadcast1$.main(flinkBroadcast1.scala:59)
    at flinkBroadcast1.main(flinkBroadcast1.scala)
Caused by: java.lang.Exception: org.apache.flink.streaming.runtime.tasks.ExceptionInChainedOperatorException: Could not forward element to next operator
...
Caused by: org.apache.flink.streaming.runtime.tasks.ExceptionInChainedOperatorException: Could not forward element to next operator
...
Caused by: java.lang.NullPointerException

来源:https://stackoverflow.com/questions/58233895/how-to-omit-a-null-value-exception-in-flink-kafka-any-help-would-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!