Repository navigation
Kafka: map columns with special names to message metadata on INSERT - #103243
Merged
Merged
Conversation
Add a new Kafka table setting `kafka_map_virtual_columns_on_write` (default `false`). When enabled, columns in the Kafka table schema named `_key`, `_timestamp`, `_headers.name` and `_headers.value` are produced as the corresponding Kafka message key, timestamp and headers, and are excluded from the message payload. This lets producers reconstruct a Kafka message with the original key, timestamp and headers (for consume-process-produce pipelines) without the payload picking up extra fields such as `_key`. Closes #85610 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [a3fe42d] Summary: ✅ AI ReviewSummaryThis PR adds ClickHouse Rules
Final Verdict
|
Member
Author
Only exclude a column from the Kafka message payload when its type matches what `KafkaProducer` actually maps (String for `_key`, DateTime for `_timestamp`, `Array(String)` for `_headers.name`/`_headers.value`). Otherwise keep the column in the payload so schemas reusing these names with different types keep working — addresses reviewer feedback from #103243. Also fix `test_kafka_produce_virtual_columns_mapping` which tried to insert `['only_name']`/`[]` into a Nested `_headers.*` pair — that row is rejected by the standard `NestedElementsValidationTransform` before it reaches the producer, so remove it and drop the unreachable `std::min` fallback in `KafkaProducer::produce`. The Nested-size constraint is now reflected in `kafka.md`.
`splitPayloadColumns` previously excluded `_headers.name` and `_headers.value` from the payload independently as long as each column had `Array(String)` type. But `KafkaProducer` only emits Kafka headers when both columns are present, so a schema containing just one of them would silently lose that column from the payload. Compute the header-mapping decision once (both columns present and typed `Array(String)`) and use it for both columns. The reading and writing predicates now stay in sync with `KafkaProducer::KafkaProducer`. Adds an integration test for the one-sided case that verifies the remaining header column is preserved in the JSON payload. Addresses reviewer feedback from #103243. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
# Conflicts: # tests/queries/0_stateless/02818_memory_profiler_sample_min_max_allocation_size.sh
Contributor
LLVM Coverage Report
Changed lines: 97.44% (152/156) | lost baseline coverage: 5 line(s) · Uncovered code |
47 of 72 tasks
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.
Adds a new Kafka table setting
kafka_map_virtual_columns_on_write(default
false). When enabled, columns in the Kafka table schema named_key,_timestamp,_headers.nameand_headers.valueare producedas the corresponding Kafka message key, timestamp and headers, and are
excluded from the message payload. Default behavior is unchanged.
This lets consume-process-produce pipelines reconstruct Kafka messages
with the original key, timestamp and headers without polluting the
payload with extra fields like
_key.Closes #85610.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Added a new Kafka table setting
kafka_map_virtual_columns_on_write. When enabled, columns named_key,_timestamp,_headers.nameand_headers.valuein the Kafka table schema are produced as the corresponding Kafka message key, timestamp and headers onINSERT, and are excluded from the message payload.Documentation entry for user-facing changes