| |
| |
|
|
| |
| CREATE TABLE event_source ( |
| user_id INT, |
| event_id BIGINT, |
| event_type INT, |
| event_time AS LOCALTIMESTAMP, |
| WATERMARK FOR event_time AS event_time - INTERVAL '10' SECOND |
| ) WITH ( |
| 'connector' = 'datagen', |
| 'rows-per-second' = '5000', |
| 'fields.user_id.kind' = 'random', |
| 'fields.user_id.min' = '1', |
| 'fields.user_id.max' = '10000', |
| 'fields.event_id.kind' = 'random', |
| 'fields.event_id.min' = '1', |
| 'fields.event_id.max' = '1000000000', |
| 'fields.event_type.kind' = 'random', |
| 'fields.event_type.min' = '1', |
| 'fields.event_type.max' = '8' |
| ); |
|
|
| |
| CREATE TABLE console_output ( |
| window_start TIMESTAMP(3), |
| window_end TIMESTAMP(3), |
| user_id INT, |
| event_id BIGINT, |
| event_type INT |
| ) WITH ( |
| 'connector' = 'print' |
| ); |
|
|
| |
| INSERT INTO console_output |
| SELECT |
| window_start, |
| window_end, |
| user_id, |
| event_id, |
| event_type |
| FROM ( |
| SELECT |
| window_start, |
| window_end, |
| user_id, |
| event_id, |
| event_type, |
| ROW_NUMBER() OVER ( |
| PARTITION BY window_start, user_id |
| ORDER BY event_time ASC |
| ) AS rn |
| FROM TABLE( |
| TUMBLE(TABLE event_source, DESCRIPTOR(event_time), INTERVAL '5' MINUTE) |
| ) |
| ) t |
| WHERE rn = 1; |
|
|