Skip to content

feat(inspect): add refs metadata table - #1007

Draft
manuzhang wants to merge 2 commits into
apache:mainfrom
manuzhang:codex/add-refs-metadata-table
Draft

manuzhang wants to merge 2 commits into
apache:mainfrom
manuzhang:codex/add-refs-metadata-table

Conversation

@manuzhang

@manuzhang manuzhang commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Add RefsTable to expose branch and tag snapshot references through an Arrow stream. Its six-column schema includes reference names, uppercase BRANCH/TAG types, snapshot IDs, and optional retention settings; rows are sorted by reference name. Null tables return kInvalidArgument, while null reference metadata returns kInvalid.

The shared metadata row-stream helper validates sources and nullable callbacks, preserves errors and exhaustion through Stream<ArrowArray>, avoids allocating builders after exhaustion, and stores concrete callbacks. SnapshotsTable now uses the same helper while retaining captured metadata and skipping null snapshots. Existing metadata test sources and their fixture live alongside the new tests under test/inspect.

Extracted from #876, whose files, partitions, and manifests tables depend on this PR. Regression tests cover vector and lazy sources, multiple batches, append/source failures through the Arrow C callbacks, invalid inputs, close/release behavior, and RefsTable format versions 1, 2, and 3.

Validation: pre-commit and git diff --check passed. Standalone metadata tests: 31 passed. Combined with #876: 87 passed. Hosted CI is separate from these local checks.

Co-authored-by: Codex <codex@openai.com>
Copilot AI balanced review requested due to automatic review settings October 13, 2026 13:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open findings
What changed in this PR

This PR adds an inspect metadata table (RefsTable) that exposes Iceberg branch/tag snapshot references as an Arrow stream, along with a shared internal helper for emitting bounded Arrow record batches.

Changes:

  • Introduces RefsTable (schema + scan implementation) and wires it into the metadata table kind enum / build system.
  • Adds a shared internal Arrow row-stream helper to generate bounded Arrow batches from row iterators.
  • Adds RefsTable unit tests (format v2/v3) and integrates them into the test target.
File Description
src/​iceberg/​type_fwd.h Adds forward declaration for RefsTable.
src/​iceberg/​inspect/​metadata_table.h Adds kRefs metadata table kind.
src/​iceberg/​inspect/​refs_table.h Declares the new RefsTable metadata table API.
src/​iceberg/​inspect/​refs_table.cc Implements RefsTable schema + scanning over snapshot refs; sorts results.
src/​iceberg/​inspect/​metadata_table_stream_internal.h Adds internal Arrow stream implementation for iterating rows in bounded batches.
src/​iceberg/​test/​inspect/​refs_table_test.cc Adds tests validating schema, sorting, and retention-field projection.
src/​iceberg/​test/​CMakeLists.txt Registers the new refs table tests in the test target.
src/​iceberg/​cpp20_compatibility_internal.h Includes the new header for compatibility aggregation.
src/​iceberg/​CMakeLists.txt Adds inspect/refs_table.cc to library sources.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/iceberg/inspect/refs_table.cc
Comment thread src/iceberg/inspect/refs_table.cc
Comment thread src/iceberg/inspect/refs_table.cc
Comment on lines +70 to +87
Result<std::optional<ArrowArray>> Next() {
ICEBERG_PRECHECK(arrow_schema_.release != nullptr,
"Cannot read from a closed metadata table stream");
ICEBERG_ASSIGN_OR_RAISE(auto builder, ArrowRowBuilder::Make(&arrow_schema_));
while (builder.num_rows() < MetadataTable::kBatchSize) {
ICEBERG_ASSIGN_OR_RAISE(auto row, rows_->Next());
if (!row.has_value()) {
break;
}
ICEBERG_RETURN_UNEXPECTED(append_row_(builder, *row));
}
if (builder.num_rows() == 0) {
return std::nullopt;
}

ICEBERG_ASSIGN_OR_RAISE(auto array, std::move(builder).Finish());
return array;
}
@manuzhang
manuzhang marked this pull request as draft October 13, 2026 15:06
Make row errors and exhaustion terminal, validate stream inputs, and store callbacks without type erasure. Reuse the helper for SnapshotsTable and cover batching, lazy reads, failures, cleanup, null metadata, and format version 1.

Co-authored-by: Codex <codex@openai.com>
manuzhang added a commit to manuzhang/iceberg-cpp that referenced this pull request Oct 13, 2026
Move the common metadata test fixture into inspect and update history and snapshots includes to match PR apache#1007.

Co-authored-by: Codex <codex@openai.com>
Copilot AI balanced review requested due to automatic review settings October 13, 2026 15:37

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment on lines +194 to +198
inspect/history_table_test.cc
inspect/metadata_table_stream_test.cc
inspect/metadata_table_test.cc
inspect/refs_table_test.cc
inspect/snapshots_table_test.cc)
Comment on lines +53 to +68
Status AppendOptional(ArrowArray* array, const auto& value) {
if (!value.has_value()) {
return AppendNull(array);
}
return AppendInt(array, static_cast<int64_t>(*value));
}

Status AppendRef(ArrowRowBuilder& builder, const RefRow& ref) {
ICEBERG_RETURN_UNEXPECTED(AppendString(builder.column(0), ref.name));
ICEBERG_RETURN_UNEXPECTED(AppendString(builder.column(1), ref.type));
ICEBERG_RETURN_UNEXPECTED(AppendInt(builder.column(2), ref.snapshot_id));
ICEBERG_RETURN_UNEXPECTED(AppendOptional(builder.column(3), ref.max_ref_age_ms));
ICEBERG_RETURN_UNEXPECTED(AppendOptional(builder.column(4), ref.min_snapshots_to_keep));
ICEBERG_RETURN_UNEXPECTED(AppendOptional(builder.column(5), ref.max_snapshot_age_ms));
return builder.FinishRow();
}

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants