feat(parquet-datasource): support virtual columns (e.g. row number) in the parquet opener#22515
Closed
JanKaul wants to merge 1 commit into
Closed
feat(parquet-datasource): support virtual columns (e.g. row number) in the parquet opener#22515JanKaul wants to merge 1 commit into
JanKaul wants to merge 1 commit into
Conversation
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.
Which issue does this PR close?
Rationale for this change
The upstream
parquetcrate exposes "virtual columns" — columns that aren't physically stored in the file but are materialized by the reader (e.g. the per-rowRowNumberextension type). DataFusion's parquet datasource didn't wire this through: a user who included aRowNumber-tagged field in their file schema would get a "column not found in parquet schema" error or a misaligned projection mask, because the opener fed the full Arrow schema toArrowReaderOptions::with_schema(which expects real fields only) and builtProjectionMask::rootsfrom indices that included virtual fields with no parquet leaves.What changes are included in this PR?
datafusion/datasource-parquet/src/opener/mod.rssplit_virtual_fieldshelper that partitions a schema into(real-only schema, virtual field list).PreparedParquetOpen::load, extract virtuals fromlogical_file_schemaand pass them toArrowReaderOptions::with_virtual_columns; store the list onMetadataLoadedParquetOpenso later stages can re-supply the real-only schema.MetadataLoadedParquetOpen, strip virtuals before eachoptions.with_schema(...)call via aresupply_schemaclosure (the underlying API rejects virtuals).#[cfg(feature = "parquet_encryption")] let mut options = options;shadow — the new unconditionalwith_virtual_columnswrite site meansoptionsalways has a potential mutation, so the cfg-gated shadow is no longer required to silenceunused_mut.datafusion/datasource-parquet/src/row_filter.rsbuild_projection_read_plan, filter virtual roots out of the indices passed toProjectionMask::roots/leaf_indices_for_roots(virtuals have no parquet column to mask).build_parquet_read_plandocumenting why no symmetric filter is needed:leaf_indices_for_rootssilently drops indices with no matching leaf, and the decoder appends virtuals to every batch regardless of the mask, soprojected_schemastays aligned.Are these changes tested?
Yes. Added two tests in
opener/mod.rs:test_virtual_row_number_column— round-trips a[Int32, RowNumber(Int64)]schema across two row groups and assertsrow_num == [0..6).test_virtual_row_number_column_with_row_group_pruning— same setup with a predicate (a >= 20) that prunes the first row group and confirms the row numbers come back as[3, 4, 5](i.e. the virtual column reflects the file's absolute row indices, not the post-pruning sequence).Are there any user-facing changes?
Yes — purely additive. A
Fieldtagged with theRowNumberextension type (or any other parquet virtual-column extension) in a file schema is now honored by the parquet datasource. No existing API signatures change.