[FLINK-40148][common] Fix TableIdRouter producing wrong sink table for multi-digit source suffix#4473
Open
sd4324530 wants to merge 1 commit into
Open
Conversation
…r multi-digit source suffix TableIdRouter.resolveReplacement used Matcher.find() followed by Matcher.replaceAll to compute the sink table id. find() only matches a prefix of the source table id, and replaceAll internally calls reset() + find(), so: - When the source-table regex has a multi-character capturing group (e.g. db_6.table_([1-9]|1[0-6])), find() matched the prefix db_6.table_1 and left the trailing digit (3, 4, 5, 6, ...) appended to the configured sink-table, producing wrong sinks like new_db_6.table_merged3 for source db_6.table_13. - When the sink-table uses a $1 back-reference, the captured value was only the first matched digit for the same reason. Switch to Matcher.matches() + Matcher.appendReplacement / Matcher.appendTail so the entire source table id is consumed before the substitution, eliminating the trailing-characters-leak. Add regression tests in TableIdRouterTest. Signed-off-by: Pei Yu <125331682@qq.com>
sd4324530
force-pushed
the
fix/table-id-router-find-vs-matches
branch
from
July 15, 2026 00:22
adb78b7 to
543bb57
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What is the purpose of this pull request?
Fix
TableIdRouter.resolveReplacementso it routes tables correctly when the source-table regex contains a multi-character capturing group (e.g. a multi-digit suffix like13,14,16) regardless of whether the sink-table uses a$Nback-reference.Previously, with a rule such as:
db_6.table_13was wrongly routed tonew_db_6.table_merged3(and similarly_14→...merged4,_16→...merged6). The bug was caused byMatcher.find()+Matcher.replaceAllinresolveReplacement:find()only matched the prefixdb_6.table_1(because the alternation[1-9]wins over1[0-6]for input13), andreplaceAllleft the trailing3appended to the configured sink-table. Tables 1-9 were unaffected because the regex consumed the entire single-digit suffix.Brief change log
Matcher.find()+Matcher.replaceAll(sinkTable)withMatcher.matches()+Matcher.appendReplacement/Matcher.appendTailinTableIdRouter.resolveReplacement. This guarantees the whole source table id is consumed before the substitution is applied, so trailing characters can no longer leak into the sink-table name.testRouteWithoutBackReferenceWithMultiDigitSuffixandtestRouteWithBackReferenceAndMultiDigitCapturetoTableIdRouterTestas regression coverage for this bug.Verifying this change
This change added tests and can be verified as follows:
flink-cdc-runtime/src/test/java/org/apache/flink/cdc/common/route/TableIdRouterTest.java:testRouteWithoutBackReferenceWithMultiDigitSuffix— reproduces the originally reported scenario (sink-table without$1, multi-digit source suffix); fails on master, passes with the fix.testRouteWithBackReferenceAndMultiDigitCapture— guards the same root cause for the$1back-reference case to prevent future regressions.TableIdRouterTestpass, together with the 7 tests inTableIdRouterMatchModeTestand the 8 tests inSchemaDerivatorTest(27 tests total, no regressions).master: the new test reproduces wrong sink-table names such asnew_db_6.table_merged0,...merged1,...merged3,...merged4,...merged5,...merged6, which match the issue's report.Was generative AI tooling used to co-author this PR?
Generated-by: cluade code with minimax m3