Click to copy
Streams • 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
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.
Was this article helpful?