-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sql
More file actions
40 lines (36 loc) · 1.2 KB
/
init.sql
File metadata and controls
40 lines (36 loc) · 1.2 KB
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
37
38
39
40
-- table for inserts
CREATE TABLE samples_null (
`id` String,
`name` String,
`labels` Map(String, String),
`timestamp` Int64,
`value` Float64
)
ENGINE = Null();
CREATE TABLE samples (
`id` String CODEC(ZSTD(3)),
`timestamp` Int64 CODEC(Delta(), ZSTD(3)),
`value` SimpleAggregateFunction(max, Float64) CODEC(Gorilla, ZSTD(3))
)
ENGINE = AggregatingMergeTree()
ORDER BY (id, timestamp)
PARTITION BY intDiv(timestamp,86400000)*86400000 -- 1 day in ms
SETTINGS min_age_to_force_merge_seconds = 3600, min_age_to_force_merge_on_partition_only = 1;
CREATE MATERIALIZED VIEW samples_mv TO samples AS
SELECT id, timestamp, value
FROM samples_null;
CREATE TABLE series (
`name` String,
`labels` Map(String, String),
`id` String,
`timestamp` Int64 EPHEMERAL,
`timestamp_min` SimpleAggregateFunction(min, Int64) DEFAULT `timestamp`,
`timestamp_max` SimpleAggregateFunction(max, Int64) DEFAULT `timestamp`
)
ENGINE = AggregatingMergeTree()
ORDER BY (name, id)
PARTITION BY intDiv(timestamp_min,86400000)*86400000 -- 1 day in ms
SETTINGS min_age_to_force_merge_seconds = 3600, min_age_to_force_merge_on_partition_only = 1;
CREATE MATERIALIZED VIEW series_mv TO series AS
SELECT name, labels, id, timestamp
FROM samples_null;