Skip to content

GH-50967: [C++] Allow CSV reader to ignore extra columns in rows with more columns - #51118

Open
HuaHuaY wants to merge 1 commit into
apache:mainfrom
HuaHuaY:strengthen_csv
Open

GH-50967: [C++] Allow CSV reader to ignore extra columns in rows with more columns#51118
HuaHuaY wants to merge 1 commit into
apache:mainfrom
HuaHuaY:strengthen_csv

Conversation

@HuaHuaY

@HuaHuaY HuaHuaY commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

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_columns in CSV struct ParseOptions that ignores extra columns.

Are these changes tested?

Yes.

Are there any user-facing changes?

Add an option ignore_extra_columns in CSV struct ParseOptions.

Copilot AI lite review requested due to automatic review settings September 1, 2026 06:35
@HuaHuaY
HuaHuaY requested a review from pitrou as a code owner September 1, 2026 06:35
@HuaHuaY
HuaHuaY requested a review from wgtmac September 1, 2026 06:35

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 (default false) 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::Equals to 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.

Copilot AI review requested due to automatic review settings September 1, 2026 07:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@wgtmac wgtmac left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me. It would be good if @pitrou could take a look.

@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants