TUMBLE(time_attr, interval)
INTERVAL '1' DAY
;设置为2小时:INTERVAL '2' HOUR
,其他用法可参见 时间相关函数。函数名 | 功能描述 |
TUMBLE_START(time-attr, size-interval) | 返回该窗口的起始时间 |
TUMBLE_END(time-attr, size-interval) | 返回该窗口的结束时间 |
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)
INTERVAL '1' DAY
;设置为2小时:INTERVAL '2' HOUR
,其他用法可参见 时间相关函数。INTERVAL '1' DAY
;设置为2小时:INTERVAL '2' HOUR
,其他用法可参见 时间相关函数。函数名 | 功能描述 |
HOP_START(time-attr, slide-interval,size-interval) | 返回该窗口的起始时间 |
HOP_END(time-attr, slide-interval,size-interval) | 返回该窗口的结束时间 |
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)
INTERVAL '1' DAY
;设置为2小时:INTERVAL '2' HOUR,其他用法可参见 时间相关函数。函数名 | 功能描述 |
SESSION_START(time-attr, size-interval) | 返回该窗口的起始时间 |
SESSION_END(time-attr, size-interval) | 返回该窗口的结束时间 |
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
本页内容是否解决了您的问题?