Adding a sink using a template

So far you have sampled the results to the Console window, so the next step is to learn how to create a sink using one of the predefined Templates to output the results of the executed SQL queries.

Learning goal

  • How to use a predefined template as a sink
  • How to use multiple SQL statements in one window

Learning path

After some careful experimentation, you have executed the SELECT * FROM summaries query, stored it as a view and sampled the results to the Streaming SQL Console.

Now, the next step is to stream the aggregated records to an external system, such as Kafka. The Community Edition comes with a preconfigured Kafka container that can be selected from the predefined Templates.

The created view has a complex schema. It would be tedious to describe it, and manually create a Kafka table with a matching schema. Luckily, SQL Stream Builder can do this task automatically.

As you can add more statements in one SQL window, you can create the Kafka table and add a SELECT query at the same time.

Add the following SQL query to the SQL window, but do not execute it:
INSERT INTO output_table SELECT * FROM summaries;

As the output_table does not exists yet, you need to import the CREATE TABLE statement to the SQL window by selecting Templates > local-kafka > json. SSB automatically inserts the appropriate CREATE TABLE DDL statement before the SELECT query. Before executing the queries, you must fill out the topic in the connector option. This means you need to replace '...' in the template with 'mytopic' as it is shown in the following example:

Click on the Execute button to run the script, both statements will be executed.

Next step

At this point of the Getting Started Guide, you have learnt the workflow of running and creating a SQL job. The next step is to try out one of the main features of SQL Stream Builder: creating Materialized Views.