【问题标题】:How to cache dstream in spark如何在火花中缓存dstream
【发布时间】:2018-01-12 10:08:05
【问题描述】:

我想从kafka读取结构化流数据作为dstream,对于每个数据,我想用很多函数来处理它,所以我尝试缓存dstream。

lines = spark\
    .readStream\
    .format("kafka")\
    .option("kafka.bootstrap.servers", bootstrapServers)\
    .option(subscribeType, topics)\
    .load()\
    .selectExpr("CAST(value AS STRING)")
lines.cache()
...
...
lines.cache()

但是,我得到了如下错误

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

有什么帮助吗?

【问题讨论】:

    标签: apache-spark spark-dataframe spark-streaming


    【解决方案1】:

    与队列功能无关。只需在最后添加lines.start()即可。

    请在提问前参考示例代码。 https://github.com/apache/spark/blob/master/examples/src/main/python/sql/streaming/structured_kafka_wordcount.py

    【讨论】:

    • 嗨okwap,我知道它在火花流中很有用,但是,我使用的是火花结构化流。是否可以在结构化流中添加缓存?
    • lines.cache()有什么问题吗?
    猜你喜欢
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-05
    • 2019-04-29
    • 2013-12-29
    • 2021-05-15
    • 1970-01-01
    相关资源
    最近更新 更多