@@ -58,59 +58,71 @@ Status Table::Refresh() {
5858 io_ = std::move (refreshed_table->io_ );
5959 properties_ = std::move (refreshed_table->properties_ );
6060
61- schemas_map_.reset ();
62- partition_spec_map_.reset ();
63- sort_orders_map_.reset ();
61+ // Reset lazy-initialized maps using move assignment
62+ schemas_map_ = Lazy<InitSchemasMap>{};
63+ partition_spec_map_ = Lazy<InitPartitionSpecsMap>{};
64+ sort_orders_map_ = Lazy<InitSortOrdersMap>{};
6465 }
6566 return {};
6667}
6768
6869Result<std::shared_ptr<Schema>> Table::schema () const { return metadata_->Schema (); }
6970
70- const std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<Schema>>>&
71- Table::schemas () const {
72- if (!schemas_map_) {
73- schemas_map_ =
74- std::make_shared<std::unordered_map<int32_t , std::shared_ptr<Schema>>>();
75- for (const auto & schema : metadata_->schemas ) {
76- if (schema->schema_id ()) {
77- schemas_map_->emplace (schema->schema_id ().value (), schema);
78- }
71+ Result<std::unordered_map<int32_t , std::shared_ptr<Schema>>> Table::InitSchemasMap (
72+ const Table& self) {
73+ std::unordered_map<int32_t , std::shared_ptr<Schema>> schemas_map;
74+ for (const auto & schema : self.metadata_ ->schemas ) {
75+ if (schema->schema_id ()) {
76+ schemas_map.emplace (schema->schema_id ().value (), schema);
7977 }
8078 }
81- return schemas_map_;
79+ return schemas_map;
80+ }
81+
82+ Result<std::reference_wrapper<const std::unordered_map<int32_t , std::shared_ptr<Schema>>>>
83+ Table::schemas () const {
84+ ICEBERG_ASSIGN_OR_RAISE (auto schemas_ref, schemas_map_.Get (*this ));
85+ return std::cref (schemas_ref.get ());
8286}
8387
8488Result<std::shared_ptr<PartitionSpec>> Table::spec () const {
8589 return metadata_->PartitionSpec ();
8690}
8791
88- const std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>>&
89- Table::specs () const {
90- if (!partition_spec_map_) {
91- partition_spec_map_ =
92- std::make_shared<std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>>();
93- for (const auto & spec : metadata_->partition_specs ) {
94- partition_spec_map_->emplace (spec->spec_id (), spec);
95- }
92+ Result<std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>>
93+ Table::InitPartitionSpecsMap (const Table& self) {
94+ std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>> partition_spec_map;
95+ for (const auto & spec : self.metadata_ ->partition_specs ) {
96+ partition_spec_map.emplace (spec->spec_id (), spec);
9697 }
97- return partition_spec_map_;
98+ return partition_spec_map;
99+ }
100+
101+ Result<std::reference_wrapper<
102+ const std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>>>
103+ Table::specs () const {
104+ ICEBERG_ASSIGN_OR_RAISE (auto specs_ref, partition_spec_map_.Get (*this ));
105+ return std::cref (specs_ref.get ());
98106}
99107
100108Result<std::shared_ptr<SortOrder>> Table::sort_order () const {
101109 return metadata_->SortOrder ();
102110}
103111
104- const std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<SortOrder>>>&
105- Table::sort_orders () const {
106- if (!sort_orders_map_) {
107- sort_orders_map_ =
108- std::make_shared<std::unordered_map<int32_t , std::shared_ptr<SortOrder>>>();
109- for (const auto & order : metadata_->sort_orders ) {
110- sort_orders_map_->emplace (order->order_id (), order);
111- }
112+ Result<std::unordered_map<int32_t , std::shared_ptr<SortOrder>>> Table::InitSortOrdersMap (
113+ const Table& self) {
114+ std::unordered_map<int32_t , std::shared_ptr<SortOrder>> sort_orders_map;
115+ for (const auto & order : self.metadata_ ->sort_orders ) {
116+ sort_orders_map.emplace (order->order_id (), order);
112117 }
113- return sort_orders_map_;
118+ return sort_orders_map;
119+ }
120+
121+ Result<
122+ std::reference_wrapper<const std::unordered_map<int32_t , std::shared_ptr<SortOrder>>>>
123+ Table::sort_orders () const {
124+ ICEBERG_ASSIGN_OR_RAISE (auto sort_orders_ref, sort_orders_map_.Get (*this ));
125+ return std::cref (sort_orders_ref.get ());
114126}
115127
116128const TableProperties& Table::properties () const { return *properties_; }
0 commit comments