MySQL Flink Watermark实现事件时间处理的关键技术(ocp认证烂大街了吗)万万没想到

随心笔谈2年前发布 编辑
166 0
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买

#1.创建表
CREATE TABLE source_table (
user_id STRING,
price BIGINT,
`timestamp` bigint,
row_time AS TO_TIMESTAMP(FROM_UNIXTIME(`timestamp`)),
watermark for row_time as row_time – interval ‘2’ second
) WITH (
‘connector’=’socket’,
‘hostname’=’node1’,
‘port’=’9999’,
‘format’=’csv’
);
#2.Watermark的解释
WATERMARK FOR ts AS ts – INTERVAL ‘2’ SECOND
这里的2,表示,数据允许延迟2秒钟到达,窗口会在(正常结束+延迟时间)后触发计算
#3.查询SQL
select
user_id,
count(*) as pv,
sum(price) as sum_price,
UNIX_TIMESTAMP(CAST(tumble_start(row_time, interval ‘5’ second) AS STRING)) * 1000 as window_start,
UNIX_TIMESTAMP(CAST(tumble_end(row_time, interval ‘5’ second) AS STRING)) * 1000 as window_end
from source_table
group by
user_id,
tumble(row_time, interval ‘5’ second);

© 版权声明

相关文章