1、简述
在基于flink的实时计算中,会有实时流join的需求,公司目前使用的是flink1.11版本,是实际的生产中,发现效果不好,甚至几乎join不到,同时多流join显得比较复杂,和同事沟通同时结合自己实践经验,想到使用union + window groupby的方式来实现 多流jion。
flink 双流join 文档:Apache Flink 1.12 Documentation: 流上的 Join
2、代码实践
insert into table_sink
SELECT
user_id,
min(client_time) client_time,
record_id,
max(client_ip) client_ip,
max(card_name) card_name,
max(event_type) event_type
FROM (
select
client_time,
user_id
record_id,
client_ip,
'' card_name,
'' event_type
from table_a
where REGEXP(substr(client_time,1,10),'[0-9]{4}-[0-9]{2}-[0-9]{2}')
union all
select
client_time,
user_id
record_id,
'' client_ip,
'' card_name,
'' event_type
from table_b
where REGEXP(substr(client_time,1,10),'[0-9]{4}-[0-9]{2}-[0-9]{2}')
union all
select
client_time,
user_id
record_id,
'' client_ip,
card_name,
event_type
from table_c
where REGEXP(substr(client_time,1,10),'[0-9]{4}-[0-9]{2}-[0-9]{2}')
)x GROUP BY user_id, record_id,TUMBLE(proctime(), INTERVAL '10' second)
3、实践经验
上面sql代码,公司业务每天的数据量有几个亿,同时在3秒内完成业务流程。实际分配的exectur是4G,发现超过10秒窗口后,就频繁GC报错,所以根据实际的业务场景,时间窗口越大,资源消耗越大,这一点需要注意。