Run a SQL job that reads JSON records from one Kafka topic, filters them, and writes
the result to another topic.
- The Kafka brokers are reachable from your deployment. For the Kafka clusters that a
deployment can reach, see Kafka clusters that you can connect to.
- The
orders and large_orders topics exist.
- If the brokers require authentication, see Configuring Kafka
authentication.
-
In the Streaming SQL Console, click Projects in the left
navigation pane, and click the name of your project.
The project opens, with the Explorer panel on the left.
To open the Streaming SQL Console, see Accessing Cloudera SQL Stream Builder.
-
In the Explorer, open the menu of Jobs,
and click New Job.
The Create New Job window opens.
-
Enter a Job Name, or click Generate Job
Name.
-
Click Create.
The job opens in a new tab, with an empty SQL editor.
-
Enter the following statements in the SQL editor:
CREATE TABLE orders (
order_id INT,
amount DOUBLE,
order_time TIMESTAMP(3),
WATERMARK FOR order_time AS order_time - INTERVAL '5' SECOND
) WITH (
'connector' = 'kafka',
'topic' = 'orders',
'properties.bootstrap.servers' = '<broker-host>:<port>',
'properties.group.id' = 'ssb-getting-started',
'scan.startup.mode' = 'earliest-offset',
'format' = 'json'
);
CREATE TABLE large_orders_kafka (
order_id INT,
amount DOUBLE,
order_time TIMESTAMP(3)
) WITH (
'connector' = 'kafka',
'topic' = 'large_orders',
'properties.bootstrap.servers' = '<broker-host>:<port>',
'format' = 'json'
);
INSERT INTO large_orders_kafka
SELECT order_id, amount, order_time
FROM orders
WHERE amount > 100;
Replace <broker-host>:<port> with the address of your
Kafka brokers.
-
Click the Execute job icon.
The job starts and runs until you stop it.
-
Read the
large_orders topic with a Kafka consumer to check the
output.
Records appear in the topic as matching records arrive in the
orders topic. If the source topic receives no data, the sink topic
stays empty.
-
When you finish, click Stop job.
To define Kafka tables without typing the connection properties in each statement,
register a Kafka data source and use the table wizard. See Adding a Kafka data
source and Creating Kafka tables with the wizard.