Skip to content

Rename unicode_word tokenizer to unicodeWord and improve docs - #99837

Merged
george-larionov merged 2 commits into
ClickHouse:masterfrom
amosbird:unicode-word-followup
Mar 20, 2026
Merged

george-larionov merged 2 commits into
ClickHouse:masterfrom
amosbird:unicode-word-followup

Conversation

@amosbird

@amosbird amosbird commented Mar 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #99357 addressing post-merge review feedback from @rschu1ze.

  • Rename unicode_word → unicodeWord for naming consistency with other tokenizers (splitByNonAlpha, ngrams, sparseGrams)
  • Add links to Unicode Text Segmentation (UAX #29) and CJK in docs
  • Rewrite stop words documentation with explicit default character list and unicodeWord([',', '。']) example
  • Add unicodeWord to valid tokenizer lists in hasAnyTokens/hasAllTokens doc strings
  • Clarify comments in ITokenizer.h: ASCII-only connectors with U+003A, CJK as single-char tokens, split validity rules for ASCII vs non-ASCII tokens
  • Add unicodeWord tests to 03403_function_tokens and 02346_text_index_creation

Changelog category (leave one):

  • Not for changelog

Changelog entry (a user-readable short description of the changes):

Not for changelog.

Version info

  • Merged into: 26.4.1.59

@clickhouse-gh

clickhouse-gh Bot commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [379ef72]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DatabaseReplicated, WasmEdge, parallel) failure
04043_system_asynchronous_inserts_user_filter FAIL cidb, issue ISSUE CREATED

AI Review

Summary

This PR renames tokenizer unicode_word to unicodeWord, updates related docs, and refreshes tests. The direction is reasonable, but there is one coverage regression: an existing negative test for invalid tokenizer-specific arguments was removed instead of being renamed. I posted one inline comment for that. Existing clickhouse-gh[bot] comments already cover other major concerns; I did not duplicate those.

Findings

⚠️ Majors

  • [tests/queries/0_stateless/04038_unicode_word_tokenizer.sql:24] An existing negative test asserting NUMBER_OF_ARGUMENTS_DOESNT_MATCH for invalid third argument to tokens was removed during rename. This weakens validation coverage and can hide regressions in argument checking.
    • Suggested fix: keep the same negative test, but rename tokenizer argument to unicodeWord.

Tests

  • ⚠️ Restore a negative test for invalid unicodeWord tokenizer arguments in tokens (equivalent to the previously covered unicode_word case) to preserve argument-validation regression protection.

ClickHouse Rules

Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ⚠️ Existing negative coverage for invalid tokenizer arguments was removed in rename-only PR.
Experimental gate ➖
No magic constants ✅
Backward compatibility ⚠️ Renaming tokenizer identifier may break existing metadata/queries unless legacy name remains accepted (already noted in existing bot thread).
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ⚠️ Rollout risk if legacy tokenizer name is not accepted at runtime.
Compilation time ✅

Final Verdict

  • Status: ⚠️ Request changes
  • Minimum required actions:
    • Restore the removed negative tokenizer-argument validation test (unicodeWord name).
    • Resolve backward-compatibility concern for legacy tokenizer name usage (unicode_word) before merge.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Mar 18, 2026
Comment thread src/Interpreters/ITokenizer.h Resolved
@amosbird
amosbird force-pushed the unicode-word-followup branch from 860fbf8 to 048382b Compare March 18, 2026 04:36
@@ -170,7 +170,7 @@ ALTER TABLE table DROP INDEX text_idx;
Compared to `ngrams(N)`, the `sparseGrams` tokenizer produces variable-length N-grams, allowing for a more flexible representation of the original text.
For example, `tokenizer = sparseGrams(3, 5, 4)` internally generates 3-, 4-, 5-grams from the input string but only the 4- and 5-grams are returned.
- `array` performs no tokenization, i.e. every row value is a token (see function [array](/sql-reference/functions/array-functions.md/#array)).
- `unicode_word` splits strings into tokens using Unicode word boundary rules (similar to UAX #29). ASCII alphanumeric characters and underscores form tokens with connectors (`:` for letters, `.` and `'` for same-type characters). Non-ASCII Unicode characters become single-character tokens. Stop words (configurable, defaults to common CJK punctuation) are skipped. An optional parameter `stop_words` can be specified as an array of strings, for example, `tokenizer = unicode_word([',', '。'])`.
- `unicodeWord` splits strings into tokens using Unicode word boundary rules (similar to [Unicode Text Segmentation (UAX #29)](https://unicode.org/reports/tr29/)). ASCII alphanumeric characters and underscores form tokens with connectors (ASCII `:` for letters, `.` and `'` for same-type characters). Non-ASCII Unicode characters, including [CJK](https://en.wikipedia.org/wiki/CJK_characters) characters, become single-character tokens. An optional parameter (for example, `tokenizer = unicodeWord([',', '。'])`) specifies character sequences that are ignored, i.e. stopwords. The default skipped characters are: `,` `。` `!` `?` `;` `:` `、` `'` `'` `"` `"` (common CJK punctuation and typographic quotation marks).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default skipped quote characters documented here do not match the implementation.

TokenizerFactory currently initializes unicodeWord stop words with typographic quotes (‘ ’ “ ”), but this line lists straight ASCII quotes (' ' " "). That is user-visible and can mislead debugging of tokenization behavior.

Please update this sentence to list the actual defaults from code (or avoid enumerating them inline and link to the source/system.tokenizers docs).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, the quotes are now the actual typographic characters (U+2018, U+2019, U+201C, U+201D).

@amosbird
amosbird force-pushed the unicode-word-followup branch from 048382b to 6f256c1 Compare March 18, 2026 05:23
@Ergus Ergus self-assigned this Mar 18, 2026

@Ergus Ergus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTm, but this requires #99834 to merged first

@amosbird

Copy link
Copy Markdown
Collaborator Author

LGTm, but this requires #99834 to merged first

Sure. We should probably get both merged before the 26.3 release.

@rschu1ze

Copy link
Copy Markdown
Member

Another minor thing I noticed: The docs have this sentence which is now no longer true:

Working with non-ASCII inputs. While text indexes can in principle be build on top of text data in any language and character set, we recommend doing so at the moment only for input in an extended ASCII character sets, i.e. Western languages. In particular, Chinese, Japanese, and Korean currently lack comprehensive indexing support, leading to potentially huge index sizes and large query times. We plan to add specialized language-specific tokenizers to handle these cases better in future. :::

@amosbird
amosbird force-pushed the unicode-word-followup branch from 6f256c1 to f7948f8 Compare March 19, 2026 07:38
@amosbird

Copy link
Copy Markdown
Collaborator Author

Updated the "Working with non-ASCII inputs" section — removed the outdated CJK warning and pointed to the unicodeWord tokenizer instead.

@amosbird
amosbird force-pushed the unicode-word-followup branch from f7948f8 to 510c2ba Compare March 19, 2026 23:58
@clickhouse-gh clickhouse-gh Bot added the submodule changed At least one submodule changed in this PR. label Mar 19, 2026
Comment thread src/Functions/tokens.cpp Outdated
{"n", "Only relevant if argument `tokenizer` is `ngrams`: An optional parameter which defines the length of the ngrams. If not set explicitly, defaults to `3`.", {"const UInt8"}},
{"separators", "Only relevant if argument `tokenizer` is `split`: An optional parameter which defines the separator strings. If not set explicitly, defaults to `[' ']`.", {"const Array(String)"}},
{"min_length", "Only relevant if argument `tokenizer` is `sparseGrams`: An optional parameter which defines the minimum gram length, defaults to 3.", {"const UInt8"}},
{"max_length", "Only relevant if argument `tokenizer` is `sparseGrams`: An optional parameter which defines the maximum gram length, defaults to 100.", {"const UInt8"}},
{"min_cutoff_length", "Only relevant if argument `tokenizer` is `sparseGrams`: An optional parameter which defines the minimum cutoff length.", {"const UInt8"}},
{"stop_words", "Only relevant if argument `tokenizer` is `unicodeWord`: An optional parameter which defines the stop words. If not set explicitly, defaults to common CJK punctuation marks.", {"const Array(String)"}},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tokens documentation now advertises unicodeWord with optional stop_words, but the resolver logic still rejects that argument.

In getReturnTypeImpl, the arguments.size() == 3 branch only permits the 3rd argument for ngrams and splitByString; unicodeWord is not handled there. So calls like tokens('x', 'unicodeWord', ['and']) still fail argument validation even though this PR adds docs/tests expecting them to work.

Please either:

  1. add unicodeWord handling in argument validation (and corresponding tokenizer-construction support), or
  2. remove stop_words from docs/tests in this PR.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed all stop_words references from this PR. Stop words support is in #99834.

@amosbird
amosbird force-pushed the unicode-word-followup branch from 510c2ba to d6e3c13 Compare March 20, 2026 00:25
@amosbird amosbird removed the submodule changed At least one submodule changed in this PR. label Mar 20, 2026
@amosbird

Copy link
Copy Markdown
Collaborator Author

@Ergus It looks like CH Inc sync requires manual intervention. Also, I noticed the 26.3 pull request is already open—would it still be possible to get this merged before the final release?

@rschu1ze

rschu1ze commented Mar 20, 2026 •

Copy link
Copy Markdown
Member

Something in the sync PR went wrong, I closed it, it will be re-created in a few minutes (theoretically).
The rest of the changes in this PR lgtm.

Follow-up to PR ClickHouse#99357 addressing post-merge review comments:
- Rename `unicode_word` to `unicodeWord` for naming consistency with other tokenizers
- Add link to Unicode Text Segmentation (UAX ClickHouse#29) spec in docs
- Add link to CJK Wikipedia article in docs
- Rewrite stop words documentation with explicit default character list
- Add `unicodeWord` to valid tokenizer lists in `hasAnyTokens`/`hasAllTokens` docs
- Clarify comments: ASCII-only connectors, CJK as single-char tokens, split validity rules
- Add `unicodeWord` tests to 03403_function_tokens and 02346_text_index_creation
…stop words removal

Revert accidental submodule pointer changes for libstemmer_c, NuRaft, and
rust_vendor that leaked in during rebase.

Update test references to reflect that stop words were removed from
unicodeWord tokenizer by PR ClickHouse#99834: fullwidth comma is now returned as a
token, and the stop-words-as-argument test case is removed.

@george-larionov george-larionov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good according to two other reviewers, I've rebased on top of the recent stop_words changes.

@clickhouse-gh

clickhouse-gh Bot commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.80% 83.80% +0.00%
Functions 24.00% 24.00% +0.00%
Branches 76.30% 76.40% +0.10%

PR changed lines: PR changed-lines coverage: 97.30% (36/37, 0 noise lines excluded)
Diff coverage report
Uncovered code

@george-larionov
george-larionov added this pull request to the merge queue Mar 20, 2026
Merged via the queue into ClickHouse:master with commit 323bf0d Mar 20, 2026
147 of 148 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants