1919
2020#pragma once
2121
22- #include < memory>
2322#include < string>
2423#include < unordered_map>
2524#include < vector>
2625
2726#include " iceberg/iceberg_export.h"
28- #include " iceberg/result.h"
27+ #include " iceberg/snapshot.h"
28+ #include " iceberg/table_identifier.h"
2929#include " iceberg/type_fwd.h"
3030
3131namespace iceberg {
@@ -35,77 +35,92 @@ class ICEBERG_EXPORT Table {
3535 public:
3636 virtual ~Table () = default ;
3737
38- // / \brief Return the full name for this table
39- virtual const std::string& name () const = 0;
38+ // / \brief Construct a table.
39+ // / \param[in] identifier The identifier of the table.
40+ // / \param[in] metadata The metadata for the table.
41+ // / \param[in] metadata_location The location of the table metadata file.
42+ // / \param[in] io The FileIO to read and write table data and metadata files.
43+ // / \param[in] catalog The catalog that this table belongs to. If null, the table will
44+ // / be read-only.
45+ Table (TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
46+ std::string metadata_location, std::shared_ptr<FileIO> io,
47+ std::shared_ptr<Catalog> catalog)
48+ : identifier_(std::move(identifier)),
49+ metadata_ (std::move(metadata)),
50+ metadata_location_(std::move(metadata_location)),
51+ io_(std::move(io)),
52+ catalog_(std::move(catalog)) {};
53+
54+ // / \brief Return the identifier of this table
55+ const TableIdentifier& name () const { return identifier_; }
4056
4157 // / \brief Returns the UUID of the table
42- virtual const std::string& uuid () const = 0 ;
58+ const std::string& uuid () const ;
4359
44- // / \brief Refresh the current table metadata
45- virtual Status Refresh () = 0;
46-
47- // / \brief Return the schema for this table
48- virtual const std::shared_ptr<Schema>& schema () const = 0;
60+ // / \brief Return the schema for this table, return NotFoundError if not found
61+ Result<std::shared_ptr<Schema>> schema () const ;
4962
5063 // / \brief Return a map of schema for this table
51- virtual const std::unordered_map<int32_t , std::shared_ptr<Schema>>& schemas () const = 0;
64+ // / \note This method is **not** thread-safe in the current implementation.
65+ const std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<Schema>>>& schemas ()
66+ const ;
5267
53- // / \brief Return the partition spec for this table
54- virtual const std::shared_ptr<PartitionSpec>& spec () const = 0 ;
68+ // / \brief Return the partition spec for this table, return NotFoundError if not found
69+ Result< std::shared_ptr<PartitionSpec>> spec () const ;
5570
5671 // / \brief Return a map of partition specs for this table
57- virtual const std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>& specs ()
58- const = 0;
72+ // / \note This method is **not** thread-safe in the current implementation.
73+ const std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>>&
74+ specs () const ;
5975
60- // / \brief Return the sort order for this table
61- virtual const std::shared_ptr<SortOrder>& sort_order () const = 0 ;
76+ // / \brief Return the sort order for this table, return NotFoundError if not found
77+ Result< std::shared_ptr<SortOrder>> sort_order () const ;
6278
6379 // / \brief Return a map of sort order IDs to sort orders for this table
64- virtual const std::unordered_map<int32_t , std::shared_ptr<SortOrder>>& sort_orders ()
65- const = 0;
80+ // / \note This method is **not** thread-safe in the current implementation.
81+ const std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<SortOrder>>>&
82+ sort_orders () const ;
6683
6784 // / \brief Return a map of string properties for this table
68- virtual const std::unordered_map<std::string, std::string>& properties () const = 0 ;
85+ const std::unordered_map<std::string, std::string>& properties () const ;
6986
7087 // / \brief Return the table's base location
71- virtual const std::string& location () const = 0 ;
88+ const std::string& location () const ;
7289
73- // / \brief Return the table's current snapshot
74- virtual const std::shared_ptr<Snapshot>& current_snapshot () const = 0 ;
90+ // / \brief Return the table's current snapshot, return NotFoundError if not found
91+ Result< std::shared_ptr<Snapshot>> current_snapshot () const ;
7592
76- // / \brief Get the snapshot of this table with the given id, or null if there is no
77- // / matching snapshot
93+ // / \brief Get the snapshot of this table with the given id
7894 // /
7995 // / \param snapshot_id the ID of the snapshot to get
80- // / \return the Snapshot with the given id
81- virtual Result<std::shared_ptr<Snapshot>> snapshot (int64_t snapshot_id) const = 0 ;
96+ // / \return the Snapshot with the given id, return NotFoundError if not found
97+ Result<std::shared_ptr<Snapshot>> SnapshotById (int64_t snapshot_id) const ;
8298
8399 // / \brief Get the snapshots of this table
84- virtual const std::vector<std::shared_ptr<Snapshot>>& snapshots () const = 0 ;
100+ const std::vector<std::shared_ptr<Snapshot>>& snapshots () const ;
85101
86102 // / \brief Get the snapshot history of this table
87103 // /
88104 // / \return a vector of history entries
89- virtual const std::vector<std::shared_ptr<HistoryEntry>>& history () const = 0;
90-
91- // / \brief Create a new table scan for this table
92- // /
93- // / Once a table scan is created, it can be refined to project columns and filter data.
94- virtual std::unique_ptr<TableScan> NewScan () const = 0;
95-
96- // / \brief Create a new append API to add files to this table and commit
97- virtual std::shared_ptr<AppendFiles> NewAppend () = 0;
98-
99- // / \brief Create a new transaction API to commit multiple table operations at once
100- virtual std::unique_ptr<Transaction> NewTransaction () = 0;
101-
102- // / TODO(wgtmac): design of FileIO is not finalized yet. We intend to use an
103- // / IO-less design in the core library.
104- // /// \brief Returns a FileIO to read and write table data and metadata files
105- // virtual std::shared_ptr<FileIO> io() const = 0;
106-
107- // / \brief Returns a LocationProvider to provide locations for new data files
108- virtual std::unique_ptr<LocationProvider> location_provider () const = 0;
105+ const std::vector<SnapshotLogEntry>& history () const ;
106+
107+ // / \brief Returns a FileIO to read and write table data and metadata files
108+ const std::shared_ptr<FileIO>& io () const ;
109+
110+ private:
111+ const TableIdentifier identifier_;
112+ std::shared_ptr<TableMetadata> metadata_;
113+ const std::string metadata_location_;
114+ std::shared_ptr<FileIO> io_;
115+ std::shared_ptr<Catalog> catalog_;
116+
117+ // Cache lazy-initialized maps.
118+ mutable std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<Schema>>>
119+ schemas_map_;
120+ mutable std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>>
121+ partition_spec_map_;
122+ mutable std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<SortOrder>>>
123+ sort_orders_map_;
109124};
110125
111126} // namespace iceberg
0 commit comments