category_id BIGINT,
behavior STRING,
ts TIMESTAMP(3),
proctime as PROCTIME(), – 处理时间列
WATERMARK FOR ts as ts - INTERVAL ‘5’ SECOND – 在ts上定义watermark,ts成为事件时间列
) WITH (
‘connector.type’ = ‘kafka’, – kafka connector
‘connector.version’ = ‘universal’, – universal 支持 0.11 以上的版本
‘connector.topic’ = ‘user_behavior’, – kafka topic
‘connector.startup-mode’ = ‘earliest-offset’, – 从起始 offset 开始读取
‘connector.properties.zookeeper.connect’ = ‘192.168.50.43:2181’, – zk 地址
‘connector.properties.bootstrap.servers’ = ‘192.168.50.43:9092’, – broker 地址
‘format.type’ = ‘json’ – 数据源格式为 json
);
- 执行SELECT * FROM user_behavior;看看原始数据,如果消息正常应该和下图类似:
[](()窗口统计
- 下面的SQL是以每十分钟为窗口,统计每个