Copilot commented on code in PR #801:
URL: https://github.com/apache/iceberg-cpp/pull/801#discussion_r3642442578
##########
src/iceberg/inspect/snapshots_table.cc:
##########
@@ -65,4 +68,46 @@ Result<std::unique_ptr<SnapshotsTable>> SnapshotsTable::Make(
return std::unique_ptr<SnapshotsTable>(new SnapshotsTable(std::move(table)));
}
+Result<ArrowArray> SnapshotsTable::Scan(
+ const std::optional<SnapshotSelection>& /*snapshot_selection*/) {
+ ICEBERG_ASSIGN_OR_RAISE(auto builder, ArrowRowBuilder::Make(*schema()));
+
+ for (const auto& snapshot : source_table()->snapshots()) {
+ // column 0: committed_at (timestamptz -> int64 micros)
Review Comment:
SnapshotsTable::Scan() unconditionally dereferences entries from
source_table()->snapshots(). Other code (e.g., TableMetadata::SnapshotById)
defensively checks for nullptr snapshots, so this loop can crash if the
snapshots vector contains a null entry.
##########
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:
FinishAndImport() uses EXPECT_THAT(ToArrowSchema(...), IsOk()) but then
unconditionally calls ValueOrDie() on the Arrow results. If
ToArrowSchema/ImportSchema/ImportRecordBatch fails, the test will hard-abort
instead of producing a normal assertion failure, which can make failures harder
to diagnose.
--
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]