Kafka Connect: Add pluggable RecordRouter interface with five built-in routing strategies#15959
Open
kumarpritam863 wants to merge 22 commits intoapache:mainfrom
Open
Kafka Connect: Add pluggable RecordRouter interface with five built-in routing strategies#15959kumarpritam863 wants to merge 22 commits intoapache:mainfrom
kumarpritam863 wants to merge 22 commits intoapache:mainfrom
Conversation
Contributor
Author
|
@bryanck can you please check. |
Contributor
Author
|
@danielcweeks can you please review this. |
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.
Summary
Introduces a pluggable
RecordRouterinterface that abstracts all record-to-table routing logic in the Kafka Connect sink, replacing the hardcoded static/dynamic if-else inSinkWriter. This unlocks customrouting strategies without modifying connector internals.
Ships six built-in implementations:
StaticRouter— wraps existing static routing behavior (broadcast + regex filtering)DynamicRouter— wraps existing dynamic routing behavior (field value as table name)TopicNameRouter— maps Kafka topic names to Iceberg table identifiers with namespace prefixing, regex transforms, explicit topic-to-table overrides, and case controlCompositeFieldRouter— multi-dimensional routing using multiple record fields combined via a template engineHeaderRouter— routes based on Kafka record header values with multi-value fan-out, explicit mappings, and configurable missing-header policiesFilterRouter— decorator that evaluates predicates (topic regex, field regex, header regex, field existence) before delegating to any other routerMotivation
The current routing is single-dimensional (one field determines the destination) and the two modes (static vs dynamic) are mutually exclusive. Users frequently need:
The pluggable interface enables all of these as independent, composable implementations.
Key design decisions
RecordRouter.configure(Map<String, String>)takes raw props instead ofIcebergSinkConfigto keep the interface decoupled — external implementations only depend on the router APIroute()returnsList<RouteTarget>to support fan-out (one record → multiple tables), which static routing already does in broadcast mode andHeaderRouteruses for multi-value headersRouteTargetcarriesignoreMissingTableto preserve the semantic difference between static routing (throw on missing) and dynamic/topic routing (NoOpWriter)configure(IcebergSinkConfig)overload to avoid the cost of re-creating config + JsonConverter from raw propsFilterRouteruses the decorator pattern — it wraps any other router and evaluates predicates before delegating, making filtering composable with any routing strategyiceberg.tables.router-classis unset,RecordRouterFactoryfalls back toStaticRouter/DynamicRouter— zero behavioral change for existing usersNew configuration
iceberg.tables.router-classRecordRouterclass name. Overridesiceberg.tablesandiceberg.tables.dynamic-enabledwhen set.TopicNameRouter properties (prefix
iceberg.tables.route.topic-name.)table-namespacetable-map.<topic>regexregex-replacement$1lowercaseignore-missing-tableCompositeFieldRouter properties (prefix
iceberg.tables.route.composite.)fieldstable-template${0}.${1}${N}references fields by index.table-namespacelowercaseignore-missing-tablenull-handlingdropdrop,literal, ordefault:<value>HeaderRouter properties (prefix
iceberg.tables.route.header.)nametable-namespacetable-map.<header-value>regexregex-replacement$1lowercaseignore-missing-tableon-missing-headerdropdrop,fail, ordefault:<table>multi-valuefirstfirst,last, orall(fan-out)FilterRouter properties (prefix
iceberg.tables.route.filter.)delegate-classmodeincludeinclude= only matching records pass.exclude= matching records dropped.topic-regexfieldfield-regexheaderheader-regexfield-existsExample usage