-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_app_data_model.cql
120 lines (106 loc) · 3.92 KB
/
demo_app_data_model.cql
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
CREATE KEYSPACE IF NOT EXISTS iot
WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };
CREATE TABLE IF NOT EXISTS iot.sensor_metadata (
vendor_id text,
sensor_id text,
manufacture_date timestamp,
deployment_date timestamp,
maintenance_history text,
retirement_date timestamp,
sensor_type text,
floor text,
wing text,
hive text,
geolocation text,
PRIMARY KEY ((sensor_id), sensor_type, hive, wing, floor, geolocation)
);
CREATE MATERIALIZED VIEW IF NOT EXISTS iot.sensor_by_location_by_hive AS
SELECT sensor_id FROM sensor_metadata
WHERE sensor_id IS NOT NULL AND
vendor_id IS NOT NULL AND
manufacture_date IS NOT NULL AND
deployment_date IS NOT NULL AND
maintenance_history IS NOT NULL AND
retirement_date IS NOT NULL AND
sensor_type IS NOT NULL AND
floor IS NOT NULL AND
wing IS NOT NULL AND
hive IS NOT NULL AND
geolocation IS NOT NULL
PRIMARY KEY (hive, wing, floor, sensor_id, sensor_type, geolocation)
WITH CLUSTERING ORDER BY (wing ASC, floor ASC, sensor_id ASC);
CREATE MATERIALIZED VIEW IF NOT EXISTS iot.sensor_by_location_by_type AS
SELECT sensor_id FROM sensor_metadata
WHERE sensor_id IS NOT NULL AND
vendor_id IS NOT NULL AND
manufacture_date IS NOT NULL AND
deployment_date IS NOT NULL AND
maintenance_history IS NOT NULL AND
retirement_date IS NOT NULL AND
sensor_type IS NOT NULL AND
floor IS NOT NULL AND
wing IS NOT NULL AND
hive IS NOT NULL AND
geolocation IS NOT NULL
PRIMARY KEY (sensor_type, sensor_id, hive, wing, floor, geolocation)
WITH CLUSTERING ORDER BY (sensor_id ASC);
CREATE MATERIALIZED VIEW IF NOT EXISTS iot.sensor_by_sensor_id AS
SELECT sensor_id FROM sensor_metadata
WHERE sensor_id IS NOT NULL AND
vendor_id IS NOT NULL AND
manufacture_date IS NOT NULL AND
deployment_date IS NOT NULL AND
maintenance_history IS NOT NULL AND
retirement_date IS NOT NULL AND
sensor_type IS NOT NULL AND
floor IS NOT NULL AND
wing IS NOT NULL AND
hive IS NOT NULL AND
geolocation IS NOT NULL
PRIMARY KEY (sensor_id, hive, wing, floor, sensor_type, geolocation)
WITH CLUSTERING ORDER BY (hive ASC, wing ASC, floor ASC, sensor_type ASC);
CREATE MATERIALIZED VIEW IF NOT EXISTS iot.sensor_by_geolocation AS
SELECT sensor_id FROM sensor_metadata
WHERE sensor_id IS NOT NULL AND
vendor_id IS NOT NULL AND
manufacture_date IS NOT NULL AND
deployment_date IS NOT NULL AND
maintenance_history IS NOT NULL AND
retirement_date IS NOT NULL AND
sensor_type IS NOT NULL AND
floor IS NOT NULL AND
wing IS NOT NULL AND
hive IS NOT NULL AND
geolocation IS NOT NULL
PRIMARY KEY (geolocation, hive, wing, floor, sensor_type, sensor_id)
WITH CLUSTERING ORDER BY (hive ASC, wing ASC, floor ASC, sensor_type ASC);
CREATE TABLE IF NOT EXISTS iot.sensor_stat_tw30_sw1 (
sensor_id text,
isActive boolean,
reading_time timestamp,
min_temperature float,
max_temperature float,
avg_temperature float,
min_humidity float,
max_humidity float,
avg_humidity float,
min_movement float,
max_movement float,
avg_movement float,
PRIMARY KEY ((sensor_id), reading_time)
) WITH CLUSTERING ORDER BY (reading_time DESC);
CREATE TABLE IF NOT EXISTS iot.daily_rollup (
sensor_id text,
date timestamp,
isActive boolean,
min_temperature float,
max_temperature float,
avg_temperature float,
min_humidity float,
max_humidity float,
avg_humidity float,
min_movement float,
max_movement float,
avg_movement float,
PRIMARY KEY ((sensor_id), date )
) WITH CLUSTERING ORDER BY (date DESC);