WZhuo commented on code in PR #801: URL: https://github.com/apache/iceberg-cpp/pull/801#discussion_r3689086773
########## 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/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]
