GH-50967: [C++] Allow CSV reader to ignore extra columns in rows with more columns - #51118
Open
HuaHuaY wants to merge 1 commit into
Open
GH-50967: [C++] Allow CSV reader to ignore extra columns in rows with more columns#51118HuaHuaY wants to merge 1 commit into
HuaHuaY wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new C++ CSV parsing option to tolerate rows with more fields than expected by ignoring any extra columns, instead of treating such rows as invalid. This extends the existing “pad short rows” behavior on the other side of the mismatch spectrum and makes the CSV reader more flexible for imperfect inputs.
Changes:
- Introduces
ParseOptions::ignore_extra_columns(defaultfalse) to ignore surplus fields when the expected column count is known. - Updates the CSV block parser to avoid materializing/parsing data for ignored extra fields while still scanning correctly for delimiters/newlines.
- Adds parser- and reader-level tests covering extra columns (including trailing delimiters) and updates dataset
CsvFileFormat::Equalsto account for the new option.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| cpp/src/arrow/dataset/file_csv.cc | Includes ignore_extra_columns in CsvFileFormat::Equals so format equality reflects the new parse behavior. |
| cpp/src/arrow/csv/options.h | Adds the ignore_extra_columns parse option to the public ParseOptions API. |
| cpp/src/arrow/csv/parser.cc | Implements ignoring of extra fields in the core parsing state machine (including bulk filter path). |
| cpp/src/arrow/csv/parser_test.cc | Adds a unit test validating that extra columns are ignored at the block parser level. |
| cpp/src/arrow/csv/reader_test.cc | Adds an integration test validating TableReader behavior with extra columns. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
HuaHuaY
force-pushed
the
strengthen_csv
branch
from
September 1, 2026 07:22
52277b3 to
3e198d8
Compare
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.
Rationale for this change
Currently, the C++ CSV reader rejects rows with more columns than expected. We can allow users to ignore the extra values instead of throwing exception.
What changes are included in this PR?
Add an option
ignore_extra_columnsin CSVstruct ParseOptionsthat ignores extra columns.Are these changes tested?
Yes.
Are there any user-facing changes?
Add an option
ignore_extra_columnsin CSVstruct ParseOptions.