Click to copy

• Reviewed for ksqlDB 0.29

How to Change Key of Stream in ksqlDB

You can change the key used by a stream and its underlying Kafka topic by recreating the stream using partition by:

CREATE STREAM FLIGHTSV0 WITH (
  KAFKA_TOPIC='FLIGHTSV0', 
  PARTITIONS=10, REPLICAS=3) AS SELECT   FLIGHTS.FROM_COUNTRY FROM_COUNTRY,   FLIGHTS.FLIGHT_ID FLIGHT_ID FROM FLIGHTS FLIGHTS PARTITION BY FLIGHTS.FROM_COUNTRY EMIT CHANGES

Use cases

Most times, you will need to change the key of a stream before you join it with another stream as they need to be co-partitioned.

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