连接 Kafka 流与全局 K 表,使用非键值方式。

huangapple go评论73阅读模式
英文:

Kafka- Joining a Kafka Stream with a Global K Table using non key value

问题

I've seen multiple postings that state it's possible to join a Kafka stream with a global K table using record values instead of keys on the global K table.

它们允许根据外键进行连接;即,您可以查找表中的数据,不仅通过流中记录的键,还可以通过记录值中的数据。

这是否意味着可以使用全局K表的记录值而不是全局K表的键来连接流与全局K表。

例如:

我有两个对象/表
订单 --> 订单ID、订单金额
订单详细 --> 订单详细ID、订单ID、数量、价格

订单将转换为Kafka流,其键为订单ID
订单详细将转换为全局K表,其键为订单详细ID

订单ID是订单详细的外键

是否可以在流(订单)和全局K表(订单详细)之间执行连接,使用订单详细的非键值,即使用订单订单ID进行连接。目的是检索具有其所有订单详细信息的订单列表。

我查看了KStreamKTableJoinProcessor并注意到process()方法总是在全局K表上搜索键。
我知道可以选择在左侧(KStream)使用的键,但是否可以在执行连接时选择来自右侧(全局K表)的记录值作为键。

一种解决方案是重新创建全局K表,将订单ID作为新键,但我不想这样做,因为那将在全局K表中只创建一个订单ID值。我试图获取一对多的关系。

英文:

Ive seen multiple posting that state its possible to join a kafka stream with a global k table using record values instead on keys on the global k table
https://kafka.apache.org/20/documentation/streams/developer-guide/dsl-api.html#kstream-globalktable-join

They allow for joining against foreign keys; i.e., you can lookup data in the table not just by the keys of records in the stream, but also by data in the record values.

Does that mean its possible to join a stream with a global k table using a record value of the global k table rather than the key of the global k table.

For Ex:

I have two objects / tables
Order --> orderId, order amount
OrderDetail --> orderDetailid, orderId, qty, price

Order will be converted in to a kafka stream with key orderId
OrderDetail will be converted in to global k table with key orderDetailId

OrderId is a foreign key in OrderDetail

Is it possible to perform a join on Stream(Order) and GlobalKTable(OrderDetail) with a non key value of OrderDetail
ie: A join on Order.orderId with OrderDetail.OrderId.
The intention here is to retrieve a list of Orders with all their Order Details

I looked at KStreamKTableJoinProcessor and noticed the process() method always searched for the key on the global k table.
I know its possible to select the key to be used on the Left Side (KStream), but is it possible to select a record value as the key from the right side (Global K Table) while performing the join.

One solution would be to recreate the global k table with orderId as the new key , but I dont want that as that would only create one orderId value in the Global K Table. Im trying to fetch a one-many relationship

答案1

得分: 0

不可能使用表侧的值来执行 KStream-GlobalKTable 的连接,您只能使用流中的值来与 GlobalKTable 的键匹配。

英文:

To answer your question - no it's not possible to do a KStream-GlobalKTable join with a value from the table side, you can only use the value from the stream to match against the key of the GlobalKTable

huangapple
  • 本文由 发表于 2023年4月13日 21:30:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76006047.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定