Twelve composites for tables that are usually declared the same way: seven for ClickHouse and five for Postgres. Each dialect’s subpath exports only its own: ReplacingTable, EventsTable, RollupView, CdcMirror, ShardedTable, StreamIngest and OtelTables from @intentius/chant-lexicon-sql/clickhouse, and SoftDeleteTable, AuditLogTable, JoinTable, TenantTable and RefreshedView from @intentius/chant-lexicon-sql/postgres. Each is built from its dialect’s tags, so what they produce is the same kind of entity a hand-written template produces, with the same checks.
Each member becomes an entity named after the export and the member: clicksTable, clicksPerDayTable and clicksPerDayView above. Members are reached as properties of the instance (clicks.table), and a member is a reference like any entity.
Every prop except RollupView’s source is SQL text, spliced into the template the way a string interpolation is (see Declaring Tables and Views). columns is a column list as you would write it inside CREATE TABLE (...), and orderBy and partitionBy are the clause bodies. A prop that does not parse fails the build with the composite’s template line.
A ReplacingMergeTree table with a version column. ReplacingMergeTree keeps one row per sort key, and on a merge the row with the highest version wins, so writing a row again with a higher version is how an update is expressed. Until a merge runs a query sees every version; read with FINAL, or aggregate with argMax, when only the latest row matters.
An append-only MergeTree events table, partitioned by its timestamp and expired by TTL. It sets ttl_only_drop_parts = 1, so expiry drops whole parts once every row in them has expired instead of rewriting parts to remove single rows. That is cheap when the partition key and the TTL follow the same column, as they do by default.
Member
Entity
table
ClickHouse::Table, ENGINE = MergeTree with TTL <timestamp> + INTERVAL <ttlDays> DAY
Prop
Default
name
name or database.name
columns
every column except the timestamp
orderBy
the sort key; put the columns queries filter on first
timestamp
ts
the timestamp column, appended to columns; the TTL and the default partition key read it
A materialized view that rolls a source table up into a target table declared beside it. The view writes into the target with TO, so the target is an ordinary table that can be queried, altered and backfilled on its own, and dropping the view leaves the data. The view reads source by reference, so the build creates the source and the target before the view.
Member
Entity
table
ClickHouse::Table, the target
view
ClickHouse::MaterializedView, named <name>_mv, TO the target
Prop
Default
name
the target’s name
source
the table or view the rollup reads, as the entity (events, or a member such as clicks.table)
columns
the target’s columns
select
the select list; alias each item to a target column, or SQLCH110 reports it
groupBy
the grouping key
orderBy
(<groupBy>)
the target’s sort key; SummingMergeTree collapses rows that share it
A ReplacingMergeTree mirror of a table in another database, fed by change data capture (ClickPipes, Debezium through Kafka, PeerDB). The pipeline writes every change to a source row as a new row, with an increasing version and a deleted flag. With both engine arguments, ReplacingMergeTree keeps the latest version per key and drops rows whose latest version is a delete when it merges them. The current view reads the table with FINAL and leaves out deleted rows, which is what a query of the source table would have returned.
A ReplicatedMergeTree table on every node of a cluster, and the Distributed table that spreads reads and writes across it. Both are created ON CLUSTER. The local table holds each shard’s rows and replicates them within the shard; with no engine arguments it takes the server’s default replication path. The Distributed table holds no data: an insert goes to one shard by the sharding key, and a query runs on every shard and merges the results. It names the local table by reference, so the build creates the local table first.
Member
Entity
local
ClickHouse::Table, named <name>_local, ENGINE = ReplicatedMergeTree
distributed
ClickHouse::Table, named <name>, ENGINE = Distributed(<cluster>, currentDatabase(), <local>, <shardingKey>)
Prop
Default
name
unqualified: the Distributed engine names its table in the current database
cluster
the cluster both tables are created on, as the server’s remote_servers names it
The tables the OpenTelemetry Collector’s clickhouse exporter writes, with the exporter’s own columns, so the exporter can run with create_schema: false and this build owns the schema. The DDL follows the exporter’s create statements at contrib v0.130.0 (exporter/clickhouseexporter/internal/sqltemplates/*.sql), the otel lexicon’s COLLECTOR_PIN. With create_schema: true the exporter also creates a trace-id lookup table, <traces>_trace_id_ts, and a materialized view, <traces>_trace_id_ts_mv, that fills it from the traces table (createTraceTables in exporter_traces.go); both are declared unless traceIdLookup is false. The exporter’s JSON tables, used only behind its clickhouse.json feature gate, are not declared.
the lookup table and its ClickHouse::View, absent when traceIdLookup is false
Prop
Default
database
none
the exporter’s database; unset, the tables are unqualified and land in default
ttl
none
a Go duration such as 72h, rendered as the exporter renders it
tables
the exporter’s names
other names, as set on the exporter (logs, traces, gauge, sum, summary, histogram, exponentialHistogram)
traceIdLookup
true
In one build root, OTEL129 fails when a ClickHouseExporter writes a table or column this build does not declare, and warns when create_schema is true for tables it declares. Across workspace members, chant workspace check fails (WSP093) when a table the exporter writes is renamed or dropped in the sql member.
The usual ingestion chain: a stream table (Kafka, S3Queue, AzureQueue, RabbitMQ, NATS or FileLog), a materialized view that reads it, and the MergeTree target the view writes. The stream table stores no rows. It is the consumer, and the view moves each batch through it into the target with TO. The view reads the stream table by reference and writes the target by reference, so the build creates both before the view, and SQLCH110 checks that the view writes only columns the target declares.
Member
Entity
target
ClickHouse::Table, named <name>, ENGINE = MergeTree
stream
ClickHouse::Table, named <name>_stream, on the engine you give
view
ClickHouse::MaterializedView, named <name>_mv, TO the target, reading the stream table
Prop
Default
name
the target’s name
columns
the target’s columns
engine
the stream table’s engine, with a named collection as its first argument: Kafka(kafka_creds)
settings
none
the body of the stream table’s SETTINGS clause: topic list, group name, format
streamColumns
columns
the stream table’s columns when the message differs from the target’s row
select
*
the view’s select list; alias each item to a target column
orderBy
the target’s sort key
targetEngine
MergeTree
partitionBy
none
A stream table usually needs credentials. Keep them in a named collection on the server and name it as the engine’s first argument. Chant checks that the collection exists when it plans, and never reads its values (Named collections). A password written in engine or settings fails the build with SQLCH128.
A change to the stream table plans as SQLCH225, a replacement around the view, and not as a rebuild: see Stream tables. Changing kafka_group_name or an S3Queue keeper_path loses the table’s position, and the plan says so.
Every Postgres composite takes name, unqualified, and schema, the schema entity or its name (default public); the members are created in that schema. The other props are SQL text unless the table says they are entities. All five pass SQLPG101 to SQLPG126: their views set security_invoker, and none uses a feature newer than the oldest supported major. lexicons/sql/examples/postgres-composites declares all five:
A table whose rows are deleted by marking them. The composite appends created_at and updated_at (timestamptz NOT NULL DEFAULT now()) and a nullable deleted_at to the columns it is given; a row is live while deleted_at is null. <name>_live is a view of the live rows with security_invoker, so row-level security on the table applies to whoever reads the view, and a partial index on the live rows keeps lookups off the deleted ones. Postgres has no default that follows an update: the application, or a trigger it owns, sets updated_at.
Member
Entity
table
Postgres::Table
live
Postgres::View, <name>_live: SELECT * FROM <table> WHERE <deletedAt> IS NULL
liveIndex
Postgres::Index, <name>_live_idx on (<liveKey>) WHERE <deletedAt> IS NULL
Prop
Default
columns
every column except the three added, with the primary key
liveKey
id
the column the app looks rows up by
comment
says rows are soft-deleted
the table’s comment, which also answers SQLPG112 for its columns
An append-only audit log partitioned by month. The parent is PARTITION BY RANGE (<timestamp>) with columns id, the timestamp, the actor, action, subject and details jsonb, and its primary key is (id, <timestamp>), since every unique key on a partitioned table must include the partition key. A default partition takes rows no month’s partition covers yet. Each month’s partition is one more table call, PARTITION OF ${audit.table} FOR VALUES FROM (...) TO (...), made ahead of time by whatever keeps partitions.
Member
Entity
table
Postgres::Table, the partitioned parent
defaultPartition
Postgres::Table, <name>_default, PARTITION OF <table> DEFAULT
actorIndex
Postgres::Index, <name>_actor_idx on (<actor>, <timestamp> DESC)
The table of a many-to-many relation. Two foreign keys, a primary key on (<leftColumn>, <rightColumn>) that also serves lookups from the left, and a reverse index on (<rightColumn>, <leftColumn>) that serves lookups from the right and keeps a delete on the right table off a scan (SQLPG102). Both foreign keys cascade by default.
Member
Entity
table
Postgres::Table, with a created_at column
reverseIndex
Postgres::Index, <name>_reverse_idx
Prop
Default
left, right
the two tables, as entities (a member such as users.table works)
A multi-tenant table whose tenant column leads every key and index. The tenant column (NOT NULL) goes in front of the columns given, the primary key is (<tenant>, <primaryKey>), and one index covers (<tenant>, <indexOn>), so a query scoped to one tenant reads one contiguous range of each. Row-level security is separate: a policy on the table (declared with the policy tag, see Access) keeps one tenant’s role out of another’s rows.
Member
Entity
table
Postgres::Table
index
Postgres::Index, <name>_tenant_idx
Prop
Default
columns
every column except the tenant’s
primaryKey
the columns that make a row unique after the tenant
A materialized view and the unique index REFRESH MATERIALIZED VIEW CONCURRENTLY needs (SQLPG111). Without that index every refresh takes an ACCESS EXCLUSIVE lock that blocks readers. The view reads source by reference, so the build orders them and the view’s lineage names the source’s columns.
Member
Entity
view
Postgres::MaterializedView: SELECT <select> FROM <source> GROUP BY <groupBy>
uniqueIndex
Postgres::Index, <name>_key, unique on (<uniqueOn>)
When chant build interprets a composite’s factory instead of calling it, it records where each field of each member came from (see What a Composite Records About Its Fields). The tags report which fields each interpolation landed in, so for EventsTable the build knows that the table’s ttl came from the timestamp and ttlDays parameters, while its engine and its ttl_only_drop_parts setting are fixed by the composite. A drift on the TTL is then reported by chant lifecycle diff as a change to ttlDays at the call site, and a drift on the engine is refused by name. An interpolated entity or member, such as RollupView’s source, is wiring inside the composite and governs no field.
That record exists only when the factory is interpreted. Each of the ten has a body chant can interpret, and imported from @intentius/chant-lexicon-sql/clickhouse or /postgres it is: chant reads the package’s TypeScript source and follows the dialect’s barrel to the module that defines the composite (#3247). A composite that is called instead records unknown for every field it emits, and a drift on one of those fields falls back to editing the declared value. That happens when the build runs without --fold, or when the calling file falls back to run.