ClickHouseSinkSchema
The tables and views of one aggregate type, in database, named after the type (<ctx>_<agg>, prefixOf):
<ctx>_<agg>_state_events, the base table the Sink inserts into: a ReplacingMergeTree partitioned by the month ofcommit_time, ordered by(tenant_id, aggregate_id, version), one row per commit (ClickHouseRows); with a TTL oncommit_timewhen AggregateSinkOptions.historyTtl is set.<ctx>_<agg>_state, a ReplacingMergeTree(version) ordered by(tenant_id, aggregate_id), the current state: filled by the materialized view<ctx>_<agg>_state_mvfrom the base table, with the base table's columns but the events and the headers, which the history keeps (STATE_COLUMNS); and the columns ClickHouse computes from them when a row is inserted (computed): an access column per access attribute (accessColumns), then a flat column per top-level scalar of the state (flatColumns), each with its fingerprint in its comment.<ctx>_<agg>_events, a ReplacingMergeTree ordered by(tenant_id, aggregate_id, version, event_index), one row per event: filled by<ctx>_<agg>_events_mv, whichARRAY JOINs the base table'sevents; under the same TTL.<ctx>_<agg>_state_flat, a view of_state FINAL: the system columns and the flat columns_statecomputes (FlatColumns); its definition's flatFingerprint and those of the writers before it are kept in its comment (FlatLineage), so that during a rolling upgrade an older writer leaves a newer writer's view as it is.
Without the history (AggregateSinkOptions.history false) only _state and _state_flat exist, and the Sink inserts into _state directly (target).
Every table and view carries the format of the Sink's tables in its comment (FORMAT_COMMENT, wow-sink-format:1), which the Sink checks before it writes: a table or view without it is not the Sink's (hasFormat).
Every table remembers the last deduplicationWindow insert blocks (non_replicated_deduplication_window), so an insert retried with the same token is dropped from the base table and, the inserts setting deduplicate_blocks_in_dependent_materialized_views, from the views' tables too. Beyond that window (a replay from an earlier checkpoint, an old owner beside the new one, a batch made up differently), the history tables' ReplacingMergeTree engine, keyed by ref@version (and the event's index in its commit), merges a replayed row away: a read with FINAL counts every commit and event once.
Constructors
Properties
The access columns of _state: the built-in owner and space, then one per declared attribute (AccessColumns).
The columns _state computes, in its order: the access columns, then the flat ones.
What Ddl.VALIDATE checks: every table and view with its columns, the materialized views by name; each of them with the format in its comment (hasFormat).
The fingerprint of the flat view's definition: the first 16 hex digits of the SHA-256 of its SELECT, its database aside, so that every writer of the same state schema has the same.
Functions
The statements that add the computed columns missing to _state, each after the column before it in computed's order (the stored columns' last for the first), so that the table lists its columns as a table created with them would. Metadata only: a part written before is computed when it is read, until it is merged.
The statements that add the stored columns lacking, which Wow added within the format, to table, each with its default (ClickHouseColumn.added): metadata only, a part written before reads the default until it is merged.
The statement that creates or replaces the flat view, its comment the format and the writers' lineage, this one's last: wow-sink-format:1 wow-sink-flat:<fingerprint>,….