Reading functions in the Tributary DuckDB extension
Function category
Reading
1 functionStream messages from Kafka topics into DuckDB tables. Multi-partition topics are scanned in parallel; the result is (topic, partition, offset, key, message) rows you decode in SQL.
Signature
Arguments
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
topic_name
|
Type
VARCHAR
|
Mode Positional |
Description
Kafka topic to read. Write it as kafka://<name>/<topic> to use the tributary_cluster secret scoped to kafka://<name>.
|
Argument
bootstrap.servers
|
Type
VARCHAR
|
Mode Named |
Description
Comma-separated host:port list of brokers to bootstrap from. Required unless it comes from a tributary_cluster secret.
|
Argument
group.id
|
Type
VARCHAR
|
Mode Named | Description Consumer group id passed to librdkafka. The scan reads explicit partition ranges and never commits offsets, so it doesn't move a group's position. |
Argument
security.protocol
|
Type
VARCHAR
|
Mode Named |
Description
PLAINTEXT, SSL, SASL_PLAINTEXT, or SASL_SSL. See Kafka security.
|
Argument
sasl.mechanism
|
Type
VARCHAR
|
Mode Named |
Description
SASL mechanism — PLAIN, SCRAM-SHA-256, SCRAM-SHA-512, etc. See Kafka SASL.
|
Argument
sasl.username
|
Type
VARCHAR
|
Mode Named | Description SASL username (PLAIN / SCRAM). |
Argument
sasl.password
|
Type
VARCHAR
|
Mode Named |
Description
SASL password (PLAIN / SCRAM). Keep it in a tributary_cluster secret, or pass it with getvariable() from a variable set with getenv(), rather than inlining it.
|
Argument
schema.registry.url
|
Type
VARCHAR
|
Mode Named |
Description
Schema Registry URL. When set, the latest JSON schemas of the <topic>-key and <topic>-value subjects are used to return key and value as JSON. Avro and Protobuf subjects are an error.
|
Argument
...
|
Type
VARCHAR
|
Mode Named |
Description
Varargs
Any other librdkafka global (client) property from its CONFIGURATION reference — ssl.ca.location, client.id, debug, etc. — plus schema.registry.url to decode JSON-schema topics. Names are checked when the query is bound (a misspelling is a Binder Error); topic-level properties such as auto.offset.reset are not accepted. Values pass to librdkafka unchanged.
|
Returns
A table with the following columns:
| Column | Type | Description |
|---|---|---|
Column
topic
|
Type
VARCHAR
|
Description Topic the message was read from. |
Column
partition
|
Type
INTEGER
|
Description Kafka partition id the message lives in. |
Column
offset
|
Type
BIGINT
|
Description Per-partition offset of the message. |
Column
key
|
Type
BLOB
|
Description
Raw message key, NULL when the message has none. JSON when schema.registry.url is set and the <topic>-key subject has a JSON schema.
|
Column
message
|
Type
BLOB
|
Description
Raw message payload. Use decode(message) for UTF-8 text such as JSON (not message::VARCHAR, which escapes quotes in DuckDB 2.0). When schema.registry.url is set and the <topic>-value subject has a JSON schema, this column is named value and has type JSON.
|
Description
Read messages from a Kafka topic as DuckDB rows. Multi-partition topics are scanned in parallel by partition. Each row is (topic, partition, offset, key, message); the key and message are BLOBs you decode in SQL based on your serialization (JSON, Avro, Protobuf, etc.), or JSON columns when schema.registry.url points at the topic's JSON schemas.
Each scan reads every non-empty partition from its first retained offset up to the high watermark seen when the scan started, without joining a consumer group or committing offsets. WHERE filters run after the read, so scope cost by snapshotting into a table, and use tributary_metadata first to plan the scan.
CREATE OR REPLACE TABLE orders_snapshot AS
SELECT *
FROM tributary_scan_topic('orders',
"bootstrap.servers" := 'kafka:9092');
SELECT
partition,
"offset",
json_extract_string(decode(message), '$.user_id') AS user_id,
json_extract_string(decode(message), '$.event') AS event
FROM tributary_scan_topic('events',
"bootstrap.servers" := 'kafka:9092');
CREATE SECRET prod_kafka (
TYPE tributary_cluster,
SCOPE 'kafka://prod',
"bootstrap.servers" 'broker.example.com:9093',
"security.protocol" 'SASL_SSL',
"sasl.mechanism" 'SCRAM-SHA-512',
"sasl.username" getenv('KAFKA_USER'),
"sasl.password" getenv('KAFKA_PASSWORD')
);
SELECT * FROM tributary_scan_topic('kafka://prod/orders');