
Unlock this content
Enter your email to unlock this content for free
How Matviews Work
TL;DR
Materialized views are insert triggers that process data in blocks. Each block inserted into the source table triggers the materialized view query, which only sees that block (not historical data). Results are written as separate parts that ClickHouse merges in the background. With AggregatingMergeTree, merges aggregate data based on the sorting key.
Example: tracking sales by product.
Source datasource (datasources/sales.datasource):
DESCRIPTION >
Sales events datasource
SCHEMA >
`product_id` String `json:$.product_id`,
`quantity` UInt32 `json:$.quantity`,
`timestamp` DateTime `json:$.timestamp`