-
Notifications
You must be signed in to change notification settings - Fork 1
/
plain_caggs.ql
36 lines (31 loc) · 1.06 KB
/
plain_caggs.ql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
-- continuous aggregates for stats_aggs of the value
\set value_expr ':payload_name'
\set cagg_1m stats_agg_1m_:hypertable
\set hcagg_1h stats_agg_1h_:hypertable
\set hcagg_1d stats_agg_1d_:hypertable
\set hcagg_1m stats_agg_1M_:hypertable
CREATE MATERIALIZED VIEW :cagg_1m
WITH (timescaledb.continuous, timescaledb.materialized_only=true) AS
select time_bucket('1m', time) as bucket,
:segment,
stats_agg(:value_expr)
FROM :hypertable GROUP BY 1, 2
WITH NO DATA;
CREATE MATERIALIZED VIEW :hcagg_1h WITH (timescaledb.continuous) AS
SELECT time_bucket('1h', bucket) as bucket,
:segment,
rollup(stats_agg) AS stats_agg
FROM :cagg_1m GROUP BY 1, 2
WITH NO DATA;
CREATE MATERIALIZED VIEW :hcagg_1d WITH (timescaledb.continuous) AS
SELECT time_bucket('1d', bucket) as bucket,
:segment,
rollup(stats_agg) as stats_agg
FROM :hcagg_1h GROUP BY 1, 2
WITH NO DATA;
CREATE MATERIALIZED VIEW :hcagg_1m WITH (timescaledb.continuous) AS
SELECT time_bucket('1d', bucket) as bucket,
:segment,
rollup(stats_agg) as stats_agg
FROM :hcagg_1d GROUP BY 1, 2
WITH NO DATA;