flink 双流jion 使用union all + groupby方式实现

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报错,所以根据实际的业务场景,时间窗口越大,资源消耗越大,这一点需要注意。
 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值