diff --git a/cameleer3-server-app/src/main/resources/clickhouse/07-stats-rollup.sql b/cameleer3-server-app/src/main/resources/clickhouse/07-stats-rollup.sql index 2c70890b..5d1efe24 100644 --- a/cameleer3-server-app/src/main/resources/clickhouse/07-stats-rollup.sql +++ b/cameleer3-server-app/src/main/resources/clickhouse/07-stats-rollup.sql @@ -2,11 +2,15 @@ -- Uses AggregatingMergeTree with -State/-Merge combinators so intermediate -- aggregates can be merged across arbitrary time windows and dimensions. -CREATE TABLE IF NOT EXISTS route_execution_stats_5m ( +-- Drop existing objects to allow schema changes (MV must be dropped before table) +DROP VIEW IF EXISTS route_execution_stats_5m_mv; +DROP TABLE IF EXISTS route_execution_stats_5m; + +CREATE TABLE route_execution_stats_5m ( bucket DateTime('UTC'), route_id LowCardinality(String), agent_id LowCardinality(String), - total_count AggregateFunction(count, UInt64), + total_count AggregateFunction(count), failed_count AggregateFunction(countIf, UInt8), duration_sum AggregateFunction(sum, UInt64), p99_duration AggregateFunction(quantileTDigest(0.99), UInt64) @@ -17,7 +21,7 @@ ORDER BY (agent_id, route_id, bucket) TTL bucket + toIntervalDay(30) SETTINGS ttl_only_drop_parts = 1; -CREATE MATERIALIZED VIEW IF NOT EXISTS route_execution_stats_5m_mv +CREATE MATERIALIZED VIEW route_execution_stats_5m_mv TO route_execution_stats_5m AS SELECT toStartOfFiveMinutes(start_time) AS bucket,