Skip to content

Commit 6c646e0

Browse files
All-lesswgtmac
authored andcommitted
Update MetadataTable to inherit from StaticTable
1 parent df05375 commit 6c646e0

12 files changed

Lines changed: 116 additions & 195 deletions

src/iceberg/inspect/history_table.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,19 @@
3131
namespace iceberg {
3232

3333
HistoryTable::HistoryTable(std::shared_ptr<Table> table)
34-
: BaseMetadataTable(table, CreateName(table->name()), CreateSchema()) {}
35-
36-
HistoryTable::~HistoryTable() = default;
37-
38-
std::shared_ptr<Schema> HistoryTable::CreateSchema() {
39-
return std::make_shared<Schema>(
34+
: MetadataTable(table, CreateName(table->name())) {
35+
this->schema_ = std::make_shared<Schema>(
4036
std::vector<SchemaField>{
41-
SchemaField::MakeRequired(1, "made_current_at", int64()),
37+
SchemaField::MakeRequired(1, "made_current_at", timestamp_tz()),
4238
SchemaField::MakeRequired(2, "snapshot_id", int64()),
4339
SchemaField::MakeOptional(3, "parent_id", int64()),
4440
SchemaField::MakeRequired(4, "is_current_ancestor", boolean())},
4541
1);
42+
this->schemas_[schema_->schema_id()] = schema_;
4643
}
4744

45+
HistoryTable::~HistoryTable() = default;
46+
4847
TableIdentifier HistoryTable::CreateName(const TableIdentifier& source_name) {
4948
return TableIdentifier{source_name.ns, source_name.name + ".history"};
5049
}

src/iceberg/inspect/history_table.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace iceberg {
3636
/// - snapshot_id (long)
3737
/// - parent_id (long, optional)
3838
/// - is_current_ancestor (bool)
39-
class ICEBERG_EXPORT HistoryTable : public BaseMetadataTable {
39+
class ICEBERG_EXPORT HistoryTable : public MetadataTable {
4040
public:
4141
/// \brief Create a HistoryTable from table metadata
4242
///
@@ -46,8 +46,10 @@ class ICEBERG_EXPORT HistoryTable : public BaseMetadataTable {
4646

4747
~HistoryTable() override;
4848

49+
MetadataTableType type() const noexcept override { return MetadataTableType::kHistory; }
50+
4951
private:
50-
HistoryTable(std::shared_ptr<Table> table);
52+
explicit HistoryTable(std::shared_ptr<Table> table);
5153

5254
std::shared_ptr<Schema> CreateSchema();
5355

src/iceberg/inspect/metadata_table.cc

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,64 +24,44 @@
2424
#include <utility>
2525

2626
#include "iceberg/file_io.h"
27+
#include "iceberg/inspect/history_table.h"
28+
#include "iceberg/inspect/snapshots_table.h"
2729
#include "iceberg/schema.h"
2830
#include "iceberg/schema_field.h"
2931
#include "iceberg/table_identifier.h"
3032
#include "iceberg/table_metadata.h"
3133
#include "iceberg/table_scan.h"
3234
#include "iceberg/type.h"
35+
#include "iceberg/type_fwd.h"
3336
#include "iceberg/util/uuid.h"
3437

3538
namespace iceberg {
3639

37-
BaseMetadataTable::BaseMetadataTable(std::shared_ptr<Table> source_table,
38-
TableIdentifier identifier,
39-
std::shared_ptr<Schema> schema)
40-
: Table(identifier, source_table->metadata(),
41-
std::string(source_table->metadata_file_location()), source_table->io(),
42-
source_table->catalog()),
43-
source_table_(std::move(source_table)),
44-
schema_(schema) {
40+
MetadataTable::MetadataTable(std::shared_ptr<Table> source_table,
41+
TableIdentifier identifier)
42+
: StaticTable(identifier, source_table->metadata(),
43+
std::string(source_table->metadata_file_location()), source_table->io(),
44+
source_table->catalog()),
45+
source_table_(std::move(source_table)) {
4546
uuid_ = Uuid::GenerateV4().ToString();
46-
schemas_[schema->schema_id()] = schema;
4747
}
4848

49-
BaseMetadataTable::~BaseMetadataTable() = default;
49+
MetadataTable::~MetadataTable() = default;
5050

51-
Status BaseMetadataTable::Refresh() {
52-
return NotSupported("Cannot refresh a metadata table");
53-
}
51+
Status MetadataTable::Refresh() { return source_table_->Refresh(); }
5452

55-
Result<std::unique_ptr<TableScanBuilder>> BaseMetadataTable::NewScan() const {
53+
Result<std::unique_ptr<TableScanBuilder>> MetadataTable::NewScan() const {
5654
return NotSupported("TODO: Scanning metadata tables is not yet supported");
5755
};
5856

59-
Result<std::shared_ptr<Transaction>> BaseMetadataTable::NewTransaction() {
60-
return NotSupported("Cannot create a transaction for a metadata table");
61-
}
62-
63-
Result<std::shared_ptr<UpdateProperties>> BaseMetadataTable::NewUpdateProperties() {
64-
return NotSupported("Cannot create an update properties for a metadata table");
65-
}
66-
67-
Result<std::shared_ptr<UpdateSchema>> BaseMetadataTable::NewUpdateSchema() {
68-
return NotSupported("Cannot create an update schema for a metadata table");
69-
}
70-
71-
Result<std::shared_ptr<UpdateLocation>> BaseMetadataTable::NewUpdateLocation() {
72-
return NotSupported("Cannot create an update location for a metadata table");
73-
}
74-
75-
Result<std::shared_ptr<UpdatePartitionSpec>> BaseMetadataTable::NewUpdatePartitionSpec() {
76-
return NotSupported("Cannot create an update partition spec for a metadata table");
77-
}
78-
79-
Result<std::shared_ptr<UpdateSortOrder>> BaseMetadataTable::NewUpdateSortOrder() {
80-
return NotSupported("Cannot create an update sort order for a metadata table");
57+
Result<std::shared_ptr<SnapshotsTable>> MetadataTableFactory::GetSnapshotsTable(
58+
std::shared_ptr<Table> table) {
59+
return SnapshotsTable::Make(table);
8160
}
8261

83-
Result<std::shared_ptr<ExpireSnapshots>> BaseMetadataTable::NewExpireSnapshots() {
84-
return NotSupported("Cannot create an expire snapshots for a metadata table");
62+
Result<std::shared_ptr<HistoryTable>> MetadataTableFactory::GetHistoryTable(
63+
std::shared_ptr<Table> table) {
64+
return HistoryTable::Make(table);
8565
}
8666

8767
} // namespace iceberg

src/iceberg/inspect/metadata_table.h

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,26 @@
2929
#include "iceberg/table.h"
3030
#include "iceberg/table_metadata.h"
3131
#include "iceberg/table_scan.h"
32+
#include "iceberg/type_fwd.h"
3233

3334
namespace iceberg {
3435

35-
/// Forward declarations
36-
class FileIO;
36+
/// \brief The type of metadata table
37+
enum class MetadataTableType {
38+
kSnapshots,
39+
kHistory,
40+
};
3741

3842
/// \brief Base class for Iceberg metadata tables
3943
///
4044
/// Metadata tables expose table metadata as queryable tables with schemas and scan
4145
/// support. They provide read-only access to metadata.
42-
class ICEBERG_EXPORT BaseMetadataTable : public Table {
46+
class ICEBERG_EXPORT MetadataTable : public StaticTable {
4347
public:
4448
/// \brief Returns the identifier of this table
45-
const TableIdentifier& name() const { return identifier_; }
49+
const TableIdentifier& name() const override { return identifier_; }
50+
51+
virtual MetadataTableType type() const noexcept = 0;
4652

4753
/// \brief Returns the UUID of the table
4854
const std::string& uuid() const { return uuid_; }
@@ -137,32 +143,10 @@ class ICEBERG_EXPORT BaseMetadataTable : public Table {
137143
/// filter data.
138144
Result<std::unique_ptr<TableScanBuilder>> NewScan() const;
139145

140-
/// \brief Creating transactions is not supported in metadata tables.
141-
Result<std::shared_ptr<Transaction>> NewTransaction() override;
142-
143-
/// \brief Updating partition specs is not supported in metadata tables.
144-
Result<std::shared_ptr<UpdatePartitionSpec>> NewUpdatePartitionSpec() override;
145-
146-
/// \brief Updating table properties is not supported in metadata tables.
147-
Result<std::shared_ptr<UpdateProperties>> NewUpdateProperties() override;
148-
149-
/// \brief Updating sort orders is not supported in metadata tables.
150-
Result<std::shared_ptr<UpdateSortOrder>> NewUpdateSortOrder() override;
151-
152-
/// \brief Updating schemas is not supported in metadata tables.
153-
Result<std::shared_ptr<UpdateSchema>> NewUpdateSchema() override;
154-
155-
/// \brief Expiring snapshots is not supported in metadata tables.
156-
Result<std::shared_ptr<ExpireSnapshots>> NewExpireSnapshots() override;
157-
158-
/// \brief Updating table location is not supported in metadata tables.
159-
Result<std::shared_ptr<UpdateLocation>> NewUpdateLocation() override;
160-
161146
protected:
162-
BaseMetadataTable(std::shared_ptr<Table> source_table, TableIdentifier identifier,
163-
std::shared_ptr<Schema> schema);
147+
explicit MetadataTable(std::shared_ptr<Table> source_table, TableIdentifier identifier);
164148

165-
virtual ~BaseMetadataTable();
149+
~MetadataTable();
166150

167151
std::shared_ptr<Table> source_table_;
168152
std::string uuid_;
@@ -177,4 +161,31 @@ class ICEBERG_EXPORT BaseMetadataTable : public Table {
177161
{partition_spec->spec_id(), partition_spec}};
178162
};
179163

164+
/// \brief Metadata table factory and inspector
165+
///
166+
/// MetadataTable provides factory methods to create specific metadata tables for
167+
/// inspecting table metadata. Each metadata table exposes a different aspect of the
168+
/// table's metadata as a scannable Iceberg table.
169+
///
170+
/// Usage:
171+
/// auto snapshots = ICEBERG_TRY(MetadataTable::GetSnapshotsTable(table));
172+
/// auto scan = ICEBERG_TRY(snapshots->NewScan());
173+
/// // ... scan and read snapshot data
174+
class ICEBERG_EXPORT MetadataTableFactory {
175+
public:
176+
/// \brief Create a SnapshotsTable from a table
177+
///
178+
/// \param table The source table
179+
/// \return A SnapshotsTable exposing all snapshots or error status
180+
static Result<std::shared_ptr<SnapshotsTable>> GetSnapshotsTable(
181+
std::shared_ptr<Table> table);
182+
183+
/// \brief Create a HistoryTable from a table
184+
///
185+
/// \param table The source table
186+
/// \return A HistoryTable exposing snapshot history or error status
187+
static Result<std::shared_ptr<HistoryTable>> GetHistoryTable(
188+
std::shared_ptr<Table> table);
189+
};
190+
180191
} // namespace iceberg

src/iceberg/inspect/metadata_table_factory.cc

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/iceberg/inspect/metadata_table_factory.h

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/iceberg/inspect/snapshots_table.cc

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,25 @@
3131
namespace iceberg {
3232

3333
SnapshotsTable::SnapshotsTable(std::shared_ptr<Table> table)
34-
: BaseMetadataTable(table, CreateName(table->name()), CreateSchema()) {}
35-
36-
SnapshotsTable::~SnapshotsTable() = default;
37-
38-
std::shared_ptr<Schema> SnapshotsTable::CreateSchema() {
39-
return std::make_shared<Schema>(
40-
std::vector<SchemaField>{SchemaField::MakeRequired(1, "committed_at", int64()),
41-
SchemaField::MakeOptional(2, "snapshot_id", int64()),
42-
SchemaField::MakeRequired(3, "parent_id", int64()),
43-
SchemaField::MakeRequired(4, "manifest_list", string()),
44-
SchemaField::MakeRequired(
45-
5, "summary",
46-
std::make_shared<iceberg::MapType>(
47-
SchemaField::MakeRequired(6, "key", string()),
48-
SchemaField::MakeRequired(7, "value", string())))},
34+
: MetadataTable(table, CreateName(table->name())) {
35+
this->schema_ = std::make_shared<Schema>(
36+
std::vector<SchemaField>{
37+
SchemaField::MakeRequired(1, "committed_at", timestamp_tz()),
38+
SchemaField::MakeRequired(2, "snapshot_id", int64()),
39+
SchemaField::MakeRequired(3, "parent_id", int64()),
40+
SchemaField::MakeOptional(4, "operation", int64()),
41+
SchemaField::MakeOptional(5, "manifest_list", string()),
42+
SchemaField::MakeOptional(
43+
6, "summary",
44+
std::make_shared<iceberg::MapType>(
45+
SchemaField::MakeRequired(7, "key", string()),
46+
SchemaField::MakeRequired(8, "value", string())))},
4947
1);
48+
this->schemas_[schema_->schema_id()] = schema_;
5049
}
5150

51+
SnapshotsTable::~SnapshotsTable() = default;
52+
5253
TableIdentifier SnapshotsTable::CreateName(const TableIdentifier& source_name) {
5354
return TableIdentifier{source_name.ns, source_name.name + ".snapshots"};
5455
}

src/iceberg/inspect/snapshots_table.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace iceberg {
3636
/// - parent_id (long)
3737
/// - manifest_list (string)
3838
/// - summary (map<string, string>)
39-
class ICEBERG_EXPORT SnapshotsTable : public BaseMetadataTable {
39+
class ICEBERG_EXPORT SnapshotsTable : public MetadataTable {
4040
public:
4141
/// \brief Create a SnapshotsTable from table metadata
4242
///
@@ -46,8 +46,12 @@ class ICEBERG_EXPORT SnapshotsTable : public BaseMetadataTable {
4646

4747
~SnapshotsTable() override;
4848

49+
MetadataTableType type() const noexcept override {
50+
return MetadataTableType::kSnapshots;
51+
}
52+
4953
private:
50-
SnapshotsTable(std::shared_ptr<Table> table);
54+
explicit SnapshotsTable(std::shared_ptr<Table> table);
5155

5256
std::shared_ptr<Schema> CreateSchema();
5357

0 commit comments

Comments
 (0)