TUMBLE(time_attr, interval)
time_attr
is a timestamp parameter that specifies the time when a record is processed. If specified as PROCTIME
, it is an automatically generated timestamp that records the moment when the data is processed by Flink. It is generally used in Processing Time mode.interval
specifies the window size. For example, use INTERVAL '1' DAY
to set a 1-day window size and INTERVAL '2' HOUR
a 2-hour window size. For other usage, see Date and Time Functions.proctime()
function. In the following example, we use PROCTIME
, but you should replace it with the actual column name in your job.Function | Description |
TUMBLE_START(time-attr, size-interval) | Returns the start timestamp of the window. |
TUMBLE_END(time-attr, size-interval) | Returns the end timestamp of the window. |
username (VARCHAR) | income (BIGINT) | times (TIMESTAMP) |
Tom | 20 | 2021-11-11 10:30:00.0 |
Jack | 10 | 2021-11-11 10:35:00.0 |
Tom | 10 | 2021-11-11 10:35:00.0 |
Tom | 10 | 2021-11-11 10:40:00.0 |
Tom | 15 | 2021-11-11 11:30:00.0 |
Jack | 10 | 2021-11-11 11:30:00.0 |
Jack | 15 | 2021-11-11 11:40:00.0 |
CREATE TABLE user_income (username VARCHAR,Income INT,times TIMESTAMP(3),WATERMARK FOR times AS times - INTERVAL '3' SECOND) WITH (...);CREATE TABLE output (win_start TIMESTAMP,win_end TIMESTAMP,username VARCHAR,hour_income BIGINT)WITH(...);INSERT INTO outputSELECTTUMBLE_START(times,INTERVAL '1' HOUR),TUMBLE_END(times,INTERVAL '1' HOUR),username,SUM(Income)FROM user_incomeGROUP BY TUMBLE(times,INTERVAL '1' HOUR),username;
win_start (TIMESTAMP) | win_end (TIMESTAMP) | username (VARCHAR) | hour_income (BIGINT) |
2021-11-11 10:00:00.0 | 2021-11-11 11:00:00.0 | Tom | 40 |
2021-11-11 10:00:00.0 | 2021-11-11 11:00:00.0 | Jack | 10 |
2021-11-11 11:00:00.0 | 2021-11-11 12:00:00.0 | Tom | 15 |
2021-11-11 11:00:00.0 | 2021-11-11 12:00:00.0 | Jack | 25 |
HOP(time_attr, sliding_interval, window_size_interval)
time_attr
is a timestamp parameter that specifies the time when a record is processed. If specified as PROCTIME
, it is an automatically generated timestamp that records the moment when the data is processed by Flink. It is generally used in Processing Time mode.window_size_interval
specifies the window size. For example, use INTERVAL '1' DAY
to set a 1-day window size and INTERVAL '2' HOUR
a 2-hour window size. For other usage, see Date and Time Functions.sliding_interval
specifies the hop interval. For example, use INTERVAL '1' DAY
to set a 1-day window size and INTERVAL '2' HOUR
a 2-hour window size. For other usage, see Date and Time Functions.Function | Description |
HOP_START(time-attr, slide-interval,size-interval) | Returns the start timestamp of the window. |
HOP_END(time-attr, slide-interval,size-interval) | Returns the end timestamp of the window. |
username (VARCHAR) | income (BIGINT) | times (TIMESTAMP) |
Tom | 20 | 2021-11-11 10:30:00.0 |
Jack | 10 | 2021-11-11 10:35:00.0 |
Tom | 10 | 2021-11-11 10:35:00.0 |
Tom | 10 | 2021-11-11 10:40:00.0 |
Tom | 15 | 2021-11-11 11:35:00.0 |
Jack | 10 | 2021-11-11 11:30:00.0 |
Jack | 15 | 2021-11-11 11:40:00.0 |
CREATE TABLE user_income (username VARCHAR,Income INT,times TIMESTAMP(3),WATERMARK FOR times AS times - INTERVAL '3' MINUTE)WITH(...);CREATE TABLE output (win_start TIMESTAMP,win_end TIMESTAMP,username VARCHAR,hour_income BIGINT)WITH(...);INSERT INTO outputSELECTHOP_START(times,INTERVAL '30' MINUTE,INTERVAL '1' HOUR),HOP_END(times,INTERVAL '30' MINUTE,INTERVAL '1' HOUR),username,SUM(income)FROM user_incomeGROUP BY HOP(times,INTERVAL '30' MINUTE,INTERVAL '1' HOUR),username;
win_start (TIMESTAMP) | win_end (TIMESTAMP) | username (VARCHAR) | hour_income (BIGINT) |
2021-11-11 10:00:00.0 | 2021-11-11 11:00:00.0 | Tom | 40 |
2021-11-11 10:00:00.0 | 2021-11-11 11:00:00.0 | Jack | 10 |
2021-11-11 10:30:00.0 | 2021-11-11 11:30:00.0 | Jack | 10 |
2021-11-11 10:30:00.0 | 2021-11-11 11:30:00.0 | Tom | 40 |
2021-11-11 11:00:00.0 | 2021-11-11 12:00:00.0 | Tom | 15 |
2021-11-11 11:00:00.0 | 2021-11-11 12:00:00.0 | Jack | 25 |
2021-11-11 11:30:00.0 | 2021-11-11 12:30:00.0 | Jack | 25 |
2021-11-11 11:30:00.0 | 2021-11-11 12:30:00.0 | Tom | 15 |
SESSION(time_attr, interval)
time_attr
is a timestamp parameter that specifies the time when a record is processed. If specified as PROCTIME
, it is an automatically generated timestamp that records the moment when the data is processed by Flink. It is generally used in Processing Time mode.interval
specifies the window size. For example, use INTERVAL '1' DAY
to set a 1-day window size and INTERVAL '2' HOUR
a 2-hour window size. For other usage, see Date and Time Functions.Function | Description |
SESSION_START(time-attr, size-interval) | Returns the start timestamp of the window. |
SESSION_END(time-attr, size-interval) | Returns the end timestamp of the window. |
username (VARCHAR) | income (BIGINT) | times (TIMESTAMP) |
Tom | 20 | 2021-11-11 10:30:00.0 |
Jack | 10 | 2021-11-11 10:35:00.0 |
Tom | 10 | 2021-11-11 10:35:00.0 |
Tom | 10 | 2021-11-11 10:40:00.0 |
Tom | 15 | 2021-11-11 11:50:00.0 |
Jack | 10 | 2021-11-11 11:40:00.0 |
Jack | 15 | 2021-11-11 11:45:00.0 |
CREATE TABLE user_income (username VARCHAR,Income INT,times TIMESTAMP(3),WATERMARK FOR times AS times - INTERVAL '3' MINUTE)WITH(...);CREATE TABLE output (win_start TIMESTAMP,win_end TIMESTAMP,username VARCHAR,hour_income BIGINT)WITH(...);INSERT INTO outputSELECTSESSION_START(times,INTERVAL '30' MINUTE),SESSION_END(times,INTERVAL '30' MINUTE),username,SUM(Income)FORM user_incomeGROUP BY SESSION(times,INTERVAL '30' MINUTE),username;
win_start (TIMESTAMP) | win_end (TIMESTAMP) | username (VARCHAR) | hour_income (BIGINT) |
2021-11-11 10:30:00.0 | 2021-11-11 11:10:00.0 | Tom | 40 |
2021-11-11 10:35:00.0 | 2021-11-11 11:05:00.0 | Jack | 10 |
2021-11-11 11:30:00.0 | 2021-11-11 12:00:00.0 | Tom | 15 |
2021-11-11 11:30:00.0 | 2021-11-11 12:10:00.0 | Jack | 25 |
SELECT user,TUMBLE_START(rowtime, INTERVAL '12' HOUR) AS sStart,TUMBLE_ROWTIME(rowtime, INTERVAL '12' HOUR) AS snd,SUM(amount)FROM OrdersGROUP BY TUMBLE(rowtime, INTERVAL '12' HOUR), user
SELECT user,TUMBLE_START(PROCTIME, INTERVAL '12' HOUR) AS sStart,TUMBLE_PROCTIME(PROCTIME, INTERVAL '12' HOUR) AS snd,SUM(amount)FROM OrdersGROUP BY TUMBLE(PROCTIME, INTERVAL '12' HOUR), user
Was this page helpful?