Ksqldb: Stream

Create a stream from Kafka Topic:

When you create a Stream it will read Kafka Topic from beginning.

CREATE STREAM `my-topic-stream` (uid STRING, amount DOUBLE) WITH (kafka_topic='my_topic', value_format='json');

Inserting into a Stream will also insert to Kafka Topic:

INSERT INTO `my-topic-stream` (uid, amount) VALUES ('123', 100.88);
INSERT INTO `my-topic-stream` (uid) VALUES ('123');
INSERT INTO `my-topic-stream` (amount) VALUES (100.88);

Inside its underlying Kafka Topic, this will insert:

{"UID":"123","AMOUNT":100.88}
{"UID":"123","AMOUNT":null}
{"UID":null,"AMOUNT":100.88}

We cannot query a Kafka Topic, but we can query a Stream:

SELECT * FROM `my-topic-stream`;

If Kafka Key maters, then create stream with KEY column:

CREATE STREAM `my-topic-stream` (id INT KEY, uid STRING, amount DOUBLE) WITH (kafka_topic='my_topic', value_format='json');

Refrences: