首页 > 解决方案 > KSQL 表 - 表连接未按预期工作

问题描述

我正在尝试在 KSQL 中加入两个表。这个想法是在连接查询之上创建一个持久表。我正在使用完全外部联接。

来源 1: Kafka 主题 -> KSQL 流 -> KSQL 表

表格顺序中的示例数据:

Key,Product_Name,Product_category   
Product_1|Category_1|2018-08-25,Product_1,Category_1    
Product_2|Category_2|2018-08-25,Product_2,Category_2    
Product_3|Category_3|2018-08-25,Product_3,Category_3    
Product_4|Category_4|2018-08-25,Product_4,Category_4    
Product_5|Category_5|2018-08-25,Product_5,Category_5

来源 2: Kafka 主题 -> KSQL 流 -> KSQL 表

表产品中的示例数据:

Key,Product_Name,Product_category
Product_1|Category_1|2018-08-25,Product_1,Category_1    
Product_2|Category_2|2018-08-25,Product_2,Category_2    
Product_3|Category_3|2018-08-25,Product_3,Category_3    
Product_4|Category_4|2018-08-25,Product_4,Category_4    
Product_5|Category_5|2018-08-25,Product_5,Category_5

源 1 中的数据流是连续的,而源 2 中的数据流是固定的,每天一次。

加盟查询:

Create Table Order_Joined_Product as 
  select 
    A.key as Order_Key,
    A.Product_Name as Order_Product,
    A.Product_Category as Order_category,
    B.key as Product_Key,
    B.Product_Name as Product,
    B.Product_Category as Product_category 
  from Order as A 
    FULL JOIN PRODUCT as B on A.Key=B.Key

现在,问题是如果我对连接表进行计数,Order_Key 计数会随着时间的推移而增加,而 Product_Key 的计数会随着时间的推移而减少。

我想要实现的是到一天结束时,我想查看源 1 中而不是 2 中的产品数量以及源 2 中而不是 1 中的产品数量。

标签: apache-kafkaksqldbconfluent-platform

解决方案


推荐阅读