sd4324530 opened a new pull request, #4473:
URL: https://github.com/apache/flink-cdc/pull/4473
## What is the purpose of this pull request?
Fix `TableIdRouter.resolveReplacement` so it routes tables correctly when
the source-table regex contains a multi-character capturing group (e.g. a
multi-digit suffix like `13`, `14`, `16`) regardless of whether the sink-table
uses a `$N` back-reference.
Previously, with a rule such as:
route:
- source-table: db_6.table_([1-9]|1[0-6])
sink-table: new_db_6.table_merged
`db_6.table_13` was wrongly routed to `new_db_6.table_merged3` (and
similarly `_14` → `...merged4`, `_16` → `...merged6`). The bug was caused by
`Matcher.find()` + `Matcher.replaceAll` in `resolveReplacement`: `find()` only
matched the prefix `db_6.table_1` (because the alternation `[1-9]` wins over
`1[0-6]` for input `13`), and `replaceAll` left the trailing `3` appended to
the configured sink-table. Tables 1-9 were unaffected because the regex
consumed the entire single-digit suffix.
## Brief change log
- Replace `Matcher.find()` + `Matcher.replaceAll(sinkTable)` with
`Matcher.matches()` + `Matcher.appendReplacement` / `Matcher.appendTail` in
`TableIdRouter.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.
- Add `testRouteWithoutBackReferenceWithMultiDigitSuffix` and
`testRouteWithBackReferenceAndMultiDigitCapture` to `TableIdRouterTest` as
regression coverage for this bug.
---
## Verifying this change
This change added tests and can be verified as follows:
- Added unit tests in
`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 `$1` back-reference case to prevent future regressions.
- All 12 tests in `TableIdRouterTest` pass, together with the 7 tests in
`TableIdRouterMatchModeTest` and the 8 tests in `SchemaDerivatorTest` (27 tests
total, no regressions).
- Manually verified by running the failing test against unmodified `master`:
the new test reproduces wrong sink-table names such as
`new_db_6.table_merged0`, `...merged1`, `...merged3`, `...merged4`,
`...merged5`, `...merged6`, which match the issue's report.
## Documentation
- Does this pull request introduce a new feature? **no**
- If yes, how is the feature documented? not applicable
---
##### Was generative AI tooling used to co-author this PR?
- [x] Yes
Generated-by: cluade code with minimax m3
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]