【发布时间】:2020-11-30 18:06:38
【问题描述】:
在使用 mapGroupsWithState 进行 spark 结构化流式传输时,我正在努力理解超时设置。
下面的链接有非常详细的规范,但我不确定我是否理解正确,尤其是GroupState.setTimeoutTimeStamp() 选项。将状态到期设置为与事件时间相关的含义。
https://spark.apache.org/docs/3.0.0-preview/api/scala/org/apache/spark/sql/streaming/GroupState.html
我在这里复制了它们:
With EventTimeTimeout, the user also has to specify the the the event time watermark in the query using Dataset.withWatermark().
With this setting, data that is older than the watermark are filtered out.
The timeout can be set for a group by setting a timeout timestamp usingGroupState.setTimeoutTimestamp(), and the timeout would occur when the watermark advances beyond the set timestamp.
You can control the timeout delay by two parameters - watermark delay and an additional duration beyond the timestamp in the event (which is guaranteed to be newer than watermark due to the filtering).
Guarantees provided by this timeout are as follows:
Timeout will never be occur before watermark has exceeded the set timeout.
Similar to processing time timeouts, there is a no strict upper bound on the delay when the timeout actually occurs. The watermark can advance only when there is data in the stream, and the event time of the data has actually advanced.
问题 1:
这句and the timeout would occur when the watermark advances beyond the set timestamp中的timestamp是什么?它是绝对时间,还是该州当前事件时间的相对持续时间?我知道我可以通过 ```
例如假设我有一些如下的数据状态,when 会通过在what settings 中设置what value 来过期吗?
+-------+-----------+-------------------+
|expired|something | timestamp|
+-------+-----------+-------------------+
| false| someKey |2020-08-02 22:02:00|
+-------+-----------+-------------------+
问题 2:
看了Data that is older than the watermark are filtered out这句话,我明白迟到的数据从kafka读取后会被忽略,这样对吗?
问题原因
如果不了解这些,我就无法真正将它们应用到用例中。含义何时使用GroupState.setTimeoutDuration(),何时使用GroupState.setTimeoutTimestamp()
非常感谢。
ps。我也尝试阅读以下内容
- https://www.waitingforcode.com/apache-spark-structured-streaming/stateful-transformations-mapgroupswithstate/read
(confused me, did not understand)
- https://databricks.com/blog/2017/10/17/arbitrary-stateful-processing-in-apache-sparks-structured-streaming.html
(did not say a lot of it for my interest)
【问题讨论】:
-
我在
mapGroupsWithState[S,U]的签名中发现了这条评论,上面写着@param timeoutConf Timeout configuration for groups that do not receive data for a while.。这让我现在更好地理解了这个概念,所以也许如果我选择GroupState.setTimeoutDuration,将在每个触发器/调用中检查状态超时;如果我选择GroupState.setTimeoutTimestamp(),则只有在收到新事件时才会检查状态时间。
标签: apache-spark spark-structured-streaming