Flinksql bug : Temporal table join requires an equality condition on fields of table

在使用Flink SQL进行维表关联时遇到错误:Temporal table join需要等值条件。错误出现在特定的流式join操作与Hive表关联的场景。解决方案是确保关联条件为等号连接,且两侧数据类型一致。然而,实践中发现,即使对数字内容的字符串字段进行类型转换(如cast(cast(field as bigint) as string)),也会导致错误。正确的做法是将int类型字段直接cast为string,然后与string类型字段进行关联。
摘要由CSDN通过智能技术生成

报错信息

org.apache.flink.table.api.TableException: Temporal table join requires an equality condition on fields of table *******************

发生地址

flinksql 与维表关联场景 包括hive的流式join

解决

关联条件必须等值关联 也就是必须是等号,并且 关联条件两边要确定数据类型相同

实测

如果关联条件都是字符串,内容是数字,两测都强制类型转换,cast(feild as bigint) 会报错。很奇怪 做了强制类型转换反而报错了
不支持 已经是int的类型 再次cast(int类型字段 as int) 与 cast(string类型字段 as int) 做关联 必须 string类型字段 = cast(int类型字段 as string) 这么做

报错!!!!
left join  hive_zjyprc_hadoop.china_bi.dim_sku_great_bargains /*+ OPTIONS('streaming-source.enable' = 'true','streaming-source.partition.include' = 'latest',
            'streaming-source.partition-order' = 'create-time','streaming-source.monitor-interval' = '1 h') */
             FOR SYSTEM_TIME AS OF w.proctime AS w3  on cast(w.category_id as bigint) = cast(w3.virtual_category_id as bigint)
正确!!!            left join  hive_zjyprc_hadoop.china_bi.dim_sku_great_bargains /*+ OPTIONS('streaming-source.enable' = 'true','streaming-source.partition.include' = 'latest',
            'streaming-source.partition-order' = 'create-time','streaming-source.monitor-interval' = '1 h') */
             FOR SYSTEM_TIME AS OF w.proctime AS w3  on w.category_id = cast(w3.virtual_category_id

  • 12
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要触发Flink的event time temporal join,需要满足以下条件: 1. 数据源必须有时间戳(timestamp)字段,用于标识事件发生的时间。 2. 数据源必须定义Event Time和Watermark,用于处理乱序事件数据。 3. 执行join操作时,需要使用Window函数将事件流分割为固定时间段的窗口,以便进行join操作。 4. 在join操作中,需要将窗口中的数据按照时间戳进行排序。 5. 确保所有数据源都使用相同的时间语义(Event Time)。 以下是一个示例代码,演示如何触发Flink的event time temporal join: ``` DataStream<Order> orders = env .addSource(new OrderSource()) .assignTimestampsAndWatermarks(new OrderTimestampExtractor()); DataStream<Payment> payments = env .addSource(new PaymentSource()) .assignTimestampsAndWatermarks(new PaymentTimestampExtractor()); orders.join(payments) .where(order -> order.getCustomerId()) .equalTo(payment -> payment.getCustomerId()) .window(TumblingEventTimeWindows.of(Time.seconds(10))) .apply(new JoinFunction<Order, Payment, String>() { @Override public String join(Order order, Payment payment) throws Exception { return "Order: " + order.toString() + ", Payment: " + payment.toString(); } }) .print(); ``` 在上述代码中,orders和payments分别是两个数据源,分别代表订单和支付信息。我们使用OrderTimestampExtractor和PaymentTimestampExtractor对它们进行时间戳和Watermark的处理。 在join操作中,我们使用where和equalTo指定订单和支付信息的关联字段,使用TumblingEventTimeWindows将事件流分割为10秒的窗口,然后使用JoinFunction进行join操作,并将结果打印出来。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Direction_Wind

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值