KSQL select * from table不返回结果并且提示没有响应

时间:2018-07-20 11:52:57

标签: apache-kafka apache-kafka-connect ksql

我正在使用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;

然后我没有结果,并且提示没有响应,我必须按ctrl+c才能重新获得控制权。

可能是什么问题?

1 个答案:

答案 0 :(得分:0)

经过一段时间尝试不同的操作并阅读文档后,我发现了问题。

我的主题中消息的字段id的类型? INT,根据KSQL TABLES文档,它们的类型必须为VARCHAR

因此,我按照here所述的步骤进行了修复,现在一切正常。

因此,步骤如下:

-- 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');