WZhuo commented on code in PR #801:
URL: https://github.com/apache/iceberg-cpp/pull/801#discussion_r3689086641


##########
src/iceberg/test/metadata_table_test.cc:
##########
@@ -33,88 +33,40 @@
 #include "iceberg/type.h"
 
 namespace iceberg {
-namespace {
-
-std::shared_ptr<Schema> MakeSnapshotsSchema() {
-  return std::make_shared<Schema>(std::vector<SchemaField>{
-      SchemaField::MakeRequired(1, "committed_at", timestamp_tz()),
-      SchemaField::MakeRequired(2, "snapshot_id", int64()),
-      SchemaField::MakeOptional(3, "parent_id", int64()),
-      SchemaField::MakeOptional(4, "operation", string()),
-      SchemaField::MakeOptional(5, "manifest_list", string()),
-      SchemaField::MakeOptional(
-          6, "summary",
-          std::make_shared<MapType>(SchemaField::MakeRequired(7, "key", 
string()),
-                                    SchemaField::MakeRequired(8, "value", 
string())))});
-}
-
-std::shared_ptr<Schema> MakeHistorySchema() {
-  return std::make_shared<Schema>(std::vector<SchemaField>{
-      SchemaField::MakeRequired(1, "made_current_at", timestamp_tz()),
-      SchemaField::MakeRequired(2, "snapshot_id", int64()),
-      SchemaField::MakeOptional(3, "parent_id", int64()),
-      SchemaField::MakeRequired(4, "is_current_ancestor", boolean())});
-}
-
-}  // namespace
 
 class MetadataTableTest : public ::testing::Test {
  protected:
   void SetUp() override {
-    io_ = std::make_shared<MockFileIO>();
-    catalog_ = std::make_shared<MockCatalog>();
-
     auto schema = std::make_shared<Schema>(
         std::vector<SchemaField>{SchemaField::MakeRequired(1, "id", int64()),
                                  SchemaField::MakeOptional(2, "name", 
string())},
         1);
-    metadata_ = std::make_shared<TableMetadata>(
+    auto metadata = std::make_shared<TableMetadata>(
         TableMetadata{.format_version = 2, .schemas = {schema}, 
.current_schema_id = 1});

Review Comment:
   Fixed. This fixture now explicitly sets `current_snapshot_id = 
kInvalidSnapshotId`.



##########
src/iceberg/inspect/metadata_table.h:
##########
@@ -46,6 +60,28 @@ class ICEBERG_EXPORT MetadataTable {
 
   virtual Kind kind() const noexcept = 0;
 
+  /// \brief Whether this metadata table supports time-travel queries.
+  ///
+  /// Time travel is supported for tables that read from a single snapshot's
+  /// manifests (e.g., Entries, Files, Manifests, Partitions). Tables that
+  /// scan all snapshots (All*) or return in-memory history (Snapshots,
+  /// History, Refs) do not support time travel.

Review Comment:
   Fixed. The documentation now describes the metadata-table capability 
directly, and time-travel behavior is represented by the separate 
`TimeTravelMetadataTable` interface instead of listing unimplemented table 
kinds.



##########
src/iceberg/test/snapshots_table_test.cc:
##########
@@ -0,0 +1,175 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <cstdint>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include <arrow/array.h>
+#include <arrow/c/bridge.h>
+#include <arrow/record_batch.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "iceberg/inspect/metadata_table.h"
+#include "iceberg/schema.h"
+#include "iceberg/schema_field.h"
+#include "iceberg/test/matchers.h"
+#include "iceberg/test/metadata_table_test_base.h"
+#include "iceberg/type.h"
+
+namespace iceberg {
+namespace {
+
+std::shared_ptr<Schema> MakeSnapshotsSchema() {
+  return std::make_shared<Schema>(std::vector<SchemaField>{
+      SchemaField::MakeRequired(1, "committed_at", timestamp_tz()),
+      SchemaField::MakeRequired(2, "snapshot_id", int64()),
+      SchemaField::MakeOptional(3, "parent_id", int64()),
+      SchemaField::MakeOptional(4, "operation", string()),
+      SchemaField::MakeOptional(5, "manifest_list", string()),
+      SchemaField::MakeOptional(
+          6, "summary",
+          std::make_shared<MapType>(SchemaField::MakeRequired(7, "key", 
string()),
+                                    SchemaField::MakeRequired(8, "value", 
string())))});
+}
+
+std::vector<std::pair<std::string, std::string>> GetMapEntries(
+    const std::shared_ptr<::arrow::MapArray>& map_array, int64_t row) {
+  auto keys = 
std::static_pointer_cast<::arrow::StringArray>(map_array->keys());
+  auto values = 
std::static_pointer_cast<::arrow::StringArray>(map_array->items());
+  std::vector<std::pair<std::string, std::string>> entries;
+  entries.reserve(map_array->value_length(row));
+  const auto offset = map_array->value_offset(row);
+  for (int64_t index = offset; index < offset + map_array->value_length(row); 
++index) {
+    entries.emplace_back(keys->GetString(index), values->GetString(index));
+  }
+  return entries;
+}
+
+}  // namespace
+
+class SnapshotsTableTest : public MetadataTableTestBase {
+ protected:
+  void SetUp() override {
+    MetadataTableTestBase::SetUp();
+
+    auto [snap1, snap2] = MakeTestSnapshots();
+    ICEBERG_UNWRAP_OR_FAIL(
+        table_, MakeTableWithSnapshots({snap1, snap2}, 
/*current_snapshot_id=*/2));
+
+    ICEBERG_UNWRAP_OR_FAIL(snapshots_table_,
+                           MetadataTable::Make(table_, 
MetadataTable::Kind::kSnapshots));
+  }
+
+  std::unique_ptr<MetadataTable> snapshots_table_;
+};
+
+TEST_F(SnapshotsTableTest, Construct) {
+  EXPECT_EQ(snapshots_table_->kind(), MetadataTable::Kind::kSnapshots);
+  EXPECT_EQ(snapshots_table_->source_table(), table_);
+  EXPECT_EQ(snapshots_table_->name().name, "test_table.snapshots");
+  EXPECT_EQ(snapshots_table_->name().ns.levels, 
(std::vector<std::string>{"db"}));
+  EXPECT_NE(snapshots_table_->schema(), nullptr);
+}
+
+TEST_F(SnapshotsTableTest, SchemaMatchesIcebergSchema) {
+  EXPECT_TRUE(*snapshots_table_->schema() == *MakeSnapshotsSchema());
+}
+
+TEST_F(SnapshotsTableTest, Scan) {
+  // Scan the snapshots table once and verify all columns of the result.
+  ICEBERG_UNWRAP_OR_FAIL(auto array, snapshots_table_->Scan());
+  auto batch = FinishAndImport(std::move(array), *snapshots_table_->schema());
+
+  // Row and column counts.
+  EXPECT_EQ(batch->num_rows(), 2);
+  EXPECT_EQ(batch->num_columns(), 6);
+
+  // Column 0: committed_at (timestamptz) — microseconds since epoch.
+  auto committed_at = 
std::static_pointer_cast<::arrow::TimestampArray>(batch->column(0));
+  EXPECT_EQ(committed_at->Value(0), 1234567890000 * 1000);
+  EXPECT_EQ(committed_at->Value(1), 9876543210000 * 1000);
+
+  // Column 1: snapshot_id (long) — returned in storage order.
+  auto snapshot_ids = 
std::static_pointer_cast<::arrow::Int64Array>(batch->column(1));
+  EXPECT_EQ(snapshot_ids->Value(0), 1);
+  EXPECT_EQ(snapshot_ids->Value(1), 2);
+
+  // Column 2: parent_id (long) — first snapshot has no parent.
+  auto parent_ids = 
std::static_pointer_cast<::arrow::Int64Array>(batch->column(2));
+  EXPECT_TRUE(parent_ids->IsNull(0));
+  EXPECT_FALSE(parent_ids->IsNull(1));
+  EXPECT_EQ(parent_ids->Value(1), 1);
+
+  // Column 3: operation (string).
+  auto operations = 
std::static_pointer_cast<::arrow::StringArray>(batch->column(3));
+  EXPECT_EQ(operations->GetString(0), "append");
+  EXPECT_EQ(operations->GetString(1), "append");
+
+  // Column 4: manifest_list (string).
+  auto manifest_lists = 
std::static_pointer_cast<::arrow::StringArray>(batch->column(4));
+  EXPECT_EQ(manifest_lists->GetString(0), "file:/tmp/manifest1.avro");
+  EXPECT_EQ(manifest_lists->GetString(1), "file:/tmp/manifest2.avro");
+
+  // Column 5: summary (map<string,string>) — each summary has 11 entries
+  // (10 data + 1 operation).
+  auto summaries = 
std::static_pointer_cast<::arrow::MapArray>(batch->column(5));
+  EXPECT_FALSE(summaries->IsNull(0));
+  EXPECT_FALSE(summaries->IsNull(1));
+  EXPECT_EQ(summaries->value_length(0), 11);
+  EXPECT_EQ(summaries->value_length(1), 11);
+
+  auto first_summary = GetMapEntries(summaries, 0);
+  EXPECT_THAT(first_summary, ::testing::Contains(::testing::Pair("operation", 
"append")));
+  EXPECT_THAT(first_summary, 
::testing::Contains(::testing::Pair("total-records", "1")));
+
+  auto second_summary = GetMapEntries(summaries, 1);
+  EXPECT_THAT(second_summary,
+              ::testing::Contains(::testing::Pair("operation", "append")));
+  EXPECT_THAT(second_summary, 
::testing::Contains(::testing::Pair("total-records", "2")));
+}
+
+TEST_F(SnapshotsTableTest, ScanSnapshotSelectionIgnored) {
+  // SnapshotsTable always returns all snapshots regardless of selection.
+  SnapshotSelection sel{.snapshot_id = 999};
+  ICEBERG_UNWRAP_OR_FAIL(auto array, snapshots_table_->Scan(sel));
+  auto batch = FinishAndImport(std::move(array), *snapshots_table_->schema());
+  // Should still return all 2 snapshots, not filtered to snapshot 999.
+  EXPECT_EQ(batch->num_rows(), 2);
+}
+
+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));

Review Comment:
   Fixed. The empty-table test now uses the shared `kInvalidSnapshotId` 
constant.



##########
src/iceberg/inspect/metadata_table.cc:
##########
@@ -35,6 +35,23 @@ MetadataTable::MetadataTable(std::shared_ptr<Table> 
source_table,
 
 MetadataTable::~MetadataTable() = default;
 
+bool MetadataTable::supports_time_travel() const noexcept {
+  // Time travel is supported for tables that read from a single snapshot's
+  // manifests. Tables that scan all snapshots or return in-memory history do
+  // not.
+  switch (kind()) {
+    case Kind::kSnapshots:
+    case Kind::kHistory:
+      return false;
+  }
+  return false;
+}

Review Comment:
   Fixed. `MetadataTable::supports_time_travel()` returns false, while 
`TimeTravelMetadataTable` overrides it to return true. The comments now match 
this capability split.



##########
src/iceberg/test/metadata_table_test_base.h:
##########
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/// \file metadata_table_test_base.h
+/// Shared test base for all metadata table tests.
+///
+/// Provides common helpers (FinishAndImport, MakeTestSnapshots,
+/// MakeTableWithSnapshots) and the MockFileIO + MockCatalog fixture that
+/// every metadata table test needs.
+
+#pragma once
+
+#include <memory>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+#include <arrow/array.h>
+#include <arrow/c/bridge.h>
+#include <arrow/record_batch.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "iceberg/schema.h"
+#include "iceberg/schema_field.h"
+#include "iceberg/schema_internal.h"
+#include "iceberg/snapshot.h"
+#include "iceberg/table.h"
+#include "iceberg/table_identifier.h"
+#include "iceberg/table_metadata.h"
+#include "iceberg/test/matchers.h"
+#include "iceberg/test/mock_catalog.h"
+#include "iceberg/test/mock_io.h"
+#include "iceberg/type.h"
+#include "iceberg/util/timepoint.h"
+
+namespace iceberg {
+
+/// \brief Base class for all metadata table tests.
+///
+/// Provides MockFileIO and MockCatalog instances plus helpers shared across
+/// metadata table tests (SnapshotsTable, HistoryTable, RefsTable, ...).
+class MetadataTableTestBase : public ::testing::Test {
+ protected:
+  void SetUp() override {
+    io_ = std::make_shared<MockFileIO>();
+    catalog_ = std::make_shared<MockCatalog>();
+
+    auto schema = std::make_shared<Schema>(
+        std::vector<SchemaField>{SchemaField::MakeRequired(1, "id", int64()),
+                                 SchemaField::MakeOptional(2, "name", 
string())},
+        1);
+    metadata_ = std::make_shared<TableMetadata>(
+        TableMetadata{.format_version = 2, .schemas = {schema}, 
.current_schema_id = 1});
+
+    TableIdentifier source_ident{.ns = Namespace{.levels = {"db"}},
+                                 .name = "source_table"};
+    ICEBERG_UNWRAP_OR_FAIL(table_, Table::Make(source_ident, metadata_,
+                                               "s3://bucket/meta.json", io_, 
catalog_));
+  }
+
+  /// \brief Import a Scan()-produced ArrowArray into an Arrow RecordBatch.
+  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();
+  }

Review Comment:
   Fixed by removing `FinishAndImport`. `ReadAllBatches` now accepts 
`ArrowArrayStream&&` and transfers stream ownership to the Arrow reader.



##########
src/iceberg/test/snapshots_table_test.cc:
##########
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <memory>
+#include <utility>
+
+#include <arrow/array.h>
+#include <arrow/c/bridge.h>
+#include <arrow/record_batch.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "iceberg/inspect/metadata_table.h"
+#include "iceberg/schema.h"
+#include "iceberg/schema_field.h"
+#include "iceberg/test/matchers.h"
+#include "iceberg/test/metadata_table_test_base.h"
+#include "iceberg/type.h"
+
+namespace iceberg {
+namespace {
+
+std::shared_ptr<Schema> MakeSnapshotsSchema() {
+  return std::make_shared<Schema>(std::vector<SchemaField>{
+      SchemaField::MakeRequired(1, "committed_at", timestamp_tz()),
+      SchemaField::MakeRequired(2, "snapshot_id", int64()),
+      SchemaField::MakeOptional(3, "parent_id", int64()),
+      SchemaField::MakeOptional(4, "operation", string()),
+      SchemaField::MakeOptional(5, "manifest_list", string()),
+      SchemaField::MakeOptional(
+          6, "summary",
+          std::make_shared<MapType>(SchemaField::MakeRequired(7, "key", 
string()),
+                                    SchemaField::MakeRequired(8, "value", 
string())))});
+}
+
+}  // namespace
+
+class SnapshotsTableTest : public MetadataTableTestBase {
+ protected:
+  void SetUp() override {
+    MetadataTableTestBase::SetUp();
+
+    auto [snap1, snap2] = MakeTestSnapshots();
+    snap1_ = snap1;
+    snap2_ = snap2;
+
+    ICEBERG_UNWRAP_OR_FAIL(
+        table_, MakeTableWithSnapshots({snap1, snap2}, 
/*current_snapshot_id=*/2));
+
+    ICEBERG_UNWRAP_OR_FAIL(snapshots_table_,
+                           MetadataTable::Make(table_, 
MetadataTable::Kind::kSnapshots));
+  }
+
+  std::shared_ptr<Table> table_;
+  std::shared_ptr<Snapshot> snap1_;
+  std::shared_ptr<Snapshot> snap2_;
+  std::unique_ptr<MetadataTable> snapshots_table_;
+};
+
+TEST_F(SnapshotsTableTest, Construct) {
+  ICEBERG_UNWRAP_OR_FAIL(snapshots_table_,
+                         MetadataTable::Make(MetadataTableTestBase::table_,
+                                             MetadataTable::Kind::kSnapshots));
+  EXPECT_EQ(snapshots_table_->kind(), MetadataTable::Kind::kSnapshots);
+  EXPECT_EQ(snapshots_table_->source_table(), MetadataTableTestBase::table_);
+  EXPECT_EQ(snapshots_table_->name().name, "source_table.snapshots");
+  EXPECT_EQ(snapshots_table_->name().ns.levels, 
(std::vector<std::string>{"db"}));
+  EXPECT_NE(snapshots_table_->schema(), nullptr);
+}
+
+TEST_F(SnapshotsTableTest, SchemaMatchesIcebergSchema) {
+  ICEBERG_UNWRAP_OR_FAIL(snapshots_table_,
+                         MetadataTable::Make(MetadataTableTestBase::table_,
+                                             MetadataTable::Kind::kSnapshots));
+  EXPECT_TRUE(*snapshots_table_->schema() == *MakeSnapshotsSchema());
+}
+
+TEST_F(SnapshotsTableTest, Scan) {
+  // Scan the snapshots table once and verify all columns of the result.
+  ICEBERG_UNWRAP_OR_FAIL(auto array, snapshots_table_->Scan());
+  auto batch = FinishAndImport(std::move(array), *snapshots_table_->schema());
+
+  // Row and column counts.
+  EXPECT_EQ(batch->num_rows(), 2);
+  EXPECT_EQ(batch->num_columns(), 6);
+
+  // Column 0: committed_at (timestamptz) — microseconds since epoch.
+  auto committed_at = 
std::static_pointer_cast<::arrow::TimestampArray>(batch->column(0));
+  EXPECT_EQ(committed_at->Value(0), 1234567890000 * 1000);
+  EXPECT_EQ(committed_at->Value(1), 9876543210000 * 1000);
+
+  // Column 1: snapshot_id (long) — returned in storage order.
+  auto snapshot_ids = 
std::static_pointer_cast<::arrow::Int64Array>(batch->column(1));
+  EXPECT_EQ(snapshot_ids->Value(0), 1);
+  EXPECT_EQ(snapshot_ids->Value(1), 2);
+
+  // Column 2: parent_id (long) — first snapshot has no parent.
+  auto parent_ids = 
std::static_pointer_cast<::arrow::Int64Array>(batch->column(2));
+  EXPECT_TRUE(parent_ids->IsNull(0));
+  EXPECT_FALSE(parent_ids->IsNull(1));
+  EXPECT_EQ(parent_ids->Value(1), 1);
+
+  // Column 3: operation (string).
+  auto operations = 
std::static_pointer_cast<::arrow::StringArray>(batch->column(3));
+  EXPECT_EQ(operations->GetString(0), "append");
+  EXPECT_EQ(operations->GetString(1), "append");
+
+  // Column 4: manifest_list (string).
+  auto manifest_lists = 
std::static_pointer_cast<::arrow::StringArray>(batch->column(4));
+  EXPECT_EQ(manifest_lists->GetString(0), "file:/tmp/manifest1.avro");
+  EXPECT_EQ(manifest_lists->GetString(1), "file:/tmp/manifest2.avro");
+
+  // Column 5: summary (map<string,string>) — each summary has 11 entries
+  // (10 data + 1 operation).
+  auto summaries = 
std::static_pointer_cast<::arrow::MapArray>(batch->column(5));
+  EXPECT_FALSE(summaries->IsNull(0));
+  EXPECT_FALSE(summaries->IsNull(1));
+  EXPECT_EQ(summaries->value_length(0), 11);
+  EXPECT_EQ(summaries->value_length(1), 11);
+}

Review Comment:
   Fixed. The test now verifies that `operation` is absent and checks the 
`total-records` value for both summary rows.



##########
src/iceberg/test/snapshots_table_test.cc:
##########
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include <memory>
+#include <utility>
+
+#include <arrow/array.h>
+#include <arrow/c/bridge.h>
+#include <arrow/record_batch.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "iceberg/inspect/metadata_table.h"
+#include "iceberg/schema.h"
+#include "iceberg/schema_field.h"
+#include "iceberg/test/matchers.h"
+#include "iceberg/test/metadata_table_test_base.h"
+#include "iceberg/type.h"
+
+namespace iceberg {
+namespace {
+
+std::shared_ptr<Schema> MakeSnapshotsSchema() {
+  return std::make_shared<Schema>(std::vector<SchemaField>{
+      SchemaField::MakeRequired(1, "committed_at", timestamp_tz()),
+      SchemaField::MakeRequired(2, "snapshot_id", int64()),
+      SchemaField::MakeOptional(3, "parent_id", int64()),
+      SchemaField::MakeOptional(4, "operation", string()),
+      SchemaField::MakeOptional(5, "manifest_list", string()),
+      SchemaField::MakeOptional(
+          6, "summary",
+          std::make_shared<MapType>(SchemaField::MakeRequired(7, "key", 
string()),
+                                    SchemaField::MakeRequired(8, "value", 
string())))});
+}
+
+}  // namespace
+
+class SnapshotsTableTest : public MetadataTableTestBase {
+ protected:
+  void SetUp() override {
+    MetadataTableTestBase::SetUp();
+
+    auto [snap1, snap2] = MakeTestSnapshots();
+    snap1_ = snap1;
+    snap2_ = snap2;
+
+    ICEBERG_UNWRAP_OR_FAIL(
+        table_, MakeTableWithSnapshots({snap1, snap2}, 
/*current_snapshot_id=*/2));
+
+    ICEBERG_UNWRAP_OR_FAIL(snapshots_table_,
+                           MetadataTable::Make(table_, 
MetadataTable::Kind::kSnapshots));
+  }
+
+  std::shared_ptr<Table> table_;
+  std::shared_ptr<Snapshot> snap1_;
+  std::shared_ptr<Snapshot> snap2_;
+  std::unique_ptr<MetadataTable> snapshots_table_;

Review Comment:
   Fixed. The unused snapshot members and the shadowing fixture table were 
removed; the test now uses `MetadataTableTestBase::table_`.



##########
src/iceberg/test/metadata_table_test_base.h:
##########
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/// \file metadata_table_test_base.h
+/// Shared test base for all metadata table tests.
+///
+/// Provides common helpers (FinishAndImport, MakeTestSnapshots,
+/// MakeTableWithSnapshots) and the MockFileIO + MockCatalog fixture that
+/// every metadata table test needs.
+
+#pragma once
+
+#include <memory>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+#include <arrow/array.h>
+#include <arrow/c/bridge.h>
+#include <arrow/record_batch.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "iceberg/schema.h"
+#include "iceberg/schema_field.h"
+#include "iceberg/schema_internal.h"
+#include "iceberg/snapshot.h"
+#include "iceberg/table.h"
+#include "iceberg/table_identifier.h"
+#include "iceberg/table_metadata.h"
+#include "iceberg/test/matchers.h"
+#include "iceberg/test/mock_catalog.h"
+#include "iceberg/test/mock_io.h"
+#include "iceberg/type.h"
+#include "iceberg/util/timepoint.h"
+
+namespace iceberg {
+
+/// \brief Base class for all metadata table tests.
+///
+/// Provides MockFileIO and MockCatalog instances plus helpers shared across
+/// metadata table tests (SnapshotsTable, HistoryTable, RefsTable, ...).
+class MetadataTableTestBase : public ::testing::Test {
+ protected:
+  void SetUp() override {
+    io_ = std::make_shared<MockFileIO>();
+    catalog_ = std::make_shared<MockCatalog>();
+
+    auto schema = std::make_shared<Schema>(
+        std::vector<SchemaField>{SchemaField::MakeRequired(1, "id", int64()),
+                                 SchemaField::MakeOptional(2, "name", 
string())},
+        1);
+    metadata_ = std::make_shared<TableMetadata>(
+        TableMetadata{.format_version = 2, .schemas = {schema}, 
.current_schema_id = 1});
+
+    TableIdentifier source_ident{.ns = Namespace{.levels = {"db"}},
+                                 .name = "source_table"};
+    ICEBERG_UNWRAP_OR_FAIL(table_, Table::Make(source_ident, metadata_,
+                                               "s3://bucket/meta.json", io_, 
catalog_));
+  }
+
+  /// \brief Import a Scan()-produced ArrowArray into an Arrow RecordBatch.
+  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();

Review Comment:
   Fixed by removing `FinishAndImport`. Tests now consume `ArrowArrayStream` 
through `ImportRecordBatchReader`, so no uninitialized `ArrowSchema` is passed 
to Arrow.



##########
src/iceberg/test/metadata_table_test_base.h:
##########
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/// \file metadata_table_test_base.h
+/// Shared test base for all metadata table tests.
+///
+/// Provides common helpers (FinishAndImport, MakeTestSnapshots,
+/// MakeTableWithSnapshots) and the MockFileIO + MockCatalog fixture that
+/// every metadata table test needs.
+
+#pragma once
+
+#include <memory>
+#include <unordered_map>
+#include <utility>
+#include <vector>
+
+#include <arrow/array.h>
+#include <arrow/c/bridge.h>
+#include <arrow/record_batch.h>
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "iceberg/schema.h"
+#include "iceberg/schema_field.h"
+#include "iceberg/schema_internal.h"
+#include "iceberg/snapshot.h"
+#include "iceberg/table.h"
+#include "iceberg/table_identifier.h"
+#include "iceberg/table_metadata.h"
+#include "iceberg/test/matchers.h"
+#include "iceberg/test/mock_catalog.h"
+#include "iceberg/test/mock_io.h"
+#include "iceberg/type.h"
+#include "iceberg/util/timepoint.h"
+
+namespace iceberg {
+
+/// \brief Base class for all metadata table tests.
+///
+/// Provides MockFileIO and MockCatalog instances plus helpers shared across
+/// metadata table tests (SnapshotsTable, HistoryTable, RefsTable, ...).
+class MetadataTableTestBase : public ::testing::Test {
+ protected:
+  void SetUp() override {
+    io_ = std::make_shared<MockFileIO>();
+    catalog_ = std::make_shared<MockCatalog>();
+
+    auto schema = std::make_shared<Schema>(
+        std::vector<SchemaField>{SchemaField::MakeRequired(1, "id", int64()),
+                                 SchemaField::MakeOptional(2, "name", 
string())},
+        1);
+    metadata_ = std::make_shared<TableMetadata>(
+        TableMetadata{.format_version = 2, .schemas = {schema}, 
.current_schema_id = 1});

Review Comment:
   Fixed. The shared metadata-table fixture now explicitly sets 
`current_snapshot_id = kInvalidSnapshotId`.



##########
src/iceberg/inspect/metadata_table.h:
##########
@@ -46,6 +60,28 @@ class ICEBERG_EXPORT MetadataTable {
 
   virtual Kind kind() const noexcept = 0;
 
+  /// \brief Whether this metadata table supports time-travel queries.
+  ///
+  /// Time travel is supported for tables that read from a single snapshot's
+  /// manifests (e.g., Entries, Files, Manifests, Partitions). Tables that
+  /// scan all snapshots (All*) or return in-memory history (Snapshots,
+  /// History, Refs) do not support time travel.
+  bool supports_time_travel() const noexcept;
+
+  /// \brief Scan the metadata table using the current snapshot.
+  ///
+  /// Convenience overload — delegates to Scan(std::nullopt).
+  Result<ArrowArray> Scan() { return Scan(std::nullopt); }
+
+  /// \brief Scan the metadata table and return all rows as an Arrow struct 
array.
+  ///
+  /// The returned ArrowArray is a struct array where each element is one row.
+  /// The caller takes ownership and must call ArrowArrayRelease when done.
+  ///
+  /// The default implementation returns NotSupported. Subclasses override this
+  /// to materialize their data.
+  virtual Result<ArrowArray> Scan(std::optional<SnapshotSelection> 
snapshot_selection);

Review Comment:
   Fixed. The time-travel overload now takes `const SnapshotSelection&`; 
metadata tables that do not support time travel do not expose that overload.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to