Repository navigation
feat: add match_columns_by_header option for CSV - #27021
Open
wyatt-herkamp wants to merge 2 commits into
Open
wyatt-herkamp wants to merge 2 commits into
wyatt-herkamp wants to merge 2 commits into
Conversation
wyatt-herkamp
marked this pull request as ready for review
November 2, 2026 21:16
xudong963
self-requested a review
November 3, 2026 00:23
Member
|
Thanks @wyatt-herkamp —the per-file schema plus BatchAdapter design is a good fit for DataFusion! Header discovery currently fails on leading blank records and BOM-prefixed comments, and the primary CsvReadOptions Rust API cannot enable the feature. How about aligning header discovery with Arrow’s CSV parsing semantics, adding regressions for those cases, exposing the option through CsvReadOptions, and marking/documenting the breaking API addition? |
…y_header on CsvReadOptions Header discovery now skips a leading UTF-8 BOM, blank records and comment lines the same way csv-core does, so files with those before the header are mapped by name rather than silently read by position.
wyatt-herkamp
force-pushed
the
csv-match-columns-by-header
branch
from
November 5, 2026 14:02
18a08c4 to
70ec58c
Compare
Contributor
Author
|
Thanks for the review @xudong963. Addressed in 70ec58c and rebased on main:
|
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
arrow-csv parses columns by position, so when reading multiple CSV files where some file is missing a column (that isn't the last one), values land in the wrong columns or parsing fails.
What changes are included in this PR?
match_columns_by_headerCSV option (config,CsvFormat,CsvSource, and proto).has_header), each file's header is read and its columns are mapped to the table schema by name; missing columns are filled viaPhysicalExprAdapterFactory. Works for both full-file and range (repartitioned) reads.CsvReadOptions::match_columns_by_headerexposes the option on theread_csvAPI.Are these changes tested?
Yes: unit tests in
datasource-csv/src/source.rsandcore/src/datasource/physical_plan/csv.rs, a proto round-trip test, and sqllogictest cases incsv_files.slt.Are there any user-facing changes?
New opt-in
format.match_columns_by_headeroption, documented informat_options.md. Default behavior is unchanged.API change:
CsvOptionsandCsvReadOptionsgain a publicmatch_columns_by_headerfield, and the protobufCsvOptions/CsvScanExecNodemessages gain the same field. Exhaustive struct literals need updating; noted in the 56.0.0 upgrade guide.