一个KSQLtable怎么会有重复的ID?

How can there be duplicate IDs in a KSQL table?

我正在使用 Confluent Community 和 Postgres 数据库,运行 遇到了以下问题。

事件很好地流入kafka并创建了主题。我从主题创建了一个流并重新输入了密钥,因为密钥为空。

在更新后的流的基础上,我创建了一个 table。目标是不断更新 table 对象(此处为类别)。

问题是,当我在数据库中进行手动更新时,table 永远不会更新新数据。这些行就像流一样不断添加。当然,我再次执行了 select,因为我知道 'update' 行会在我们仍然是 运行 查询时出现。

ksql> select * from categories;
1568287458487 | 1 | 1 | Beverages | Soft drinks, coffees, teas, beers, and ales
1568287458487 | 2 | 2 | Condiments | Sweet and savory sauces, relishes, spreads, and seasonings
1568287458488 | 3 | 3 | Confections | Desserts, candies, and sweet breads
1568287458488 | 4 | 4 | Dairy Products | Cheeses
1568287458488 | 5 | 5 | Grains/Cereals | Breads, crackers, pasta, and cereal
1568287458488 | 6 | 6 | Meat/Poultry | Prepared meats
1568287458489 | 7 | 7 | Produce | Dried fruit and bean curd
1568287458489 | 8 | 8 | Seafood | Seaweed and fish
1568288647248 | 8 | 8 | Seafood2 | Seaweed and fish
1568290562250 | 1 | 1 | asdf | Soft drinks, coffees, teas, beers, and ales
1568296165250 | 8 | 8 | Seafood3 | Seaweed and fish
1568296704747 | 8 | 8 | Seafood4 | Seaweed and fish
^CQuery terminated
ksql> select * from categories;
1568287458487 | 1 | 1 | Beverages | Soft drinks, coffees, teas, beers, and ales
1568287458487 | 2 | 2 | Condiments | Sweet and savory sauces, relishes, spreads, and seasonings
1568287458488 | 3 | 3 | Confections | Desserts, candies, and sweet breads
1568287458488 | 4 | 4 | Dairy Products | Cheeses
1568287458488 | 5 | 5 | Grains/Cereals | Breads, crackers, pasta, and cereal
1568287458488 | 6 | 6 | Meat/Poultry | Prepared meats
1568287458489 | 7 | 7 | Produce | Dried fruit and bean curd
1568287458489 | 8 | 8 | Seafood | Seaweed and fish
1568288647248 | 8 | 8 | Seafood2 | Seaweed and fish
1568290562250 | 1 | 1 | asdf | Soft drinks, coffees, teas, beers, and ales
1568296165250 | 8 | 8 | Seafood3 | Seaweed and fish
1568296704747 | 8 | 8 | Seafood4 | Seaweed and fish
^CQuery terminated
ksql> 

postgres 中的类别 table:

CREATE TABLE categories (
    category_id smallint NOT NULL,
    category_name character varying(15) NOT NULL,
    description text
);

KSQL 中的类别 table:

ksql> describe extended categories;

Name                 : CATEGORIES
Type                 : TABLE
Key field            : CATEGORY_ID_ST
Key format           : STRING
Timestamp field      : Not set - using <ROWTIME>
Value format         : AVRO
Kafka topic          : categories_rk (partitions: 1, replication: 1)

 Field          | Type                      
--------------------------------------------
 ROWTIME        | BIGINT           (system) 
 ROWKEY         | VARCHAR(STRING)  (system) 
 CATEGORY_ID_ST | VARCHAR(STRING)           
 CATEGORY_NAME  | VARCHAR(STRING)           
 DESCRIPTION    | VARCHAR(STRING)           
 MESSAGETOPIC   | VARCHAR(STRING)           
 MESSAGESOURCE  | VARCHAR(STRING)           
--------------------------------------------

本应具有唯一 ROWKEY 的 table 怎么可能不断添加更多具有相同 ROWKEY 的 'update' 行?

我实际上希望 table 显示始终最新的类别列表,如 https://www.youtube.com/watch?v=DPGn-j7yD68&list=PLa7VYi0yPIH2eX8q3mPpZAn3qCS1eDX8W&index=9:

中所述

"A TABLE is a materialized view of events with only the latest values for each key"。但也许我误解了?

KSQL 中的 table 随着新数据的到来不断更新。 table 的行写入的输出主题称为更改日志:它是 table 更改的 immutable 日志。如果多次更新特定键,则输出主题将包含同一键的多条消息。每个新值都会替换上一个。

当您 运行 查询如:

select * from categories;

在您使用的 ksql 版本中,您没有 运行ning 传统查询,就像您在传统 RDBS 中所期望的那样。这样的查询将为您提供 table 中的当前行集。在 ksql 中,上面的查询将在更新发生时将所有更新流式传输到行。因此,如果同一个密钥被多次更新;您会多次看到查询输出相同的键。

在较新版本的 ksqlDB 中,不会写入上述查询:

select * from categories emit changes;

在 ksql 内部,每个键只在物化 table 中存储一次,而且总是最新版本。