Skip to main content
A table-valued function (TVF) that reads data from a Kafka stream. READ_STREAM returns a table with columns defined by the stream’s schema, along with metadata pseudo-columns such as $offset, $partition_id, and $timestamp. READ_STREAM works with a managed stream object that tracks consumer offsets. When consume is set to true (the default), Firebolt advances the stream’s offsets after reading, so subsequent reads only return new messages.

Prerequisites

Before using READ_STREAM, you need:
  1. A Kafka location that stores connection details for your Kafka cluster:
  1. A stream object that defines the schema and binds to a Kafka topic:
See CREATE STREAM for the full reference.

Syntax

Parameters

Setting consume to true (the default) makes the query a write operation. Read-only queries, such as standalone SELECT statements outside of CREATE TABLE AS SELECT or INSERT INTO ... SELECT, cannot consume from a stream. Either set consume => false or use READ_STREAM inside a write statement.

Return type

The result is a table whose columns match the stream’s schema, plus the following pseudo-columns: Pseudo-columns are not included in SELECT * by default — reference them explicitly (for example, SELECT $offset, $partition_id, * FROM ...).

Stream types

The TYPE parameter on the stream controls how raw Kafka messages are parsed:

Consumer offsets

Firebolt tracks consumer offsets per partition for each stream object. You can inspect offsets through information_schema.streams:
To manually reposition a stream’s offset on a specific partition, use ALTER STREAM:

Examples

Read without consuming

Preview the latest unconsumed messages from a stream without advancing offsets:

Ingest into a managed table

Consume messages from the stream and insert them into a Firebolt table in a single statement:
After this statement, the stream’s offsets advance past the consumed messages. Running the same query again returns only messages that arrived after the previous read.

Incremental ingestion

Append new messages to an existing table:

Filter and transform

Apply SQL transformations on the stream data before loading. For a RAW_TEXT stream, you can parse fields from the raw message:

Use pseudo-columns

Access Kafka metadata alongside your data:

Limit messages per partition

Control how many messages are read from each Kafka partition: