Skip to main content
Each model is one SQL file with a MODEL() header and one outer SELECT. StreamBuild uses the result to create a ClickHouse table and the materialized view that writes into it.
The header grammar is:
  • fields are whitespace-separated key value entries
  • lists use [...]
  • nested mappings use (...)
  • commas are optional separators and may trail the final entry
  • values containing spaces must be quoted
YAML-like key: value and {...} mappings are not accepted. MODEL (); uses all defaults.

SQL contract

The outer statement must be one SELECT. Every outer projection must:
  • be explicit rather than *
  • have a unique alias
  • declare an exact ClickHouse type with CAST(expr AS Type) AS alias or expr::Type AS alias
CTEs may contain stars, untyped expressions, and set operations. A top-level UNION, INTERSECT, or EXCEPT is rejected; wrap it in a CTE and finish with a typed projection. order_by, partition_by, and ttl expressions may reference only output columns.

Header fields

replay_on_change and bounded_replay_fallback are rejected in direct mode. replay_anchor remains valid because direct rebuilds also need replay roots.

Driving references

A model has exactly one untyped driving input:
or:
Source-root models use __source. Downstream models use __ref. Additional joins and subqueries must declare their role:
Mutable references emit a replay warning and prevent the model from being a replay anchor. Both side-reference types participate in graph scope and ordering.

Replay columns

Normalized replay columns are source-independent:
Managed Kafka landing exposes partition, offset, timestamp, and landed-at values. Adopted sources expose the roles declared in their column mapping. Preserve the columns required by the source mode through non-aggregate models when those outputs should remain eligible replay anchors. Aggregate models do not need to expose post-aggregate replay columns. StreamBuild places replay predicates on their input query instead.

Engines and duplicate delivery

Common engines include MergeTree, ReplacingMergeTree, SummingMergeTree, and AggregatingMergeTree, including replicated variants. Engine choice is part of replay correctness: the replay cutoff is inclusive, so authored SQL and storage engines must tolerate duplicate delivery where necessary.