spark如何计算给定窗口间隔的窗口开始时间? [英] How spark calculates the window start time with given window interval?

本文介绍了spark如何计算给定窗口间隔的窗口开始时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑我有一个带有时间戳字段列的输入 df 并且在将窗口持续时间(没有滑动间隔)设置为:

10 分钟

Consider I have a input df with a timestamp field column and when setting window duration (with no sliding interval) as :

10 minutes

输入时间(2019-02-28 22:33:02)
形成的窗口为 (2019-02-28 22:30:02) to (2019-02-28 22:40:02)

8 分钟

输入相同的时间(2019-02-28 22:33:02)
形成的窗口为 (2019-02-28 22:26:02) to (2019-02-28 22:34:02)

5 分钟

输入相同的时间(2019-02-28 22:33:02)
形成的窗口为 (2019-02-28 22:30:02) to (2019-02-28 22:35:02)

14 分钟

输入时间(2019-02-28 22:33:02)
形成的窗口为 (2019-02-28 22:32:02) to (2019-02-28 22:46:02)

spark 如何计算给定输入 ts 的窗口的开始时间?

推荐答案

这在理解间隔是如何计算的"一节中有解释在使用 Apache Spark 进行流处理"中O'Reilly 出版的书:

This is explained in the section "Understanding How Intervals are computed" in the "Stream Processing with Apache Spark" book published by O'Reilly:

窗口间隔与对应于下一个的秒/分钟/小时/天的开始对齐";所用时间单位的时间幅度上限."

"The window intervals are aligned to the start of the second/minute/hour/day that corresponds to the next" upper time magnitude of the time unit used."

在您的情况下,您总是使用分钟,因此下一个较高的时间量级是小时".因此它试图到达小时的开始.您的案例更详细(忘记 2 秒,这只是内部延迟):

In your case you are always using minutes so the next upper time magnitude is "hour". Therefore it tries to reach the start of the hour. Your cases in more details (forget about the 2 seconds, this is just a delay in the internals):

  • 10 分钟:22:40 + 10 + 10 ->开始时间
  • 8 分钟:22:34 + 8 + 8 + 8 ->开始时间
  • 5 分钟:22:35 + 5 + 5 + ... + 5 ->开始时间
  • 14 分钟:22:46 + 14 ->开始时间

它独立于传入的数据及其时间戳/事件时间.

It is independent of the incoming data and its timestamp/event_time.

作为一个附加节点,下窗口边界是inclusive,而上边界是exclusive.在数学符号中,这看起来像 [start_time, end_time).

As an additional node, the lower window boundary is inclusive whereas the upper one is exclusive. In mathematical notations this would look like [start_time, end_time).

这篇关于spark如何计算给定窗口间隔的窗口开始时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆