How to convert JavaPairInputDStream into DataSet/DataFrame in Spark

前端 未结 2 1434
礼貌的吻别
礼貌的吻别 2021-02-06 06:14

I am trying to receive streaming data from kafka. In this process I am able to receive and store the streaming data into JavaPairInputDStream.

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-06 06:31

    Technically Dstream is sequence of RDDs, you won't convert Dstream to Datframe instead you will convert each RDD to Dataframe/Dataset as below(Scala code please convert it in Java for your case):

    stream.foreachRDD { rdd =>
    
      val dataFrame = rdd.map {case (key, value) => Row(key, value)}.toDF()
    
    }
    

提交回复
热议问题