ClickHouse/tests/queries/0_stateless/01780_column_sparse.reference
2021-06-07 18:34:22 +03:00

183 lines
3.9 KiB
Plaintext

-- { echo }
DROP TABLE IF EXISTS t_sparse;
DROP TABLE IF EXISTS t_sparse_1;
CREATE TABLE t_sparse (id UInt64, u UInt64, s String, arr1 Array(String), arr2 Array(UInt64))
ENGINE = MergeTree ORDER BY tuple()
SETTINGS ratio_of_defaults_for_sparse_serialization = 0.1;
INSERT INTO t_sparse SELECT
number,
if (number % 10 = 0, number, 0),
if (number % 5 = 0, toString(number), ''),
if (number % 7 = 0, arrayMap(x -> toString(x), range(number % 10)), []),
if (number % 12 = 0, range(number % 10), [])
FROM numbers (200);
SELECT column, serialization_kind FROM system.parts_columns
WHERE table = 't_sparse' AND database = currentDatabase()
ORDER BY column;
arr1 Default
arr2 Default
id Default
s Sparse
u Sparse
SELECT * FROM t_sparse WHERE u != 0 ORDER BY id;
10 10 10 [] []
20 20 20 [] []
30 30 30 [] []
40 40 40 [] []
50 50 50 [] []
60 60 60 [] []
70 70 70 [] []
80 80 80 [] []
90 90 90 [] []
100 100 100 [] []
110 110 110 [] []
120 120 120 [] []
130 130 130 [] []
140 140 140 [] []
150 150 150 [] []
160 160 160 [] []
170 170 170 [] []
180 180 180 [] []
190 190 190 [] []
SELECT * FROM t_sparse WHERE s != '' ORDER BY id;
0 0 0 [] []
5 0 5 [] []
10 10 10 [] []
15 0 15 [] []
20 20 20 [] []
25 0 25 [] []
30 30 30 [] []
35 0 35 ['0','1','2','3','4'] []
40 40 40 [] []
45 0 45 [] []
50 50 50 [] []
55 0 55 [] []
60 60 60 [] []
65 0 65 [] []
70 70 70 [] []
75 0 75 [] []
80 80 80 [] []
85 0 85 [] []
90 90 90 [] []
95 0 95 [] []
100 100 100 [] []
105 0 105 ['0','1','2','3','4'] []
110 110 110 [] []
115 0 115 [] []
120 120 120 [] []
125 0 125 [] []
130 130 130 [] []
135 0 135 [] []
140 140 140 [] []
145 0 145 [] []
150 150 150 [] []
155 0 155 [] []
160 160 160 [] []
165 0 165 [] []
170 170 170 [] []
175 0 175 ['0','1','2','3','4'] []
180 180 180 [] []
185 0 185 [] []
190 190 190 [] []
195 0 195 [] []
SELECT * FROM t_sparse WHERE arr1 != [] ORDER BY id;
7 0 ['0','1','2','3','4','5','6'] []
14 0 ['0','1','2','3'] []
21 0 ['0'] []
28 0 ['0','1','2','3','4','5','6','7'] []
35 0 35 ['0','1','2','3','4'] []
42 0 ['0','1'] []
49 0 ['0','1','2','3','4','5','6','7','8'] []
56 0 ['0','1','2','3','4','5'] []
63 0 ['0','1','2'] []
77 0 ['0','1','2','3','4','5','6'] []
84 0 ['0','1','2','3'] [0,1,2,3]
91 0 ['0'] []
98 0 ['0','1','2','3','4','5','6','7'] []
105 0 105 ['0','1','2','3','4'] []
112 0 ['0','1'] []
119 0 ['0','1','2','3','4','5','6','7','8'] []
126 0 ['0','1','2','3','4','5'] []
133 0 ['0','1','2'] []
147 0 ['0','1','2','3','4','5','6'] []
154 0 ['0','1','2','3'] []
161 0 ['0'] []
168 0 ['0','1','2','3','4','5','6','7'] [0,1,2,3,4,5,6,7]
175 0 175 ['0','1','2','3','4'] []
182 0 ['0','1'] []
189 0 ['0','1','2','3','4','5','6','7','8'] []
196 0 ['0','1','2','3','4','5'] []
SELECT * FROM t_sparse WHERE arr2 != [] ORDER BY id;
12 0 [] [0,1]
24 0 [] [0,1,2,3]
36 0 [] [0,1,2,3,4,5]
48 0 [] [0,1,2,3,4,5,6,7]
72 0 [] [0,1]
84 0 ['0','1','2','3'] [0,1,2,3]
96 0 [] [0,1,2,3,4,5]
108 0 [] [0,1,2,3,4,5,6,7]
132 0 [] [0,1]
144 0 [] [0,1,2,3]
156 0 [] [0,1,2,3,4,5]
168 0 ['0','1','2','3','4','5','6','7'] [0,1,2,3,4,5,6,7]
192 0 [] [0,1]
SELECT sum(u) FROM t_sparse;
1900
SELECT sum(u) FROM t_sparse GROUP BY id % 7;
210
360
300
240
190
330
270
SELECT arrayFilter(x -> x % 2 = 1, arr2) FROM t_sparse WHERE arr2 != [] LIMIT 5;
[1]
[1,3]
[1,3,5]
[1,3,5,7]
[1]
CREATE TABLE t_sparse_1 (id UInt64, v Int64)
ENGINE = MergeTree ORDER BY tuple()
SETTINGS ratio_of_defaults_for_sparse_serialization = 0;
INSERT INTO t_sparse_1 VALUES (1, 6), (2, 1), (3, 0), (4, -1), (5, 0), (6, 0), (7, -2), (8, 0), (9, 0), (10, 4), (11, 0);
SELECT * FROM t_sparse_1 ORDER BY v;
7 -2
4 -1
3 0
5 0
6 0
8 0
9 0
11 0
2 1
10 4
1 6
SELECT * FROM t_sparse_1 ORDER BY v DESC;
1 6
10 4
2 1
3 0
5 0
6 0
8 0
9 0
11 0
4 -1
7 -2
SELECT * FROM t_sparse_1 ORDER BY v, id LIMIT 5;
7 -2
4 -1
3 0
5 0
6 0
SELECT * FROM t_sparse_1 ORDER BY v DESC, id LIMIT 5;
1 6
10 4
2 1
3 0
5 0
DROP TABLE t_sparse;
DROP TABLE t_sparse_1;