[spark] Expose written columns for streaming micro-batches - #9023
Open
LsomeYeah wants to merge 3 commits into
Open
[spark] Expose written columns for streaming micro-batches#9023LsomeYeah wants to merge 3 commits into
LsomeYeah wants to merge 3 commits into
Conversation
LsomeYeah
force-pushed
the
codex/spark-streaming-written-columns
branch
from
August 5, 2026 10:34
f7a16e4 to
7e33328
Compare
LsomeYeah
marked this pull request as ready for review
August 5, 2026 10:41
JingsongLi
reviewed
Aug 7, 2026
| <td>Whether to read row in the form of changelog (add rowkind column in row to represent its change type).</td> | ||
| </tr> | ||
| <tr> | ||
| <td><h5>read.stream.batch-written-columns.enabled</h5></td> |
Contributor
There was a problem hiding this comment.
Why introducing this option? Is there any problem with enabling it by default?
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
Expose opt-in, plan-level written-column metadata for each Spark Structured Streaming micro-batch. This lets consumers of wide sparse change streams obtain stable field IDs from the files admitted to the current batch before materializing business rows, instead of scanning every column to infer updates from null values.
Changes
KnownWrittenColumns(fieldIds)and the conservativeAllColumnsfallback.writeColsexpand to their file schema, while unresolved metadata falls back to all columns.schemaId -> TableSchemafor the stream lifetime, in addition to caching(schemaId, writeCols)projections while collecting a batch summary.read.stream.batch-written-columns.enabled, disabled by default.(startOffset, endOffset]micro-batch and attach it to the corresponding InputPartitions for driver-side discovery.PaimonSparkMicroBatchMetadata.writtenColumns(Dataset)Driver-side, zero-Action API for rawforeachBatchdatasets.SharedStateand require exactly one distinct Paimon source before returning metadata. This also handles sources that Spark replaces withLocalRelationbecause they have no new offset in the current batch.Testing
foreachBatchaccess after a projection, and same-source self-union.maxFilesPerTriggerdoes not mix columns from the next batch on a Data Evolution$row_trackingstream.DataEvolutionUtilsTestandDataEvolutionFileStoreScanTest(17 tests).PaimonSourceTest(24 tests).Notes
The public Spark helper is marked
@Experimental. The option is disabled by default and does not change source schema, offset/checkpoint semantics, split admission, or row reader behavior.This PR exposes planning metadata for early narrowing inside
foreachBatch; it does not implement per-micro-batch physical reader column pruning because the Structured Streaming source schema remains fixed for the query.The query/source lookup uses Spark internals only inside
paimon-sparkand fails closed to an empty result if those internals cannot be resolved. It does not introduce a Paimon global registry or rely on completed source metrics.