Streams
A stream is a Kafka broker that event hooks read, and its records are declared like the rows of a table.
SOURCE_STREAM('kafka://<host:port>[,<host:port>…]' WITH (FORMAT = 'json' [, <property> = <value> …]))
EXTERNAL_COLUMNS(<column> <type>, … FROM TABLE(<stream>[<topic>])) SOURCE_STREAM()declares the broker.EXTERNAL_COLUMNS(… FROM TABLE(<stream>[<topic>]))declares the records of one topic, each column with its type.- A record is never looked up, so its columns take no
BIND TO. - A topic name with dots or hyphens is written bare:
TABLE(STREAM[payments.v1]),TABLE(STREAM[prod-payments]). - An event hook fires on each record and reads its fields through an alias:
ON PAYMENTS AS p, thenp[amount]( Hooks ).
Records
FORMAT = 'json' is the one format decoded. A record's value is a JSON object, read by these rules:
| A record's | Is read |
|---|---|
| field names | against the declared columns, by name, ignoring case. Of two fields that differ only by case (Amount, amount), the last in the object is kept. Fields not declared are ignored |
missing or null field | as NULL, and the record still decodes. What the NULL does depends on where it lands ( A NULL field ) |
ROW and ARRAY columns | as declared: card ROW<brand VARCHAR, fee DECIMAL(10, 2)>, items ARRAY<ROW<sku VARCHAR, price DECIMAL(10, 2)>>, read with p[card][brand]. Top-level names match ignoring case. Fields inside a ROW match exactly |
TIMESTAMP field | from an ISO 8601 string ("2026-11-25T10:00:00.250"), read as UTC, or from a number in the column's unit (milliseconds for TIMESTAMP(3)). A string with an offset or Z ("2026-11-25T11:00:00+01:00") is converted to UTC |
DECIMAL field | from a JSON number or a numeric string ("7.50"), exactly from its text, never through a floating-point number. It is brought to the column's scale as CAST does, half away from zero: 1.005 in a DECIMAL(10, 2) is 1.01, and -1.005 is -1.01. A value with more integer digits than the column holds does not decode |
A record that does not decode is a data error, HOOK-RECORD-DECODE. That covers a value that is not JSON or not an object, a Kafka tombstone (a record whose value is null), and a value that does not read as its column's type, such as "abc" for a number. The record is counted, sampled and skipped. It writes nothing and removes nothing, and its offset is committed ( Delivery and failures ).
Reserved fields
Every record also carries five fields, as every source read carries source_status:
| Field | Type | Holds |
|---|---|---|
record_key | VARCHAR | the record's key. NULL for a record without a key. Bytes that are not UTF-8 are replaced by U+FFFD, so two binary keys can read alike |
record_time | TIMESTAMP(3) | the Kafka timestamp. A record without one gets the consumer's clock when it is read |
record_partition | INTEGER | the partition |
record_offset | BIGINT | the offset |
record_headers | ARRAY<ROW<name VARCHAR, value VARCHAR>> | the headers in the record's order, duplicates kept. A value that is not UTF-8 reads as NULL |
WHERE and USING read them as any field: p[record_headers]. Declaring one of these names is refused (UE/STREAM-RECORD-RESERVED-FIELD). A payload field of that name is ignored: the record's own value wins.
A record without a Kafka timestamp takes the consumer's clock as its time. Replayed later, it gets a new, later time, and its writes replace values of newer events ( Which write lands ).
Connections
A broker that needs authentication or TLS says so in WITH:
| Property | Takes |
|---|---|
SECURITY_PROTOCOL | 'plaintext' (the default), 'ssl', 'sasl_plaintext' or 'sasl_ssl' |
SASL_MECHANISM | 'plain', 'scram-sha-256' or 'scram-sha-512'. Required with a SASL protocol |
USERNAME, PASSWORD | the SASL user and its password. Required with a SASL protocol |
SSL_CA | the path of the CA bundle that signed the broker's certificate. Without it, TLS trusts the system's roots (librdkafka probes the standard CA paths). The broker's host name is always checked against its certificate |
SSL_CERTIFICATE, SSL_KEY, SSL_KEY_PASSWORD | a client certificate and its key, for brokers that authenticate clients by TLS |
CREATE OR REPLACE FEATURES IN FM.TUTORIALS.HOOK_REF AS
PERSIST
secure_stream := SOURCE_STREAM(
'kafka://broker:9093'
WITH (
FORMAT = 'json',
SECURITY_PROTOCOL = 'sasl_ssl',
SASL_MECHANISM = 'scram-sha-512',
USERNAME = 'hooks',
PASSWORD = SECRET('env', 'KAFKA_PASSWORD'),
SSL_CA = '/etc/kafka/ca.crt'
)
)
;| feature_name VARCHAR | status VARCHAR | message VARCHAR |
|---|---|---|
| FM.TUTORIALS.HOOK_REF.SECURE_STREAM | CREATED | Feature created as not exists |
Any property can be a SECRET(), and a password should be. When featuremeshd reads a stream's secrets, and what a password written in clear does, is in Credentials .
Properties go with their protocol. SASL properties need a SASL protocol, TLS properties a TLS one, and a client key comes with its certificate:
CREATE OR REPLACE FEATURE FM.TUTORIALS.HOOK_REF.BAD AS SOURCE_STREAM('kafka://broker:9093' WITH (FORMAT = 'json', SECURITY_PROTOCOL = 'ssl', USERNAME = 'hooks', PASSWORD = SECRET('env', 'KAFKA_PASSWORD')));The consumer's other librdkafka settings come from featuremeshd's configuration, and the stream's own properties win over them ( Consumer settings ).
Related
- Hooks : the event hook that reads a stream.
- Delivery and failures : what a decode error and a
NULLfield do. - Configure featuremeshd : consumer groups and offsets.
- Limits : formats and brokers that are not read.