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)到(2019-02-28 22:40:02)

8分钟

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

with same input of time(2019-02-28 22:33:02)
window formed is as (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)到(2019-02-28 22:35:02)

with same input of time(2019-02-28 22:33:02)
window formed is as (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)至(2019-02-28 22:46:02)

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

推荐答案

这在了解间隔的计算方式"部分中进行了解释.在使用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:

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

"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天全站免登陆