Kafka/KsqlDb :为什么 PRIMARY KEY 附加字符?
Kafka/KsqlDb : Why is PRIMARY KEY appending chars?
我打算创建一个名为 WEB_TICKETS 的 TABLE,其中 PRIMARY KEY 等于 key->ID 值。出于某种原因,当我 运行 CREATE TABLE 指令时,PRIMARY KEY 值附加了字符 'JO' - 为什么会这样?
KsqlDb 语句
这些按预期工作
CREATE STREAM STREAM_WEB_TICKETS (
ID_TICKET STRUCT<ID STRING> KEY
)
WITH (KAFKA_TOPIC='web.mongodb.tickets', FORMAT='AVRO');
CREATE STREAM WEB_TICKETS_REKEYED
WITH (KAFKA_TOPIC='web_tickets_by_id') AS
SELECT *
FROM STREAM_WEB_TICKETS
PARTITION BY ID_TICKET->ID;
PRINT 'web_tickets_by_id' FROM BEGINNING LIMIT 1;
key: 5d0c2416b326fe00515408b8
以下成功创建了 table 但 PRIMARY KEY 值不是我所期望的:
CREATE TABLE web_tickets (
id_pk STRING PRIMARY KEY
)
WITH (KAFKA_TOPIC = 'web_tickets_by_id', VALUE_FORMAT = 'AVRO');
select id_pk from web_tickets EMIT CHANGES LIMIT 1;
|ID_PK|
|J05d0c2416b326fe00515408b8
如您所见,ID_PK 值附加了字符 JO。这是为什么?
看来我没有正确设置 KEY FORMAT。以下命令产生预期结果。
CREATE TABLE web_tickets_test_2 (
id_pk VARCHAR PRIMARY KEY
)
WITH (KAFKA_TOPIC = 'web_tickets_by_id', FORMAT = 'AVRO');
我打算创建一个名为 WEB_TICKETS 的 TABLE,其中 PRIMARY KEY 等于 key->ID 值。出于某种原因,当我 运行 CREATE TABLE 指令时,PRIMARY KEY 值附加了字符 'JO' - 为什么会这样?
KsqlDb 语句
这些按预期工作
CREATE STREAM STREAM_WEB_TICKETS (
ID_TICKET STRUCT<ID STRING> KEY
)
WITH (KAFKA_TOPIC='web.mongodb.tickets', FORMAT='AVRO');
CREATE STREAM WEB_TICKETS_REKEYED
WITH (KAFKA_TOPIC='web_tickets_by_id') AS
SELECT *
FROM STREAM_WEB_TICKETS
PARTITION BY ID_TICKET->ID;
PRINT 'web_tickets_by_id' FROM BEGINNING LIMIT 1;
key: 5d0c2416b326fe00515408b8
以下成功创建了 table 但 PRIMARY KEY 值不是我所期望的:
CREATE TABLE web_tickets (
id_pk STRING PRIMARY KEY
)
WITH (KAFKA_TOPIC = 'web_tickets_by_id', VALUE_FORMAT = 'AVRO');
select id_pk from web_tickets EMIT CHANGES LIMIT 1;
|ID_PK|
|J05d0c2416b326fe00515408b8
如您所见,ID_PK 值附加了字符 JO。这是为什么?
看来我没有正确设置 KEY FORMAT。以下命令产生预期结果。
CREATE TABLE web_tickets_test_2 (
id_pk VARCHAR PRIMARY KEY
)
WITH (KAFKA_TOPIC = 'web_tickets_by_id', FORMAT = 'AVRO');