This topic describes how to write data to one or more sinks in a job.
Example of how to write data to a sink
- Statement for creating a source table
CREATE TABLE datagen_source ( name VARCHAR, score BIGINT ) WITH ( 'connector' = 'datagen' );
- Statement for creating a result table
create table blackhole_sink( name VARCHAR, score BIGINT ) WITH ( 'connector' = 'blackhole' );
- DML statement for writing data from the source table to the result table
INSERT INTO blackhole_sink SELECT UPPER(name), score FROM datagen_source;
Example of how to write data to multiple sinks
- Statement for creating a source table
CREATE TABLE datagen_source ( name VARCHAR, score BIGINT ) WITH ( 'connector' = 'datagen' );
- Statement for creating a result table A
CREATE TABLE blackhole_sinkA( name VARCHAR, score BIGINT ) WITH ( 'connector' = 'blackhole' );
- Statement for creating a result table B
CREATE TABLE blackhole_sinkB( name VARCHAR, score BIGINT ) WITH ( 'connector' = 'blackhole' );
- DML statement for writing data from the source table to multiple result tables
In this example, data is written to two sinks.
BEGIN STATEMENT SET; -- This is required when you write data to multiple sinks. INSERT INTO blackhole_sinkA SELECT UPPER(name), sum(score) FROM datagen_source GROUP BY UPPER(name); INSERT INTO blackhole_sinkB SELECT LOWER(name), max(score) FROM datagen_source GROUP BY LOWER(name); END; -- This is required when you write data to multiple sinks.
Note The statement that writes data to multiple sinks must start with BEGIN STATEMENT SET; and end with END;.