Click to copy

• Reviewed for ksqlDB 0.29

How to Create an Empty Stream in ksqlDB

REMEMBER - You can create streams by either importing existing topics as streams, by creating empty streams, or by querying other streams.

This is an example of creating a new stream:

CREATE STREAM flights (
  flight_id STRING KEY,
  from_country STRING,
  to_country STRING,
  departed_at TIMESTAMP
) WITH (
  KAFKA_TOPIC = 'flights',
  PARTITIONS = 10,
  VALUE_FORMAT = 'JSON',
  KEY_FORMAT = 'KAFKA'
);

In addition to the new stream, a new Apache Kafka topic named flights will be created as well.

Required stream properties

The PARTITIONS stream property is required when creating a stream from a non-existing topic. If you forget it, you will get this error:

Topic 'flights' does not exist. If you want to create a new topic for the stream/table please re-run the statement providing the required 'PARTITIONS' configuration in the WITH clause (and optionally 'REPLICAS')
Discover what readers are saying
topictale
Get easy to digest how-tos on ksqlDB
Sign up
Please read our Privacy Policy to understand how we protect and manage your data.
You may also like