[spark] Expose written columns for streaming micro-batches - #9023
[spark] Expose written columns for streaming micro-batches#9023LsomeYeah wants to merge 5 commits into
Conversation
f7a16e4 to
7e33328
Compare
| <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> |
There was a problem hiding this comment.
Why introducing this option? Is there any problem with enabling it by default?
There was a problem hiding this comment.
Good point. There is no known issue with enabling it by default, so I removed the option, the metadata is now planned automatically.
a68e359 to
efa8dca
Compare
|
Thanks for working on this. The core idea—attaching driver-only metadata to the exact InputPartitions admitted for the micro-batch and recovering it from the raw However, I think the implementation can be made substantially smaller:
So my preferred shape would be: keep the transient InputPartition + RDD-lineage approach, but use a private lazy batch-metadata object, return One additional verification gap: because this feature depends on |
efa8dca to
c4820e5
Compare
c4820e5 to
571a15c
Compare
|
@JingsongLi Thanks for the thoughtful guidance! I’ve updated the PR accordingly: written-column resolution is now lazy and memoized, the API is simplified to Optional[List[Integer]], Spark-version handling is kept local to the helper, and Core field-ID resolution is shared. The Spark 4 foreachBatch metadata tests also pass, and the change is now down from 17 files to 7. |
Summary
Expose plan-level written-column IDs for each Spark Structured Streaming micro-batch. Consumers of wide sparse change streams can inspect the exact fields written by files admitted to the current batch before materializing business rows, avoiding a full-column NULL scan.
Changes
(startOffset, endOffset]batch, using each file's historical schema so field IDs remain stable across schema evolution and renames.PaimonSparkMicroBatchMetadata.writtenColumnIds(Dataset)API for rawforeachBatchdatasets.Optional[List[Integer]]: a present value is the exact sorted immutable field-ID list, including a known empty list; an emptyOptionalmeans unavailable, ambiguous, or conservatively unresolved.writeColsexpand to their historical file schema; missing schemas or unknown non-system write columns return an emptyOptionalfor conservative all-column fallback.foreachBatch, but not per-batch physical reader pruning.Testing
DataEvolutionUtilsTest(10/10): multi-file and multi-schema unions, rename-stable field IDs, legacywriteCols, strict fallback, system fields, exact empty sets, schema caching, and projection caching.PaimonSourceTest(24/24): lazy and memoized evaluation, driver-only serialization, rawforeachBatchaccess after projection, zero Action, same-source self-union, multiple-source ambiguity, read limits, Data Evolution$row_tracking, and an explicitly written all-null column.Trigger ProcessingTime 5scase, unrelated to metadata extraction.git diff --check.Notes
The helper is
@Experimental. Metadata planning does not change source schema, offsets or checkpoints, split admission, or row-reader behavior.Written-column IDs are resolved only when the helper is called. If metadata cannot be proven complete, the API returns an empty
Optionaland callers must conservatively process all columns.This supports early projection and narrow caching inside
foreachBatch; it does not implement per-micro-batch physical reader pruning because the Structured Streaming source schema remains fixed for the query.