Course: ksqlDB 101

Splitting Two Streams with ksqlDB

2 min
Allison WaltherIntegration Architect (Course Presenter)
Robin MoffattStaff Developer Advocate (Course Author)

Splitting Two Streams with ksqlDB

You can perform the inverse of merging streams with ksqlDB: you can split them. By specifying a predicate on a field in the data, you can route messages to different target streams.

Take the example of a stream of orders for all countries:

orders-for-all-countries

You may want to split these orders for country-specific processing:

orders-combined

To do this in ksqlDB, use SQL statements with appropriate predicates:

CREATE STREAM ORDERS_US AS
   SELECT * FROM ORDERS_COMBINED
   WHERE SOURCE = 'US';

CREATE STREAM ORDERS_UK AS
   SELECT * FROM ORDERS_COMBINED
   WHERE SOURCE = 'UK';

CREATE STREAM ORDERS_OTHER AS
   SELECT * FROM ORDERS_COMBINED
   WHERE SOURCE != 'US'
   AND SOURCE != 'UK';

Use the promo code KSQLDB101 to get $101 of free Confluent Cloud usage

Be the first to get updates and new content

We will only share developer content and updates, including notifications when new content is added. We will never send you sales emails. 🙂 By subscribing, you understand we will process your personal information in accordance with our Privacy Statement.