CREATE SINK

CREATE SINK sends data from Materialize to an external sink.

Conceptual framework 

Sinks let you stream data out of Materialize, using either sources or views.

Sink source type Description
Source Simply pass all data received from the source to the sink without modifying it.
Materialized view Stream all changes to the view to the sink. This lets you use Materialize to process a stream, and then stream the processed values. Note that this feature only works with materialized views, and does not work with non-materialized views.

Syntax 

CREATE SINK IF NOT EXISTS sink_name FROM item_name INTO KAFKA BROKER host TOPIC topic FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY url SCHEMA FILE path inline_schema
Field Use
IF NOT EXISTS If specified, do not generate an error if a sink of the same name already exists.

If not specified, throw an error if a sink of the same name already exists. (Default)
sink_name A name for the sink. This name is only used within Materialize.
item_name The name of the source or view you want to send to the sink.
KAFKA BROKER host The Kafka broker’s host name.
TOPIC topic The Kafka topic to write to.
CONFLUENT SCHEMA REGISTRY url The URL of the Confluent schema registry to get schema information from.
SCHEMA FILE path The absolute path to a file containing the schema.
SCHEMA inline_schema A string representing the schema.

Detail 

Kafka sinks 

When creating sinks, Materialize expects either:

Examples 

From sources 

CREATE SOURCE quotes
FROM KAFKA BROKER 'localhost' TOPIC 'quotes'
FORMAT AVRO USING
    CONFLUENT SCHEMA REGISTRY 'http://localhost:8081';
CREATE SINK quotes_sink
FROM quotes
INTO KAFKA BROKER 'localhost' TOPIC 'quotes-sink'
FORMAT AVRO USING
    CONFLUENT SCHEMA REGISTRY 'http://localhost:8081';

From materialized views 

CREATE SOURCE quotes
FROM KAFKA BROKER 'localhost' TOPIC 'quotes'
FORMAT AVRO USING
    CONFLUENT SCHEMA REGISTRY 'http://localhost:8081';
CREATE MATERIALIZED VIEW frank_quotes AS
    SELECT * FROM quotes
    WHERE attributed_to = 'Frank McSherry';
CREATE SINK quotes_sink
FROM frank_quotes
INTO KAFKA BROKER 'localhost' TOPIC 'frank-quotes-sink'
FORMAT AVRO USING
    CONFLUENT SCHEMA REGISTRY 'http://localhost:8081';