ClickHouseSinkSchema

class ClickHouseSinkSchema(val type: AggregateType, val database: String, val aggregate: AggregateSinkOptions, val flatColumns: List<FlatColumn>, deduplicationWindow: Int = ClickHouseSinkOptions.DEFAULT_DEDUPLICATION_WINDOW, val accessColumns: List<ComputedColumn> = emptyList())

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 of commit_time, ordered by (tenant_id, aggregate_id, version), one row per commit (ClickHouseRows); with a TTL on commit_time when 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_mv from 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, which ARRAY JOINs the base table's events; under the same TTL.

  • <ctx>_<agg>_state_flat, a view of _state FINAL: the system columns and the flat columns _state computes (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

Link copied to clipboard
constructor(type: AggregateType, database: String, aggregate: AggregateSinkOptions, flatColumns: List<FlatColumn>, deduplicationWindow: Int = ClickHouseSinkOptions.DEFAULT_DEDUPLICATION_WINDOW, accessColumns: List<ComputedColumn> = emptyList())

Types

Link copied to clipboard

Properties

Link copied to clipboard

The access columns of _state: the built-in owner and space, then one per declared attribute (AccessColumns).

Link copied to clipboard
Link copied to clipboard

The columns _state computes, in its order: the access columns, then the flat ones.

Link copied to clipboard
Link copied to clipboard

The statements that create what is missing, in order: the tables, then the materialized views that fill them. The flat view is not among them: it is replaced only when its writers' lineage allows (flatView).

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

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).

Link copied to clipboard
Link copied to clipboard

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.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The table the Sink inserts into: the base table, or _state without the history.

Link copied to clipboard

Functions

Link copied to clipboard

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.

Link copied to clipboard

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.

Link copied to clipboard
fun flatView(lineage: FlatLineage): String

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>,….

Link copied to clipboard
fun qualified(name: String): String

name in database, quoted.

Link copied to clipboard
open override fun toString(): String