【问题标题】:Spark Structured Streaming cannot writeStream in kafkaSpark Structured Streaming无法在kafka中writeStream
【发布时间】:2020-03-28 15:37:05
【问题描述】:

我正在使用结构化流式传输,并尝试将结果发送到名为“results”的 kafka 主题中。

我收到以下错误:

'Append output mode not supported when there are streaming aggregations on streaming DataFrames/DataSets without watermark;;

谁能帮忙?

query1 = prediction.writeStream.format("kafka")\
  .option("topic", "results")\
  .option("kafka.bootstrap.servers", "localhost:9092")\
  .option("checkpointLocation", "checkpoint")\
  .start()
query1.awaitTermination()

预测模式是:

root
 |-- prediction: double (nullable = false)
 |-- count: long (nullable = false)

我错过了什么吗?

【问题讨论】:

标签: apache-kafka spark-structured-streaming


【解决方案1】:

错误消息提示缺少什么:水印。

当您聚合流数据时,水印用于处理延迟传入的数据。有关结构化流式处理的详细信息,请参见 Spark documentation

重要的是 withWatermark 与聚合中使用的时间戳列在同一列上使用。

Spark 文档中给出了如何使用withWatermark 的示例:

words = ...  # streaming DataFrame of schema { timestamp: Timestamp, word: String }

# Group the data by window and word and compute the count of each group
windowedCounts = words \
    .withWatermark("timestamp", "10 minutes") \
    .groupBy(
        window(words.timestamp, "10 minutes", "5 minutes"),
        words.word) \
    .count()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 2020-07-25
    • 2020-09-08
    • 1970-01-01
    相关资源
    最近更新 更多