-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclickhouse.sql
112 lines (81 loc) · 2.62 KB
/
clickhouse.sql
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
CREATE DATABASE IF NOT EXISTS helloworld
CREATE TABLE helloworld.my_first_table
(
user_id UInt32,
message String,
timestamp DateTime,
metric Float32
) \
ENGINE = MergeTree() \
PRIMARY KEY (user_id, timestamp) \
INSERT INTO helloworld.my_first_table (user_id, message, timestamp, metric) \ VALUES
(101, 'Hello, ClickHouse!', now() \, -1.0 ) \,
(102, 'Insert a lot of rows per batch', yesterday() \, 1.41421 ) \,
(102, 'Sort your data based on your commonly-used queries', today() \, 2.718 ) \,
(101, 'Granules are the smallest chunks of data read', now() \ + 5, 3.14159 ) \
SELECT * FROM helloworld.my_first_table
SELECT *
FROM helloworld.my_first_table
ORDER BY timestamp
FORMAT TabSeparated
https://storage.googleapis.com/covid19-open-data/v3/epidemiology.csv
DESCRIBE s3(
'http://minio:9000/raw/covid/epidemiology.csv', 'datalake', 'datalake', 'CSVWithNames') \
SELECT *
FROM
s3(
'http://minio:9000/raw/covid/epidemiology.csv', 'datalake', 'datalake',
CSVWithNames,
'date Date,
location_key LowCardinality(String) \,
new_confirmed Int32,
new_deceased Int32,
new_recovered Int32,
new_tested Int32,
cumulative_confirmed Int32,
cumulative_deceased Int32,
cumulative_recovered Int32,
cumulative_tested Int32'
) \;
CREATE TABLE covid19 (
date Date,
location_key LowCardinality(String) \,
new_confirmed Int32,
new_deceased Int32,
new_recovered Int32,
new_tested Int32,
cumulative_confirmed Int32,
cumulative_deceased Int32,
cumulative_recovered Int32,
cumulative_tested Int32
) \
ENGINE = MergeTree
ORDER BY (location_key, date) \;
INSERT INTO covid19
SELECT *
FROM
s3(
'http://minio:9000/raw/covid/epidemiology.csv', 'datalake', 'datalake',
CSVWithNames,
'date Date,
location_key LowCardinality(String) \,
new_confirmed Int32,
new_deceased Int32,
new_recovered Int32,
new_tested Int32,
cumulative_confirmed Int32,
cumulative_deceased Int32,
cumulative_recovered Int32,
cumulative_tested Int32'
) \;
SELECT formatReadableQuantity(count() \) \
FROM covid19;
SELECT formatReadableQuantity(sum(new_confirmed) \) \
FROM covid19;
SELECT
AVG(new_confirmed) \ OVER (PARTITION BY location_key ORDER BY date ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING) \ AS cases_smoothed,
new_confirmed,
location_key,
date
FROM covid19;
SELECT * FROM system.parts WHERE table='minio'