Sniper007
Sniper007

Reputation: 65

KSQL table not showing data but Stream with same structure returning data

I have created a table in KSQL, while querying it's not returning any data. Then I created a stream on the same topic with same structure and I am able to query the data.

What am I missing here. I need this as a table for joining with a stream.

CREATE TABLE users_table \
(registertime bigint, userid varchar, regionid varchar, gender varchar) \
WITH (value_format='json', kafka_topic='users_topic',key='userid');

and

CREATE STREAM users_stream \
(registertime bigint, userid varchar, regionid varchar, gender varchar) \
 WITH (value_format='json', kafka_topic='users_topic');

Thanks in advance.

Upvotes: 4

Views: 2140

Answers (1)

Matthias J. Sax
Matthias J. Sax

Reputation: 62330

If you read a topic as a TABLE the messages in the topic must have the key set. If the key is null, records will be dropped silently. A key in a KSQL TABLE is a primary key and null is no valid value for a primary key.

Furthermore, the value in the message of the key attribute, must be the same as the key (note, that the schema itself is define on the value of the message). For example, if you have a schema, <A,B,C> and you set A as the key, the messages in the topic must be <key,value> == <a,<a,b,c>>. Otherwise, you will get incorrect results.

Upvotes: 8

Related Questions