简体   繁体   中英

ksql what is the difference between the primary key and with KEY

ksql.

  1. what is the difference between the primary key and with KEY then create ktable?
  2. should they be applied simultaneously?

在此处输入图像描述

在此处输入图像描述

In both scenarios, they will represent the message key which kinda makes sense when you think about how Kafka handles "tables".

But there is also a difference between those 2: in the second scenario, we see the KEY field more as an optimization technique. As you can notice, the same field can be found in the message value, so it will be extracted from there.

Quoting from the official documentation page:

 If the Kafka message key is also present as a field/column in the Kafka message value, you may set this property to associate the corresponding field/column with the implicit ROWKEY column (message key)

Regarding your second question, if you check the latest version of the documentation you'll notice that the second query is no longer valid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM