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

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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Flink双流join是指在Flink流处理框架中,将两个流数据进行关联操作的一种方式。在Flink中,支持两种方式的流的Join: Window Join和Interval Join。 Window Join是基于时间窗口的关联操作,包括滚动窗口Join、滑动窗口Join和会话窗口Join。滚动窗口Join是指将两个流中的元素根据固定大小的时间窗口进行关联操作。滑动窗口Join是指将两个流中的元素根据固定大小的时间窗口以固定的滑动间隔进行关联操作。会话窗口Join是指将两个流中的元素根据一段时间内的活动情况进行关联操作。 Interval Join是基于时间区间的关联操作,它允许流中的元素根据时间区间进行关联操作,而不依赖于固定大小的时间窗口。这样可以处理两条流步调不一致的情况,避免等不到join流窗口就自动关闭的问题。 总结起来,Flink双流join提供了通过时间窗口和时间区间的方式将两个流进行关联操作的灵活性和可靠性。根据具体的需求和数据特点,可以选择合适的窗口类型来进行双流join操作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [Flink双流join](https://blog.csdn.net/weixin_42796403/article/details/114713553)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Flink双流JOIN](https://blog.csdn.net/qq_44696532/article/details/124456980)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值