Adding a sink using a template

Now that you know how to sample the queried results to the Result tab, learn how to create a sink using one of the predefined Templates to output the results of the executed SQL queries.

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.