Skip to content

GH-45806: [C++][Statistics] Add array statistics schema support#50071

Open
cjc0013 wants to merge 2 commits into
apache:mainfrom
cjc0013:statistics-schema-array-nested-support
Open

GH-45806: [C++][Statistics] Add array statistics schema support#50071
cjc0013 wants to merge 2 commits into
apache:mainfrom
cjc0013:statistics-schema-array-nested-support

Conversation

@cjc0013
Copy link
Copy Markdown

@cjc0013 cjc0013 commented Jun 1, 2026

Rationale for this change

The statistics schema documentation describes statistics arrays for Arrow arrays and nested field column indexes, but C++ only exposed RecordBatch::MakeStatisticsArray() and only enumerated top-level record batch columns.

This leaves two related gaps:

  • callers cannot ask an Array to produce its statistics schema representation directly;
  • RecordBatch::MakeStatisticsArray() drops statistics attached to nested child arrays.

What changes are included in this PR?

  • Add Array::MakeStatisticsArray().
  • Share the statistics-array construction path between Array and RecordBatch.
  • Traverse nested ArrayData::child_data when enumerating record batch column statistics, using the same depth-first column index order described by the IPC record batch message rules.
  • Preserve existing record batch row-count behavior.

Are these changes tested?

Yes. Locally:

  • ninja arrow-table-test -j2
  • ./debug/arrow-table-test --gtest_filter="*MakeStatisticsArray*": 24 tests passed
  • ./debug/arrow-table-test: 181 tests passed

Are there any user-facing changes?

Yes. This adds the public C++ Array::MakeStatisticsArray() API and lets RecordBatch::MakeStatisticsArray() include nested child-array statistics when present. This is not a breaking API change.

Closes #45804.
Addresses part of #45474.
Refs #45806.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 1, 2026

⚠️ GitHub issue #45806 has been automatically assigned in GitHub to PR creator.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends Arrow C++ statistics-schema support by adding an Array::MakeStatisticsArray() API and updating RecordBatch::MakeStatisticsArray() to enumerate statistics for nested child arrays using the IPC RecordBatch depth-first column index order, while preserving existing record-batch row-count behavior.

Changes:

  • Added public C++ API Array::MakeStatisticsArray() and shared the statistics-array construction path between Array and RecordBatch.
  • Updated statistics enumeration to traverse ArrayData::child_data for nested statistics (depth-first column indexing).
  • Added unit tests covering Array::MakeStatisticsArray() and nested field enumeration in RecordBatch::MakeStatisticsArray().

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
cpp/src/arrow/record_batch.cc Refactors statistics enumeration into reusable helpers; adds nested traversal; implements Array::MakeStatisticsArray() and shared builder path.
cpp/src/arrow/record_batch_test.cc Adds tests for the new Array API and nested-field statistics inclusion/order for record batches.
cpp/src/arrow/array/array_base.h Declares the new public Array::MakeStatisticsArray() API with documentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +595 to +599
Status EnumerateArrayStatistics(const std::shared_ptr<ArrayData>& data,
int32_t* nth_column, int* nth_statistics,
OnStatistics on_statistics,
bool include_exact_row_count = false) {
const auto current_column = (*nth_column)++;
Comment on lines +648 to +650
template <typename EnumerateStatisticsFunction>
Result<std::shared_ptr<Array>> MakeStatisticsArrayFromEnumerator(
EnumerateStatisticsFunction enumerate_statistics, MemoryPool* memory_pool) {
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.

[C++][Statistics] Lack of method for creating statistics array for Array

2 participants