-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Skip NULL elements in text index over Array(LowCardinality(Nullable)) #110055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alexey-milovidov
merged 3 commits into
ClickHouse:master
from
groeneai:fix-110039-text-index-array-lc-nullable
Jul 12, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
2789cb2
Skip NULL elements in text index over Array(LowCardinality(Nullable))
groeneai 6c4617b
Merge remote-tracking branch 'origin/master' into fix-110039-text-ind…
groeneai 9ff7d35
Skip NULL elements in tokenizeToArray for Array(LowCardinality(Nullab…
groeneai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/queries/0_stateless/04401_text_index_array_lowcardinality_nullable.reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| array_nullable 1 | ||
| array_lc_nullable 2 | ||
| has_hello 2 | ||
| after_optimize 2 | ||
| nested_lc_nullable 1 | ||
| materialize_lc_nullable 1 | ||
| pp_array_lc_nullable 2 | ||
| pp_has_hello 2 | ||
| pp_after_optimize 2 | ||
| pp_materialize_lc_nullable 1 |
99 changes: 99 additions & 0 deletions
99
tests/queries/0_stateless/04401_text_index_array_lowcardinality_nullable.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| -- Text index on Array(LowCardinality(Nullable(String))) must skip NULL array elements during | ||
| -- index construction, exactly as for Array(Nullable(String)). Regression test for issue #110039: | ||
| -- the array branch of the index aggregator checked isNullable(), which is false for | ||
| -- LowCardinality(Nullable), so getDataAt() was called on a NULL element and threw NOT_IMPLEMENTED | ||
| -- on INSERT / MATERIALIZE INDEX / merge. | ||
|
|
||
| SET mutations_sync = 2; | ||
|
|
||
| -- Control: Array(Nullable(String)) already works. | ||
| DROP TABLE IF EXISTS t_arr_nullable; | ||
| CREATE TABLE t_arr_nullable | ||
| ( | ||
| id UInt64, | ||
| a Array(Nullable(String)), | ||
| INDEX a_text a TYPE text(tokenizer = 'array') GRANULARITY 1 | ||
| ) | ||
| ENGINE = MergeTree ORDER BY id; | ||
| INSERT INTO t_arr_nullable VALUES (1, [NULL]); | ||
| SELECT 'array_nullable', count() FROM t_arr_nullable; | ||
|
|
||
| -- The fix: Array(LowCardinality(Nullable(String))) with a NULL element. | ||
| DROP TABLE IF EXISTS t_arr_lc_nullable; | ||
| CREATE TABLE t_arr_lc_nullable | ||
| ( | ||
| id UInt64, | ||
| a Array(LowCardinality(Nullable(String))), | ||
| INDEX a_text a TYPE text(tokenizer = 'array') GRANULARITY 1 | ||
| ) | ||
| ENGINE = MergeTree ORDER BY id; | ||
| INSERT INTO t_arr_lc_nullable VALUES (1, [NULL]); | ||
| INSERT INTO t_arr_lc_nullable VALUES (2, ['hello', NULL, 'world']); | ||
| SELECT 'array_lc_nullable', count() FROM t_arr_lc_nullable; | ||
| SELECT 'has_hello', id FROM t_arr_lc_nullable WHERE has(a, 'hello') ORDER BY id; | ||
| -- Merge/OPTIMIZE rebuilds the index; it must not wedge on the NULL element. | ||
| OPTIMIZE TABLE t_arr_lc_nullable FINAL; | ||
| SELECT 'after_optimize', count() FROM t_arr_lc_nullable; | ||
|
|
||
| -- Nested stores its field as Array(LowCardinality(Nullable(String))) (fiddle case). | ||
| DROP TABLE IF EXISTS t_nested_lc_nullable; | ||
| CREATE TABLE t_nested_lc_nullable | ||
| ( | ||
| id UInt64, | ||
| n Nested(a LowCardinality(Nullable(String))), | ||
| INDEX a_text n.a TYPE text(tokenizer = 'array') GRANULARITY 1 | ||
| ) | ||
| ENGINE = MergeTree ORDER BY id; | ||
| INSERT INTO t_nested_lc_nullable VALUES (1, [NULL]); | ||
| SELECT 'nested_lc_nullable', count() FROM t_nested_lc_nullable; | ||
|
|
||
| -- MATERIALIZE INDEX on pre-existing data must also skip NULL elements. | ||
| DROP TABLE IF EXISTS t_materialize_lc_nullable; | ||
| CREATE TABLE t_materialize_lc_nullable | ||
| ( | ||
| id UInt64, | ||
| a Array(LowCardinality(Nullable(String))) | ||
| ) | ||
| ENGINE = MergeTree ORDER BY id; | ||
| INSERT INTO t_materialize_lc_nullable VALUES (1, ['x', NULL, 'y']); | ||
| ALTER TABLE t_materialize_lc_nullable ADD INDEX a_text a TYPE text(tokenizer = 'array') GRANULARITY 1; | ||
| ALTER TABLE t_materialize_lc_nullable MATERIALIZE INDEX a_text; | ||
| SELECT 'materialize_lc_nullable', id FROM t_materialize_lc_nullable WHERE has(a, 'x') ORDER BY id; | ||
|
|
||
| -- Postprocessor variant: when a postprocessor is present, update() routes through | ||
| -- tokenizeToArray() whose array branch also checked isNullable() (false for | ||
| -- LowCardinality(Nullable)) and threw NOT_IMPLEMENTED on a NULL element. Cover | ||
| -- INSERT / MATERIALIZE INDEX / merge for Array(LowCardinality(Nullable(String))). | ||
| DROP TABLE IF EXISTS t_arr_lc_nullable_pp; | ||
| CREATE TABLE t_arr_lc_nullable_pp | ||
| ( | ||
| id UInt64, | ||
| a Array(LowCardinality(Nullable(String))), | ||
| INDEX a_text a TYPE text(tokenizer = 'splitByNonAlpha', postprocessor = lower(a)) GRANULARITY 1 | ||
| ) | ||
| ENGINE = MergeTree ORDER BY id; | ||
| INSERT INTO t_arr_lc_nullable_pp VALUES (1, [NULL]); | ||
| INSERT INTO t_arr_lc_nullable_pp VALUES (2, ['Hello', NULL, 'World']); | ||
| SELECT 'pp_array_lc_nullable', count() FROM t_arr_lc_nullable_pp; | ||
| SELECT 'pp_has_hello', id FROM t_arr_lc_nullable_pp WHERE hasAnyTokens(a, 'HELLO') ORDER BY id; | ||
| OPTIMIZE TABLE t_arr_lc_nullable_pp FINAL; | ||
| SELECT 'pp_after_optimize', count() FROM t_arr_lc_nullable_pp; | ||
|
|
||
| DROP TABLE IF EXISTS t_materialize_lc_nullable_pp; | ||
| CREATE TABLE t_materialize_lc_nullable_pp | ||
| ( | ||
| id UInt64, | ||
| a Array(LowCardinality(Nullable(String))) | ||
| ) | ||
| ENGINE = MergeTree ORDER BY id; | ||
| INSERT INTO t_materialize_lc_nullable_pp VALUES (1, ['X', NULL, 'Y']); | ||
| ALTER TABLE t_materialize_lc_nullable_pp ADD INDEX a_text a TYPE text(tokenizer = 'splitByNonAlpha', postprocessor = lower(a)) GRANULARITY 1; | ||
| ALTER TABLE t_materialize_lc_nullable_pp MATERIALIZE INDEX a_text; | ||
| SELECT 'pp_materialize_lc_nullable', id FROM t_materialize_lc_nullable_pp WHERE hasAnyTokens(a, 'x') ORDER BY id; | ||
|
|
||
| DROP TABLE t_arr_nullable; | ||
| DROP TABLE t_arr_lc_nullable; | ||
| DROP TABLE t_nested_lc_nullable; | ||
| DROP TABLE t_materialize_lc_nullable; | ||
| DROP TABLE t_arr_lc_nullable_pp; | ||
| DROP TABLE t_materialize_lc_nullable_pp; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.