Repository navigation
Fix bug in levenshteinDistanceWeighted function - #101767
Conversation
|
Workflow [PR], commit [17443e2] Summary: ✅ AI ReviewSummaryThis PR fixes the dynamic-programming state transition in ClickHouse Rules
Final VerdictStatus: ✅ Approve |
There was a problem hiding this comment.
Pull request overview
Fixes an incorrect dynamic-programming update in the weighted Levenshtein implementation that produced wrong distances (and therefore wrong arraySimilarity) for inputs with consecutive matching elements, and adds a regression test to prevent recurrence.
Changes:
- Fix
levenshteinDistanceWeighted()to correctly advance theprev(diagonal) value on matches and to use the diagonal for substitution cost. - Add stateless SQL regression queries covering consecutive-match scenarios for both
arrayLevenshteinDistanceWeightedandarraySimilarity. - Update the corresponding
.referenceexpected output.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Common/levenshteinDistance.h |
Corrects the DP inner loop to preserve/update the diagonal (prev) properly and compute substitution from the diagonal. |
tests/queries/0_stateless/03369_function_arrayLevenshtein.sql |
Adds regression queries for consecutive matching elements (issue #101725). |
tests/queries/0_stateless/03369_function_arrayLevenshtein.reference |
Updates expected results for the new regression queries. |
|
The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix. |
LLVM Coverage Report
Changed lines: 100.00% (17/17) · Uncovered code |
| arraySimilarity(['1', '2'], ['1'], [toFloat64(1), 2], [toFloat64(1)]); | ||
| SELECT ''; | ||
|
|
||
| -- Regression test for consecutive matching elements (https://github.com/ClickHouse/ClickHouse/issues/101725) |
There was a problem hiding this comment.
We prefer adding a new test for every new found case, instead of editing existing tests.
Cherry pick #101767 to 25.8: Fix bug in levenshteinDistanceWeighted function
Backport #101767 to 26.3: Fix bug in levenshteinDistanceWeighted function
Backport #101767 to 25.8: Fix bug in levenshteinDistanceWeighted function
…ghted function
OTHER: arrayLevenshteinDistanceWeighted / arraySimilarity -> wrong. Effect in the production build a394e92: its upstream test(s) 03369_function_arrayLevenshtein fail on it and pass on official 26.8.8.8, run on isolated servers (evidence/fix_ci_20260925/upstream_repro/server_triage_PROD263_vs_UP2688.tsv). Upstream patch unchanged, with its test(s): 03369_function_arrayLevenshtein. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes bug in arrayLevenshteinDistanceWeighted and arraySilimarity functions. Closes #101725
Documentation entry for user-facing changes
Version info
26.4.1.598(included in26.4and later)26.3.17.58,25.8.29.24