【发布时间】:2023-03-29 13:22:01
【问题描述】:
我尝试使用下面的代码代替 query.awaitTermination() 在 spark 中重新启动流式查询,下面的代码将在无限循环中并寻找触发器以重新启动查询,然后执行下面的代码。基本上我试图刷新缓存的 df .
query.processAllavaialble()
query.stop()
//oldDF is a cached Dataframe created from GlobalTempView which is of size 150GB.
oldDF.unpersist()
val inputDf: DataFrame = readFile(spec, sparkSession) //read file from S3
or anyother source
val recreateddf = inputDf.persist()
//Start the query// here should i start query again by invoking readStream ?
但是当我查看 spark 文档时,它说
void processAllAvailable() ///documentation says This method is intended for testing/// Blocks until all available data in the source has been processed and committed to the sink. This method is intended for testing. Note that in the case of continually arriving data, this method may block forever. Additionally, this method is only guaranteed to block until data that has been synchronously appended data to a Source prior to invocation. (i.e. getOffset must immediately reflect the addition).
stop() Stops the execution of this query if it is running. This method blocks until the threads performing execution has stopped.
那么在不停止我的 Spark 流应用程序的情况下重新启动查询的更好方法是什么
【问题讨论】:
-
我在答案中添加了一个参考示例
标签: apache-spark spark-streaming