@@ -41,7 +41,8 @@ class ICEBERG_EXPORT Table {
4141 // / \param[in] metadata The metadata for the table.
4242 // / \param[in] metadata_location The location of the table metadata file.
4343 // / \param[in] io The FileIO to read and write table data and metadata files.
44- // / \param[in] catalog The catalog that this table belongs to.
44+ // / \param[in] catalog The catalog that this table belongs to. If null, the table will
45+ // / be read-only.
4546 Table (TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata,
4647 std::string metadata_location, std::shared_ptr<FileIO> io,
4748 std::shared_ptr<Catalog> catalog)
@@ -57,41 +58,41 @@ class ICEBERG_EXPORT Table {
5758 // / \brief Returns the UUID of the table
5859 const std::string& uuid () const ;
5960
60- // / \brief Return the schema for this table, return empty schema if not found
61- const std::shared_ptr<Schema>& schema () const ;
61+ // / \brief Return the schema for this table, return NotFoundError if not found
62+ Result< std::shared_ptr<Schema>> schema () const ;
6263
6364 // / \brief Return a map of schema for this table
64- const std::unordered_map<int32_t , std::shared_ptr<Schema>>& schemas () const ;
65+ const std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<Schema>>>& schemas ()
66+ const ;
6567
66- // / \brief Return the partition spec for this table, return null if default spec is not
67- // / found
68- const std::shared_ptr<PartitionSpec>& spec () const ;
68+ // / \brief Return the partition spec for this table, return NotFoundError if not found
69+ Result<std::shared_ptr<PartitionSpec>> spec () const ;
6970
7071 // / \brief Return a map of partition specs for this table
71- const std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>& specs () const ;
72+ const std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>>&
73+ specs () const ;
7274
73- // / \brief Return the sort order for this table, return null if default sort order is
74- // / not found
75- const std::shared_ptr<SortOrder>& sort_order () const ;
75+ // / \brief Return the sort order for this table, return NotFoundError if not found
76+ Result<std::shared_ptr<SortOrder>> sort_order () const ;
7677
7778 // / \brief Return a map of sort order IDs to sort orders for this table
78- const std::unordered_map<int32_t , std::shared_ptr<SortOrder>>& sort_orders () const ;
79+ const std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<SortOrder>>>&
80+ sort_orders () const ;
7981
8082 // / \brief Return a map of string properties for this table
8183 const std::unordered_map<std::string, std::string>& properties () const ;
8284
8385 // / \brief Return the table's base location
8486 const std::string& location () const ;
8587
86- // / \brief Return the table's current snapshot, return null if not found
87- std::shared_ptr<Snapshot> current_snapshot () const ;
88+ // / \brief Return the table's current snapshot, return NotFoundError if not found
89+ Result< std::shared_ptr<Snapshot> > current_snapshot () const ;
8890
89- // / \brief Get the snapshot of this table with the given id, or null if there is no
90- // / matching snapshot
91+ // / \brief Get the snapshot of this table with the given id
9192 // /
9293 // / \param snapshot_id the ID of the snapshot to get
93- // / \return the Snapshot with the given id
94- std::shared_ptr<Snapshot> SnapshotById (int64_t snapshot_id) const ;
94+ // / \return the Snapshot with the given id, return NotFoundError if not found
95+ Result< std::shared_ptr<Snapshot> > SnapshotById (int64_t snapshot_id) const ;
9596
9697 // / \brief Get the snapshots of this table
9798 const std::vector<std::shared_ptr<Snapshot>>& snapshots () const ;
@@ -101,31 +102,22 @@ class ICEBERG_EXPORT Table {
101102 // / \return a vector of history entries
102103 const std::vector<SnapshotLogEntry>& history () const ;
103104
105+ // / \brief Returns a FileIO to read and write table data and metadata files
106+ const std::shared_ptr<FileIO>& io () const ;
107+
104108 private:
105109 const TableIdentifier identifier_;
106110 const std::shared_ptr<TableMetadata> metadata_;
107111 const std::string metadata_location_;
108112 std::shared_ptr<FileIO> io_;
109113 std::shared_ptr<Catalog> catalog_;
110114
111- mutable std::shared_ptr<Schema> schema_;
112- mutable std::unordered_map<int32_t , std::shared_ptr<Schema>> schemas_map_;
113-
114- mutable std::shared_ptr<PartitionSpec> partition_spec_;
115- mutable std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>> partition_spec_map_;
116-
117- mutable std::shared_ptr<SortOrder> sort_order_;
118- mutable std::unordered_map<int32_t , std::shared_ptr<SortOrder>> sort_orders_map_;
119-
120- mutable std::shared_ptr<Snapshot> current_snapshot_;
121-
122- // once_flags
123- mutable std::once_flag init_schemas_once_;
124- mutable std::once_flag init_partition_spec_once_;
125- mutable std::once_flag init_partition_specs_once_;
126- mutable std::once_flag init_sort_order_once_;
127- mutable std::once_flag init_sort_orders_once_;
128- mutable std::once_flag init_snapshot_once_;
115+ mutable std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<Schema>>>
116+ schemas_map_;
117+ mutable std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>>
118+ partition_spec_map_;
119+ mutable std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<SortOrder>>>
120+ sort_orders_map_;
129121};
130122
131123} // namespace iceberg
0 commit comments