Queries with streaming sources must be executed with writeStream.start();

前端 未结 5 2023
悲&欢浪女
悲&欢浪女 2020-12-09 16:05

I\'m trying to read the messages from kafka (version 10) in spark and trying to print it.

     import spark.implicits._

         val spark = SparkSession
           


        
5条回答
  •  星月不相逢
    2020-12-09 16:56

    I struggled a lot with this issue. I tried each of suggested solution from various blog. But I my case there are few statement in between calling start() on query and finally at last i was calling awaitTerminate() function that cause this.

    Please try in this fashion, It is perfectly working for me. Working example:

    val query = df.writeStream
          .outputMode("append")
          .format("console")
          .start().awaitTermination();
    

    If you write in this way that will cause exception/ error:

    val query = df.writeStream
          .outputMode("append")
          .format("console")
          .start()
    
        // some statement 
        // some statement 
    
        query.awaitTermination();
    

    will throw given exception and will close your streaming driver.

提交回复
热议问题