Answer a question

I've trouble to resolve the following exception "Queries with streaming sources must be executed with writeStream.start();; kafka"

My code is the following :

val spark = SparkSession
      .builder()
      .getOrCreate()

val bootstrapServers = "localhost:9092"
val topicName = "name"

val df = spark
      .readStream
      .format("kafka")
      .option("kafka.bootstrap.servers", bootstrapServers)
      .option("subscribe", topicName)
      .option("group.id", "Structured-Streaming-kpi")
      .option("failOnDataLoss", false)
      .load()

df.writeStream
      .format("console")
      .start()
      .awaitTermination();
df.show()

Answers

I think the problem is this df.show()

Your df is written to console already.

Try to remove it and see what happens

Logo

华为、百度、京东云现已入驻,来创建你的专属开发者社区吧!

更多推荐