feat(inspect): implement SnapshotsTable scanning#801
Conversation
28c4513 to
a53f8ce
Compare
9bc23e1 to
04b657f
Compare
- Add Scan() virtual method and Scan() convenience overload to MetadataTable - Add SnapshotSelection struct for time-travel snapshot resolution - Add supports_time_travel() concrete method driven by kind() - Implement SnapshotsTable::Scan() to materialize snapshot rows via ArrowRowBuilder
There was a problem hiding this comment.
Pull request overview
Implements initial metadata-table scanning support by adding a Scan() API to MetadataTable (with snapshot-selection parameters for future time-travel) and providing a concrete SnapshotsTable::Scan() implementation that materializes snapshot rows into Arrow arrays. The PR also restructures/extends the metadata-table test suite to validate schemas and snapshot scanning behavior.
Changes:
- Added
SnapshotSelectionand a virtualMetadataTable::Scan()API (with a convenience overload) plussupports_time_travel(). - Implemented
SnapshotsTable::Scan()to emit snapshot rows (6 columns) viaArrowRowBuilder. - Added/expanded tests and wired new test sources into the metadata-table test target.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/iceberg/inspect/metadata_table.h | Adds SnapshotSelection, Scan() API, and supports_time_travel() declaration/docs. |
| src/iceberg/inspect/metadata_table.cc | Implements default Scan() + supports_time_travel() and wires factory for kinds. |
| src/iceberg/inspect/snapshots_table.h | Declares SnapshotsTable::Scan() override. |
| src/iceberg/inspect/snapshots_table.cc | Implements snapshot scanning into Arrow via ArrowRowBuilder. |
| src/iceberg/test/metadata_table_test.cc | Simplifies base setup and adds SupportsTimeTravel test. |
| src/iceberg/test/metadata_table_test_base.h | New shared fixture/helpers for metadata table tests. |
| src/iceberg/test/snapshots_table_test.cc | New tests validating snapshots table construction/schema/scan output. |
| src/iceberg/test/history_table_test.cc | New schema test for history table. |
| src/iceberg/test/CMakeLists.txt | Adds new test sources to the metadata-table test target. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/iceberg/inspect/metadata_table.cc:38
supports_time_travel()is currently hard-coded to return false. That matches today’s twoKindvalues, but it’s easy to forget to update once additional metadata table kinds are added, and it doesn’t reflect the docstring/PR description that this is kind-driven. Consider switching onkind()and making the non-exhaustive case unreachable to keep future additions honest.
bool MetadataTable::supports_time_travel() const noexcept { return false; }
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
| metadata_ = std::make_shared<TableMetadata>( | ||
| TableMetadata{.format_version = 2, .schemas = {schema}, .current_schema_id = 1}); |
| auto metadata = std::make_shared<TableMetadata>( | ||
| TableMetadata{.format_version = 2, .schemas = {schema}, .current_schema_id = 1}); |
| TEST_F(SnapshotsTableTest, ScanEmptySnapshotList) { | ||
| // A table with zero snapshots should return zero rows. | ||
| ICEBERG_UNWRAP_OR_FAIL(auto empty_table, | ||
| MakeTableWithSnapshots({}, /*current_snapshot_id=*/-1)); |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/iceberg/inspect/metadata_table.cc:38
- supports_time_travel() is documented (and described in the PR) as being driven by the metadata table kind, but the implementation always returns false regardless of kind. This makes the API misleading and forces future kinds to remember to update callers rather than the method itself.
bool MetadataTable::supports_time_travel() const noexcept { return false; }
| for (const auto& snapshot : source_table()->snapshots()) { | ||
| // column 0: committed_at (timestamptz -> int64 micros) |
| static std::shared_ptr<::arrow::RecordBatch> FinishAndImport(ArrowArray&& array, | ||
| const Schema& schema) { | ||
| ArrowSchema c_schema{}; | ||
| EXPECT_THAT(ToArrowSchema(schema, &c_schema), IsOk()); | ||
| auto arrow_schema = ::arrow::ImportSchema(&c_schema).ValueOrDie(); | ||
|
|
||
| // ImportRecordBatch takes ownership of the array and releases it. | ||
| return ::arrow::ImportRecordBatch(&array, arrow_schema).ValueOrDie(); | ||
| } |
Summary
Implement
Scan()forSnapshotsTable, adding the core scanning infrastructure toMetadataTableand materializing snapshot rows into Arrow arrays viaArrowRowBuilder.Changes
metadata_table.h/.ccSnapshotSelectionstruct withsnapshot_id,as_of_timestamp,ref_nameoptional fields for time-travel queriesScan()virtual method returningResult<ArrowArray>with a convenience zero-arg overloadsupports_time_travel()concrete method driven bykind(), matching Java'sTIME_TRAVEL_TABLE_TYPESstatic set (currently bothkSnapshotsandkHistoryreturnfalse)Scan()returnsNotSupportedsnapshots_table.h/.ccSnapshotsTable::Scan()— iteratessource_table()->snapshots()and writes 6 columns (committed_at,snapshot_id,parent_id,operation,manifest_list,summary) viaArrowRowBuildersnap.timestampMillis() \* 1000Tests
metadata_table_test_base.h— sharedMetadataTableTestBasewithMockFileIO+MockCatalogfixture,FinishAndImport(),MakeTestSnapshots(),MakeTableWithSnapshots()helpersmetadata_table_test.cc— 2 framework tests (FactoryRejectsNullSourceTable,SupportsTimeTravel)snapshots_table_test.cc— 11 tests (Construct,SchemaMatchesIcebergSchema, 9 scan data tests matching JavaTestDataTaskParserfixture)history_table_test.cc— 1 schema test