ksql select*from表不返回任何结果,提示没有响应

f2uvfpb9  于 2021-06-08  发布在  Kafka
关注(0)|答案(1)|浏览(487)

我正在使用kafka connect将mysql表中的行流式传输到kafka主题中。这很有效。
然后我创建一个表,其中包含:

CREATE TABLE mytable (id INT, email VARCHAR, gender VARCHAR, first_name VARCHAR, last_name VARCHAR) WITH (KAFKA_TOPIC='mysql-my-table', VALUE_FORMAT='AVRO', KEY='id');

这也很有效,我可以这样确认:

LIST TABLES; 
DESCRIBE EXTENDED mytable;

我懂了 mytable .
问题是当我执行

SELECT * FROM mytable;

然后我没有结果,提示也没有React,我只好按 ctrl+c 为了夺回控制权。
有什么问题吗?

jrcvhitl

jrcvhitl1#

经过一段时间的尝试和阅读文档,我发现了这个问题。
田野 id 因为我的主题中的消息类型是? INT 根据ksql表文档,它们必须是 VARCHAR 所以我按照这里描述的步骤来解决这个问题,现在一切正常。
具体步骤如下:

-- Create a stream on the original topic
CREATE STREAM users_with_wrong_key_format (userid INT, username VARCHAR, email VARCHAR)
WITH (KAFKA_TOPIC='users', VALUE_FORMAT='JSON');

-- Derive a new stream with the required key changes.
-- 1) The CAST statement converts the key to the required format.
-- 2) The PARTITION BY clause re-partitions the stream based on the new, converted key.
CREATE STREAM users_with_proper_key
WITH(KAFKA_TOPIC='users-with-proper-key') AS
SELECT CAST(userid as VARCHAR) as userid_string, username, email
FROM users_with_wrong_key_format
PARTITION BY userid_string;

-- Now you can create the table on the properly keyed stream.
CREATE TABLE users_table (userid_string VARCHAR, username VARCHAR, email VARCHAR)
WITH (KAFKA_TOPIC='users-with-proper-key',
        VALUE_FORMAT='JSON',
        KEY='userid_string');

-- Now you can create the table on the properly keyed stream.
CREATE TABLE users_table (userid_string VARCHAR, username VARCHAR, email VARCHAR)
WITH (KAFKA_TOPIC='users-with-proper-key',
    VALUE_FORMAT='JSON',
    KEY='userid_string');

相关问题