[Enhancement] Expose Kafka/Pulsar message metadata via an INCLUDE METADATA clause in Routine Load (backport #73840)#76321
Closed
mergify[bot] wants to merge 1 commit into
Closed
Conversation
…ADATA clause in Routine Load (#73840) Signed-off-by: Evgeniy Shishkin <eshishki@gmail.com> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> (cherry picked from commit 0796ea6) # Conflicts: # be/src/exec/CMakeLists.txt # be/src/exec/file_scanner/avro_scanner.cpp # be/src/exec/file_scanner/avro_scanner.h # be/src/exec/file_scanner/json_scanner.cpp # be/src/exec/file_scanner/json_scanner.h # be/src/runtime/routine_load/data_consumer_group.cpp # be/src/runtime/routine_load/data_consumer_group.h # be/test/CMakeLists.txt # be/test/exec/file_scanner/json_scanner_test.cpp # be/test/runtime/routine_load/data_consumer_test.cpp # fe/fe-core/src/main/java/com/starrocks/load/Load.java # fe/fe-core/src/test/java/com/starrocks/load/LoadTest.java # fe/fe-core/src/test/java/com/starrocks/planner/StreamLoadScanNodeTest.java # fe/fe-grammar/src/main/antlr/com/starrocks/grammar/StarRocks.g4
Contributor
Author
|
Cherry-pick of 0796ea6 has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
Contributor
Author
|
@mergify[bot]: Backport conflict, please reslove the conflict and resubmit the pr |
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.
Why I'm doing:
Routine Load consumers already receive each Kafka/Pulsar message's metadata — topic, partition,
offset, timestamp, key, headers — but there was no way to land any of it in table columns; only the
message payload could be loaded. Users who need provenance (which topic/partition/offset a row came
from), event-time processing, or routing on a header value had no access to it.
What I'm doing:
Add an
INCLUDE METADATA (...)clause to CREATE/ALTER ROUTINE LOAD that binds per-message sourcemetadata to source columns:
Each
<KEY> AS <alias>binds a metadata key to a hidden source column named<alias>thatCOLUMNSexpressions reference; the BE scanner fills it from the message by slot id, so a payload field with
the same name is never shadowed. The valid keys are source-dependent and inferred from the
FROMtype:
TOPIC,KEY,PARTITION,OFFSET,TIMESTAMP_MS,HEADERS.TOPIC,KEY,PARTITION,MESSAGE_ID,PUBLISH_TIME_MS,EVENT_TIME_MS,PROPERTIES.HEADERS/PROPERTIESis aMAP<VARCHAR, VARCHAR>(duplicate keys last-wins; raw bytes, no UTF-8validation); a single value is read with
element_at(alias, 'name'). Available forformat = json(Kafka and Pulsar) and
format = avro(Kafka only — Pulsar maps non-JSON to CSV); not supported forCSV, because the consumer accumulates several messages into one pipe buffer (the JSON/Avro path uses
one buffer per message), so a CSV row cannot be tied back to its own message's metadata. An
unsupported key for the source raises an explicit error that lists the source's supported keys.
Validated at both CREATE and ALTER.
Unit tests (FE clause validation/binding + persistence round-trip, BE metadata fill + Pulsar topic
parsing) and user documentation (en/zh/ja) added.
Fixes #73841
Compatibility & upgrade:
This change is additive; existing jobs are unaffected and no migration is required.
TStreamSourceMetaKind,TRoutineLoadMetaColumn,TBrokerScanRangeParams.stream_source_meta_columns(field 35), andneed_source_metadata/need_message_key/need_message_headersonTKafkaLoadInfo(8/6/7) andTPulsarLoadInfo(9/7/8). Nothing isrequired, so mixed-version FE and BE interoperate during arolling upgrade.
INCLUDE METADATAclause takes the existing path — no hiddencolumn,
need_source_metadataunset, the consumer attaches only the partition/offset it always did(feeding malformed-record error logs), and the scanner reads every field from the payload. Output is
unchanged; no job needs to be recreated.
CREATE ROUTINE LOADSQL persisted in thejob's origin statement, so
SHOW CREATE ROUTINE LOADrenders it and FE replay rebuilds the job fromthat SQL.
stream_source_meta_columnsleaves those columns empty rather than failing, so upgrade BE before creating metadata jobs.
Downgrade is safe: a downgraded BE ignores the optional fields and the persisted job SQL stays intact.
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check:
This is an automatic backport of pull request [Enhancement] Expose Kafka/Pulsar message metadata via an INCLUDE METADATA clause in Routine Load #73840 done by Mergify.