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


##########
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:
   The supports_time_travel() doc describes several metadata table kinds 
(Entries/Files/Manifests/Partitions/Refs/All*) that don't exist in 
MetadataTable::Kind yet (only kSnapshots/kHistory are defined). This makes the 
public API documentation misleading; either narrow the doc to the currently 
implemented kinds or expand Kind/supports_time_travel alongside the doc.



##########
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:
   FinishAndImport() declares ArrowSchema without initialization. If 
ToArrowSchema() ever returns early before calling ArrowSchemaInit (e.g., schema 
not Arrow-compatible), passing an uninitialized ArrowSchema into 
arrow::ImportSchema() is undefined behavior. Initializing the struct avoids 
that failure mode.



##########
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:
   supports_time_travel() currently always returns false, but the comment 
describes logic about "tables that read from a single snapshot's manifests". 
Either simplify the implementation/comment to reflect current reality (only 
Snapshots/History exist and neither supports time travel), or implement the 
intended kind-based allowlist when additional kinds are added.



##########
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:
   Scan() takes std::optional<SnapshotSelection> by value. Because 
SnapshotSelection may carry a std::string (ref_name), this forces an avoidable 
copy at every call site and bakes that cost into a virtual public API. Consider 
taking `const std::optional<SnapshotSelection>&` instead (and update 
overrides/callers accordingly) before the API becomes harder to change.



-- 
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