Get Started Free
‹ Back to courses
course: ksqlDB 101

Hands On: Splitting Two Streams with ksqlDB

2 min
Allison

Allison Walther

Integration Architect (Presenter)

Hands On: Splitting Two Streams with ksqlDB

This exercise will demonstrate how to split streams in ksqlDB.

Inspect Your Existing Data

  1. Begin by looking at the orders_combined stream from the module 9 exercise, which has orders from both the US and the UK:

    SELECT * FROM orders_combined EMIT CHANGES;

    Click Run query and see that the results contain orders from both the US and the UK.

Create New Split Streams

  1. Create a new stream to contain only orders from the US:

    CREATE STREAM us_orders AS
    SELECT * FROM orders_combined
    WHERE source = 'US';

    Click Run query.

  2. Create another new stream to contain only orders from the UK:

    CREATE STREAM uk_orders AS
    SELECT * FROM orders_combined
    WHERE source = 'UK';

    Click Run query.

Inspect Your Data Using the Flow Tab

  1. Move to the Flow tab. Click on the US_ORDERS stream. On the right-hand side, you see that the stream contains only orders from the US. Click on the UK_ORDERS stream and you see that it likewise contains only orders from the UK.

Use the promo code KSQLDB101 & CONFLUENTDEV1 to get $25 of free Confluent Cloud usage and skip credit card entry.

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.

Hands On: Splitting Two Streams with ksqlDB

Right now we're gonna work through how you would split streams. First, we'll start off by looking at an order's combined stream. This stream has orders from both the US and the UK. Go ahead and run that query. You'll see that the results, like I said, contain orders from both the US and the UK. Let's create a new stream called US orders. The purpose of this stream is to only have orders from the US. Run the query. Let's change that query to only have orders from the UK. Run that query. Now move over to the Flow tab. Go ahead and click on the US orders. On the right-hand side you'll see it only contains orders from the US. Click on the UK orders and you'll see it only has orders from the UK. And there you have it, you've split a stream.