-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_clickhouse_ddl.sql
198 lines (179 loc) · 3.83 KB
/
example_clickhouse_ddl.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
CREATE TABLE test.felix
(
`id` Int32 DEFAULT 100
)
ENGINE = MergeTree
PRIMARY KEY id
ORDER BY id
SETTINGS index_granularity = 8192;
CREATE TABLE test.my_first_table
(
`user_id` UInt32,
`message` String,
`timestamp` DateTime,
`metric` Float32
)
ENGINE = MergeTree
PRIMARY KEY (user_id, timestamp)
ORDER BY (user_id, timestamp)
SETTINGS index_granularity = 8192;
CREATE TABLE test.nullable
(
`n` Nullable(UInt32)
)
ENGINE = MergeTree
ORDER BY tuple()
SETTINGS index_granularity = 8192;
CREATE TABLE test.stock
(
`s_i_id` Int32,
`s_w_id` Int32,
`s_quantity` Nullable(Int32),
`s_dist_01` Nullable(String) DEFAULT NULL
)
ENGINE = MergeTree
PRIMARY KEY (s_w_id, s_i_id)
ORDER BY (s_w_id, s_i_id)
SETTINGS index_granularity = 8192;
CREATE TABLE test.users_a
(
`uid` Int16,
`name` String,
`age` Int16,
`name_len` UInt8 MATERIALIZED length(name),
CONSTRAINT c1 ASSUME length(name) = name_len
)
ENGINE = MergeTree
ORDER BY (name_len, name)
SETTINGS index_granularity = 8192;
CREATE TABLE test.yy
(
`name` FixedString(10)
)
ENGINE = MergeTree
PRIMARY KEY name
ORDER BY name
SETTINGS index_granularity = 8192;
CREATE TABLE test.zz
(
`name` String
)
ENGINE = MergeTree
PRIMARY KEY name
ORDER BY name
SETTINGS index_granularity = 8192;
CREATE TABLE sherry.asynchronous_inserts
(
`query` String,
`database` String,
`table` String,
`format` String,
`first_update` DateTime64(6),
`total_bytes` UInt64,
`entries.query_id` Array(String),
`entries.bytes` Array(UInt64)
)
ENGINE = MergeTree
ORDER BY query
SETTINGS index_granularity = 8192;
CREATE TABLE sherry.certificates
(
`version` Int32,
`serial_number` Nullable(String),
`signature_algo` Nullable(String),
`issuer` Nullable(String),
`not_before` Nullable(String),
`not_after` Nullable(String),
`subject` Nullable(String),
`pkey_algo` Nullable(String),
`path` String,
`default` UInt8
)
ENGINE = MergeTree
PRIMARY KEY version
ORDER BY version
SETTINGS index_granularity = 8192;
CREATE TABLE sherry.dt
(
`timestamp` DateTime('Asia/Istanbul'),
`event_id` UInt8
)
ENGINE = TinyLog;
CREATE TABLE sherry.dt64
(
`timestamp` DateTime64(3, 'Asia/Istanbul'),
`event_id` UInt8
)
ENGINE = TinyLog;
CREATE TABLE sherry.float_vs_decimal
(
`my_float` Float64,
`my_decimal` Decimal(18, 3)
)
ENGINE = MergeTree
ORDER BY tuple()
SETTINGS index_granularity = 8192;
CREATE TABLE sherry.json
(
`o` Object('json')
)
ENGINE = Memory;
CREATE TABLE sherry.order_info
(
`oid` UInt64,
`buyer_nick` String,
`seller_nick` String,
`payment` Decimal(18, 4),
`order_status` UInt8,
`gmt_order_create` DateTime,
`gmt_order_pay` DateTime,
`gmt_update_time` DateTime,
INDEX oid_idx oid TYPE minmax GRANULARITY 32,
INDEX idx_seller_nick seller_nick TYPE minmax GRANULARITY 1,
INDEX idx_seller_nick_order_status (seller_nick, order_status) TYPE minmax GRANULARITY 1
)
ENGINE = MergeTree
PARTITION BY toYYYYMMDD(gmt_order_create)
PRIMARY KEY (seller_nick, gmt_order_create)
ORDER BY (seller_nick, gmt_order_create, oid)
SETTINGS index_granularity = 8192;
CREATE TABLE sherry.secondary
(
`oid` UInt64,
`buyer_nick` String,
`order_status` UInt8,
INDEX order_status_idx order_status TYPE minmax GRANULARITY 32
)
ENGINE = MergeTree
PRIMARY KEY oid
ORDER BY oid
SETTINGS index_granularity = 8192;
CREATE TABLE sherry.t_enum
(
`x` Enum8('hello' = 1, 'world' = 2)
)
ENGINE = TinyLog;
CREATE TABLE sherry.test_bool
(
`A` Int64,
`B` Bool
)
ENGINE = Memory;
CREATE TABLE sherry.visits
(
`VisitDate` Date,
`Hour` UInt8,
`ClientID` UUID
)
ENGINE = MergeTree
PARTITION BY toYYYYMM(VisitDate)
ORDER BY Hour
SETTINGS index_granularity = 8192;
CREATE TABLE sherry.was
(
`name` String
)
ENGINE = MergeTree
PRIMARY KEY name
ORDER BY name
SETTINGS index_granularity = 8192;