GH-51361: [C++][Parquet] Derive records_to_read in FileReaderImpl::ReadColumn from RowGroup  (#51362)

### Rationale for this change
Fixes #51361.

### What changes are included in this PR?
Method `FileReaderImpl::ReadColumn` should derive `records_to_read` from the RowGroup rather than ColumnChunk's `num_values`. Deriving the right ColumnChunk index in `FileReaderImpl::DecodeRowGroups` is not trivial for nested schemas. This simplifies `FileReaderImpl::ReadColumn` and fixes #51361.

This was silently masked for full-schema reads and for columns with identical num_values(), but surfaces as a hard failure when an earlier, unselected column requires decryption: reading only a trailing plaintext column of a partially column-key-encrypted, plaintext-footer Parquet file threw "Cannot decrypt ColumnMetadata" even though the requested column was never encrypted.

This never corrupts data on unencrypted files: ReadColumn's wrong index is only ever used to look up ColumnChunk(i)->num_values(), a count fed into the *already-correct* reader as an upper bound on how many records to decode. Every row contributes at least one definition/repetition-level entry, so num_values() for any column is always >= that row group's true row count, and every column in a row group shares the same row count.

### Are these changes tested?
Yes, in the context of reading a plaintext column of a partially encrypted Parquet file. This cannot be tested with non-encrypted files.

### Are there any user-facing changes?
No.

### Was AI used for this PR?

In accordance to the [AI generation guidelines](https://arrow.apache.org/docs/dev/developers/overview.html#ai-generated-code), please disclose below whether and how AI was used in this PR.

**PR code and description written by:**

- [X] Human
- [X] AI

**Reviewed before submission by:**

- [X] Human
- [ ] AI
- [ ] Not reviewed
* GitHub Issue: #51361

Lead-authored-by: Enrico Minack <enrico.minack@insightsoftmax.com>
Co-authored-by: Enrico Minack <github@enrico.minack.dev>
Signed-off-by: Adam Reeve <adreeve@gmail.com>
3 files changed
tree: 8dcd79b2f5b2f745642541fdbe8177beeb1daf0b
  1. .claude/
  2. .github/
  3. c_glib/
  4. ci/
  5. cpp/
  6. dev/
  7. docs/
  8. format/
  9. matlab/
  10. python/
  11. r/
  12. ruby/
  13. .asf.yaml
  14. .clang-format
  15. .clang-tidy
  16. .clang-tidy-ignore
  17. .dockerignore
  18. .editorconfig
  19. .env
  20. .gitattributes
  21. .gitignore
  22. .gitmodules
  23. .hadolint.yaml
  24. .pre-commit-config.yaml
  25. .rubocop.yml
  26. .shellcheckrc
  27. CHANGELOG.md
  28. cmake-format.py
  29. CODE_OF_CONDUCT.md
  30. compose.yaml
  31. CONTRIBUTING.md
  32. CPPLINT.cfg
  33. LICENSE.txt
  34. NOTICE.txt
  35. README.md
README.md

Apache Arrow

Fuzzing Status License BlueSky Follow

Powering In-Memory Analytics

Apache Arrow is a universal columnar format and multi-language toolbox for fast data interchange and in-memory analytics. It contains a set of technologies that enable data systems to efficiently store, process, and move data.

Major components of the project include:

The icon denotes that this component of the project is maintained in a separate repository.

Arrow is an Apache Software Foundation project. Learn more at arrow.apache.org.

What's in the Arrow libraries?

The reference Arrow libraries contain many distinct software components:

  • Columnar vector and table-like containers (similar to data frames) supporting flat or nested types
  • Fast, language agnostic metadata messaging layer (using Google's FlatBuffers library)
  • Reference-counted off-heap buffer memory management, for zero-copy memory sharing and handling memory-mapped files
  • IO interfaces to local and remote filesystems
  • Self-describing binary wire formats (streaming and batch/file-like) for remote procedure calls (RPC) and interprocess communication (IPC)
  • Integration tests for verifying binary compatibility between the implementations (e.g. sending data from Java to C++)
  • Conversions to and from other in-memory data structures
  • Readers and writers for various widely-used file formats (such as Parquet, CSV)

Implementation status

The official Arrow libraries in this repository are in different stages of implementing the Arrow format and related features. See our current feature matrix on git main.

How to Contribute

Please read our latest project contribution guide.

If you are using AI coding tools, please review our AI-generated code guidance.

Getting involved

Even if you do not plan to contribute to Apache Arrow itself or Arrow integrations in other projects, we'd be happy to have you involved:

Continuous Integration Sponsors

We use runs-on for managing the project self-hosted runners. We use AWS for some of the required infrastructure for the project.