Skip to content

Commit 1dbaf80

Browse files
Merge pull request #11303 from ClickHouse/fix-index-analysis-empty-array
Fix issue #11286; add a test
2 parents 2fab952 + 8c88214 commit 1dbaf80

File tree

3 files changed

+124
-2
lines changed

3 files changed

+124
-2
lines changed

src/Storages/MergeTree/KeyCondition.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,23 @@ const KeyCondition::AtomMap KeyCondition::atom_map
181181
},
182182
{
183183
"empty",
184-
[] (RPNElement & out, const Field &)
184+
[] (RPNElement & out, const Field & value)
185185
{
186+
if (value.getType() != Field::Types::String)
187+
return false;
188+
186189
out.function = RPNElement::FUNCTION_IN_RANGE;
187190
out.range = Range("");
188191
return true;
189192
}
190193
},
191194
{
192195
"notEmpty",
193-
[] (RPNElement & out, const Field &)
196+
[] (RPNElement & out, const Field & value)
194197
{
198+
if (value.getType() != Field::Types::String)
199+
return false;
200+
195201
out.function = RPNElement::FUNCTION_NOT_IN_RANGE;
196202
out.range = Range("");
197203
return true;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
--- notEmpty
2+
['a'] 2
3+
['a','b','c'] 3
4+
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'] 4
5+
--- empty
6+
[] 1
7+
--- = []
8+
[] 1
9+
--- != []
10+
['a'] 2
11+
['a','b','c'] 3
12+
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'] 4
13+
--- > []
14+
['a'] 2
15+
['a','b','c'] 3
16+
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'] 4
17+
--- < []
18+
--- >= []
19+
[] 1
20+
['a'] 2
21+
['a','b','c'] 3
22+
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'] 4
23+
--- <= []
24+
[] 1
25+
---
26+
--- notEmpty
27+
['a'] 2
28+
['a','b','c'] 3
29+
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'] 4
30+
--- empty
31+
[] 1
32+
--- = []
33+
[] 1
34+
--- != []
35+
['a'] 2
36+
['a','b','c'] 3
37+
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'] 4
38+
--- > []
39+
['a'] 2
40+
['a','b','c'] 3
41+
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'] 4
42+
--- < []
43+
--- >= []
44+
[] 1
45+
['a'] 2
46+
['a','b','c'] 3
47+
['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'] 4
48+
--- <= []
49+
[] 1
50+
---
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
drop table if exists count_lc_test;
2+
3+
CREATE TABLE count_lc_test
4+
(
5+
`s` LowCardinality(String),
6+
`arr` Array(LowCardinality(String)),
7+
`num` UInt64
8+
)
9+
ENGINE = MergeTree
10+
ORDER BY (s, arr);
11+
12+
INSERT INTO count_lc_test(num, arr) VALUES (1,[]),(2,['a']),(3,['a','b','c']),(4,['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']);
13+
14+
SELECT '--- notEmpty';
15+
select * from count_lc_test where notEmpty(arr);
16+
SELECT '--- empty';
17+
select * from count_lc_test where empty(arr);
18+
SELECT '--- = []';
19+
select * from count_lc_test where arr = [];
20+
SELECT '--- != []';
21+
select * from count_lc_test where arr != [];
22+
SELECT '--- > []';
23+
select * from count_lc_test where arr > [];
24+
SELECT '--- < []';
25+
select * from count_lc_test where arr < [];
26+
SELECT '--- >= []';
27+
select * from count_lc_test where arr >= [];
28+
SELECT '--- <= []';
29+
select * from count_lc_test where arr <= [];
30+
SELECT '---';
31+
32+
DROP TABLE count_lc_test;
33+
34+
35+
drop table if exists count_lc_test;
36+
37+
CREATE TABLE count_lc_test
38+
(
39+
`s` LowCardinality(String),
40+
`arr` Array(String),
41+
`num` UInt64
42+
)
43+
ENGINE = MergeTree
44+
ORDER BY (s, arr);
45+
46+
INSERT INTO count_lc_test(num, arr) VALUES (1,[]),(2,['a']),(3,['a','b','c']),(4,['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa']);
47+
48+
SELECT '--- notEmpty';
49+
select * from count_lc_test where notEmpty(arr);
50+
SELECT '--- empty';
51+
select * from count_lc_test where empty(arr);
52+
SELECT '--- = []';
53+
select * from count_lc_test where arr = [];
54+
SELECT '--- != []';
55+
select * from count_lc_test where arr != [];
56+
SELECT '--- > []';
57+
select * from count_lc_test where arr > [];
58+
SELECT '--- < []';
59+
select * from count_lc_test where arr < [];
60+
SELECT '--- >= []';
61+
select * from count_lc_test where arr >= [];
62+
SELECT '--- <= []';
63+
select * from count_lc_test where arr <= [];
64+
SELECT '---';
65+
66+
DROP TABLE count_lc_test;

0 commit comments

Comments
 (0)