Skip to content

GH-55773: [C++][Python][ORC] Preserve row counts for empty projections - #55774

Open
jiangxt2 wants to merge 1 commit into
apache:mainfrom
jiangxt2:orc-zero-column-row-count
Open

jiangxt2 wants to merge 1 commit into
apache:mainfrom
jiangxt2:orc-zero-column-row-count

Conversation

@jiangxt2

@jiangxt2 jiangxt2 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

ORCFile.read(columns=[]) and ORCFile.read_stripe(..., columns=[]) return zero rows for nonempty ORC data. An empty projection should retain the number of rows, as ORCFile.iter_batches(columns=[]) already does. This follows the discussion in #54926.

Closes #55773.

What changes are included in this PR?

Accumulate the number of rows read from ORC batches when the output schema has no fields, and construct a zero-column record batch with that row count. This fixes the C++ Read() and ReadStripe() paths and their Python ORCFile.read() and ORCFile.read_stripe() interfaces. Add C++ and Python regression tests for whole-file and stripe reads, multiple stripes, empty files, caller-provided schemas and read errors.

Are these changes tested?

On macOS arm64 with Release builds, Python 3.13.7 and ORC 2.2.1:

cpp/build/dev/release/arrow-orc-adapter-test
python -m pytest -q -ra --enable-orc --enable-dataset --enable-pandas python/pyarrow/tests/test_orc.py

The C++ suite passed 48 tests and skipped one existing time-zone database test limited to ORC versions before 2.0. The Python ORC suite passed 131 tests. C++ and Python format and lint checks passed.

Are there any user-facing changes?

Yes. Empty projections through ORCFile.read() and ORCFile.read_stripe() now return the actual number of rows instead of zero.

This PR contains a "Critical Fix". The affected reads report an incorrect row count for nonempty data.

Was AI used for this PR?

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

OpenAI Codex assisted with the implementation, tests, description, and static review. The human contributor directed the scope and approved the implementation and test changes.

Generated-by: OpenAI Codex
Signed-off-by: jiangxt2 <jiangxt2@vip.qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C++][Python][ORC] Empty projections lose row counts in ORCFile reads

1 participant