@@ -42,7 +42,8 @@ Table::Table(TableIdentifier identifier, std::shared_ptr<TableMetadata> metadata
4242 metadata_location_(std::move(metadata_location)),
4343 io_(std::move(io)),
4444 catalog_(std::move(catalog)),
45- properties_(TableProperties::FromMap(metadata_->properties)) {}
45+ properties_(TableProperties::FromMap(metadata_->properties)),
46+ metadata_cache_(std::make_unique<TableMetadataCache>(metadata_.get())) {}
4647
4748const std::string& Table::uuid () const { return metadata_->table_uuid ; }
4849
@@ -57,60 +58,36 @@ Status Table::Refresh() {
5758 metadata_location_ = std::move (refreshed_table->metadata_location_ );
5859 io_ = std::move (refreshed_table->io_ );
5960 properties_ = std::move (refreshed_table->properties_ );
60-
61- schemas_map_.reset ();
62- partition_spec_map_.reset ();
63- sort_orders_map_.reset ();
61+ metadata_cache_ = std::make_unique<TableMetadataCache>(metadata_.get ());
6462 }
6563 return {};
6664}
6765
6866Result<std::shared_ptr<Schema>> Table::schema () const { return metadata_->Schema (); }
6967
70- const std::shared_ptr< std::unordered_map<int32_t , std::shared_ptr<Schema>>>&
68+ Result< std::reference_wrapper< const std::unordered_map<int32_t , std::shared_ptr<Schema>>>>
7169Table::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- }
79- }
80- }
81- return schemas_map_;
70+ return metadata_cache_->GetSchemasById ();
8271}
8372
8473Result<std::shared_ptr<PartitionSpec>> Table::spec () const {
8574 return metadata_->PartitionSpec ();
8675}
8776
88- const std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>>&
77+ Result<std::reference_wrapper<
78+ const std::unordered_map<int32_t , std::shared_ptr<PartitionSpec>>>>
8979Table::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- }
96- }
97- return partition_spec_map_;
80+ return metadata_cache_->GetPartitionSpecsById ();
9881}
9982
10083Result<std::shared_ptr<SortOrder>> Table::sort_order () const {
10184 return metadata_->SortOrder ();
10285}
10386
104- const std::shared_ptr<std::unordered_map<int32_t , std::shared_ptr<SortOrder>>>&
87+ Result<
88+ std::reference_wrapper<const std::unordered_map<int32_t , std::shared_ptr<SortOrder>>>>
10589Table::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- }
113- return sort_orders_map_;
90+ return metadata_cache_->GetSortOrdersById ();
11491}
11592
11693const TableProperties& Table::properties () const { return *properties_; }
0 commit comments