2626#include < vector>
2727
2828#include " iceberg/iceberg_export.h"
29+ #include " iceberg/location_provider.h"
2930#include " iceberg/result.h"
31+ #include " iceberg/table_scan.h"
32+ #include " iceberg/transaction.h"
3033#include " iceberg/type_fwd.h"
3134
3235namespace iceberg {
@@ -45,21 +48,21 @@ class ICEBERG_EXPORT Table {
4548 // / \brief Refresh the current table metadata
4649 virtual Status Refresh () = 0;
4750
48- // / \brief Return the schema for this table
49- virtual const std::shared_ptr<Schema>& schema () const = 0;
51+ // / \brief Return the schema for this table, return NotFoundError if not found
52+ virtual Result< std::shared_ptr<Schema>> schema () const = 0;
5053
5154 // / \brief Return a map of schema for this table
5255 virtual const std::unordered_map<int32_t , std::shared_ptr<Schema>>& schemas () const = 0;
5356
54- // / \brief Return the partition spec for this table
55- virtual const std::shared_ptr<PartitionSpec>& spec () const = 0;
57+ // / \brief Return the partition spec for this table, return NotFoundError if not found
58+ virtual Result< std::shared_ptr<PartitionSpec>> spec () const = 0;
5659
5760 // / \brief Return a map of partition specs for this table
5861 virtual const std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>& specs ()
5962 const = 0;
6063
61- // / \brief Return the sort order for this table
62- virtual const std::shared_ptr<SortOrder>& sort_order () const = 0;
64+ // / \brief Return the sort order for this table, return NotFoundError if not found
65+ virtual Result< std::shared_ptr<SortOrder>> sort_order () const = 0;
6366
6467 // / \brief Return a map of sort order IDs to sort orders for this table
6568 virtual const std::unordered_map<int32_t , std::shared_ptr<SortOrder>>& sort_orders ()
@@ -71,8 +74,8 @@ class ICEBERG_EXPORT Table {
7174 // / \brief Return the table's base location
7275 virtual const std::string& location () const = 0;
7376
74- // / \brief Return the table's current snapshot
75- virtual const std::shared_ptr<Snapshot>& current_snapshot () const = 0;
77+ // / \brief Return the table's current snapshot, or NotFoundError if not found
78+ virtual Result< std::shared_ptr<Snapshot>> current_snapshot () const = 0;
7679
7780 // / \brief Get the snapshot of this table with the given id, or null if there is no
7881 // / matching snapshot
@@ -92,42 +95,51 @@ class ICEBERG_EXPORT Table {
9295 // / \brief Create a new table scan for this table
9396 // /
9497 // / Once a table scan is created, it can be refined to project columns and filter data.
95- virtual std::unique_ptr<TableScan> NewScan () const = 0;
98+ virtual Result< std::unique_ptr<TableScan> > NewScan () const = 0;
9699
97100 // / \brief Create a new append API to add files to this table and commit
98- virtual std::shared_ptr<AppendFiles> NewAppend () = 0;
101+ virtual Result< std::shared_ptr<AppendFiles> > NewAppend () = 0;
99102
100103 // / \brief Create a new transaction API to commit multiple table operations at once
101- virtual std::unique_ptr<Transaction> NewTransaction () = 0;
104+ virtual Result< std::unique_ptr<Transaction> > NewTransaction () = 0;
102105
103106 // / TODO(wgtmac): design of FileIO is not finalized yet. We intend to use an
104107 // / IO-less design in the core library.
105108 // /// \brief Returns a FileIO to read and write table data and metadata files
106109 // virtual std::shared_ptr<FileIO> io() const = 0;
107110
108111 // / \brief Returns a LocationProvider to provide locations for new data files
109- virtual std::unique_ptr<LocationProvider> location_provider () const = 0;
112+ virtual Result< std::unique_ptr<LocationProvider> > location_provider () const = 0;
110113};
111114
115+ // / \brief An abstract base implementation of the Iceberg Table interface.
116+ // /
117+ // / BaseTable provides common functionality for Iceberg table implementations,
118+ // / including lazy initialization of schema, partition specs, sort orders,
119+ // / and snapshot metadata.
120+ // /
121+ // / This class is not intended to be used directly by users, but serves as a foundation
122+ // / for concrete implementations such as StaticTable or CatalogTable.
112123class ICEBERG_EXPORT BaseTable : public Table {
113124 public:
114125 ~BaseTable () override = default ;
126+
115127 BaseTable (std::string name, std::shared_ptr<TableMetadata> metadata);
116128
117129 const std::string& name () const override { return name_; }
118130
119131 const std::string& uuid () const override ;
120132
121- const std::shared_ptr<Schema>& schema () const override ;
133+ Result< std::shared_ptr<Schema>> schema () const override ;
122134
123135 const std::unordered_map<int32_t , std::shared_ptr<Schema>>& schemas () const override ;
124136
125- const std::shared_ptr<PartitionSpec>& spec () const override ;
137+ Result< std::shared_ptr<PartitionSpec>> spec () const override ;
126138
127139 const std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>& specs ()
128140 const override ;
129141
130- const std::shared_ptr<SortOrder>& sort_order () const override ;
142+ Result< std::shared_ptr<SortOrder>> sort_order () const override ;
131143
132144 const std::unordered_map<int32_t , std::shared_ptr<SortOrder>>& sort_orders ()
133145 const override ;
@@ -136,7 +148,7 @@ class ICEBERG_EXPORT BaseTable : public Table {
136148
137149 const std::string& location () const override ;
138150
139- const std::shared_ptr<Snapshot>& current_snapshot () const override ;
151+ Result< std::shared_ptr<Snapshot>> current_snapshot () const override ;
140152
141153 Result<std::shared_ptr<Snapshot>> snapshot (int64_t snapshot_id) const override ;
142154
@@ -164,6 +176,8 @@ class ICEBERG_EXPORT BaseTable : public Table {
164176 mutable std::shared_ptr<Snapshot> current_snapshot_;
165177 mutable std::unordered_map<int64_t , std::shared_ptr<Snapshot>> snapshots_map_;
166178
179+ mutable std::vector<std::shared_ptr<HistoryEntry>> history_;
180+
167181 std::shared_ptr<TableMetadata> metadata_;
168182
169183 // once_flags
@@ -173,21 +187,25 @@ class ICEBERG_EXPORT BaseTable : public Table {
173187 mutable std::once_flag init_snapshot_once_;
174188};
175189
190+ // / \brief A read-only implementation of an Iceberg table.
191+ // /
192+ // / StaticTable represents a snapshot of a table that does not support mutation.
176193class ICEBERG_EXPORT StaticTable : public BaseTable {
177194 public:
178195 ~StaticTable () override = default ;
196+
179197 StaticTable (std::string name, std::shared_ptr<TableMetadata> metadata)
180198 : BaseTable(std::move(name), std::move(metadata)) {}
181199
182200 Status Refresh () override ;
183201
184- std::unique_ptr<TableScan> NewScan () const override ;
202+ Result< std::unique_ptr<TableScan> > NewScan () const override ;
185203
186- std::shared_ptr<AppendFiles> NewAppend () override ;
204+ Result< std::shared_ptr<AppendFiles> > NewAppend () override ;
187205
188- std::unique_ptr<Transaction> NewTransaction () override ;
206+ Result< std::unique_ptr<Transaction> > NewTransaction () override ;
189207
190- std::unique_ptr<LocationProvider> location_provider () const override ;
208+ Result< std::unique_ptr<LocationProvider> > location_provider () const override ;
191209};
192210
193211} // namespace iceberg
0 commit comments