|
20 | 20 | #pragma once |
21 | 21 |
|
22 | 22 | #include <memory> |
23 | | -#include <string> |
24 | 23 |
|
25 | 24 | #include "iceberg/iceberg_export.h" |
26 | | -#include "iceberg/location_provider.h" |
27 | 25 | #include "iceberg/result.h" |
28 | | -#include "iceberg/sort_order.h" |
29 | | -#include "iceberg/table.h" |
30 | | -#include "iceberg/table_metadata.h" |
31 | | -#include "iceberg/table_scan.h" |
| 26 | +#include "iceberg/table_identifier.h" |
32 | 27 | #include "iceberg/type_fwd.h" |
33 | 28 |
|
34 | 29 | namespace iceberg { |
35 | 30 |
|
36 | | -/// \brief The type of metadata table |
37 | | -enum class MetadataTableType { |
38 | | - kSnapshots, |
39 | | - kHistory, |
40 | | -}; |
41 | | - |
42 | | -/// \brief Base class for Iceberg metadata tables |
43 | | -/// |
44 | | -/// Metadata tables expose table metadata as queryable tables with schemas and scan |
45 | | -/// support. They provide read-only access to metadata. |
46 | | -class ICEBERG_EXPORT MetadataTable : public StaticTable { |
| 31 | +/// \brief Base class for Iceberg metadata tables. |
| 32 | +class ICEBERG_EXPORT MetadataTable { |
47 | 33 | public: |
48 | | - virtual MetadataTableType type() const noexcept = 0; |
49 | | - |
50 | | - /// \brief Returns the table's metadata file location |
51 | | - std::string_view metadata_file_location() const { |
52 | | - return source_table_->metadata_file_location(); |
53 | | - } |
54 | | - |
55 | | - /// \brief Returns the table's base location |
56 | | - std::string_view location() const { return source_table_->location(); } |
57 | | - |
58 | | - /// \brief Returns the time when this table was last updated |
59 | | - TimePointMs last_updated_ms() const { return source_table_->last_updated_ms(); } |
60 | | - |
61 | | - /// \brief Returns the table's current snapshot, return NotFoundError if not found |
62 | | - Result<std::shared_ptr<Snapshot>> current_snapshot() const { |
63 | | - return source_table_->current_snapshot(); |
64 | | - } |
| 34 | + enum class Kind { |
| 35 | + kSnapshots, |
| 36 | + kHistory, |
| 37 | + }; |
65 | 38 |
|
66 | | - /// \brief Get the snapshot of this table with the given id |
67 | | - /// |
68 | | - /// \param snapshot_id the ID of the snapshot to get |
69 | | - /// \return the Snapshot with the given id, return NotFoundError if not found |
70 | | - Result<std::shared_ptr<Snapshot>> SnapshotById(int64_t snapshot_id) const { |
71 | | - return source_table_->SnapshotById(snapshot_id); |
72 | | - } |
| 39 | + static Result<std::unique_ptr<MetadataTable>> Make(std::shared_ptr<Table> table, |
| 40 | + Kind kind); |
73 | 41 |
|
74 | | - /// \brief Get the snapshots of this table |
75 | | - const std::vector<std::shared_ptr<Snapshot>>& snapshots() const { |
76 | | - return source_table_->snapshots(); |
77 | | - } |
| 42 | + virtual ~MetadataTable(); |
78 | 43 |
|
79 | | - /// \brief Get the snapshot history of this table |
80 | | - const std::vector<SnapshotLogEntry>& history() const { |
81 | | - return source_table_->history(); |
82 | | - } |
| 44 | + virtual Kind kind() const noexcept = 0; |
83 | 45 |
|
84 | | - /// \brief Returns the catalog that this table belongs to |
85 | | - const std::shared_ptr<Catalog>& catalog() const { return source_table_->catalog(); } |
| 46 | + const TableIdentifier& name() const { return identifier_; } |
86 | 47 |
|
87 | | - /// \brief Returns a LocationProvider for this table |
88 | | - Result<std::unique_ptr<LocationProvider>> location_provider() const { |
89 | | - return source_table_->location_provider(); |
90 | | - } |
| 48 | + const std::shared_ptr<Schema>& schema() const { return schema_; } |
91 | 49 |
|
92 | | - /// \brief Refreshing is not supported in metadata tables. |
93 | | - Status Refresh() override; |
94 | | - |
95 | | - /// \brief Create a new table scan builder for this table |
96 | | - /// |
97 | | - /// Once a table scan builder is created, it can be refined to project columns and |
98 | | - /// filter data. |
99 | | - Result<std::unique_ptr<DataTableScanBuilder>> NewScan() const override; |
100 | | - |
101 | | - ~MetadataTable(); |
| 50 | + const std::shared_ptr<Table>& source_table() const { return source_table_; } |
102 | 51 |
|
103 | 52 | protected: |
104 | | - explicit MetadataTable(std::shared_ptr<Table> source_table, TableIdentifier identifier); |
105 | | - |
106 | | - /// \brief Returns the schema for this metadata table |
107 | | - /// |
108 | | - /// Subclasses override this method to provide their custom schema during |
109 | | - /// MetadataTable construction. The returned schema is used to initialize |
110 | | - /// the underlying TableMetadata. |
111 | | - /// |
112 | | - /// \return The schema for this metadata table, or nullptr for default schema |
113 | | - virtual std::shared_ptr<Schema> GetSchema() const { return nullptr; } |
| 53 | + explicit MetadataTable(std::shared_ptr<Table> source_table, TableIdentifier identifier, |
| 54 | + std::shared_ptr<Schema> schema); |
114 | 55 |
|
| 56 | + private: |
| 57 | + TableIdentifier identifier_; |
| 58 | + std::shared_ptr<Schema> schema_; |
115 | 59 | std::shared_ptr<Table> source_table_; |
116 | 60 | }; |
117 | 61 |
|
118 | | -/// \brief Metadata table factory and inspector |
119 | | -/// |
120 | | -/// MetadataTable provides factory methods to create specific metadata tables for |
121 | | -/// inspecting table metadata. Each metadata table exposes a different aspect of the |
122 | | -/// table's metadata as a scannable Iceberg table. |
123 | | -/// |
124 | | -/// Usage: |
125 | | -/// auto metadata_table = ICEBERG_TRY( |
126 | | -/// MetadataTableFactory::CreateMetadataTable( |
127 | | -/// table, MetadataTableType::kSnapshots)); |
128 | | -/// auto scan = ICEBERG_TRY(metadata_table->NewScan()); |
129 | | -/// // ... scan and read metadata table data |
130 | | -class ICEBERG_EXPORT MetadataTableFactory { |
131 | | - public: |
132 | | - /// \brief Create a metadata table from a table |
133 | | - /// |
134 | | - /// \param table The source table |
135 | | - /// \param type The metadata table type to create |
136 | | - /// \return A MetadataTable instance or error status |
137 | | - static Result<std::unique_ptr<MetadataTable>> CreateMetadataTable( |
138 | | - std::shared_ptr<Table> table, MetadataTableType type); |
139 | | -}; |
140 | | - |
141 | 62 | } // namespace iceberg |
0 commit comments