2222#include < algorithm>
2323#include < iterator>
2424
25+ #include " iceberg/catalog/catalog_util.h"
2526#include " iceberg/file_io.h"
2627#include " iceberg/metrics/metrics_reporters.h"
2728#include " iceberg/table.h"
@@ -338,29 +339,30 @@ Status InMemoryNamespace::UpdateTableMetadataLocation(
338339 return {};
339340}
340341
341- std::shared_ptr<InMemoryCatalog> InMemoryCatalog::Make (
342+ Result< std::shared_ptr<InMemoryCatalog> > InMemoryCatalog::Make (
342343 const std::string& name, const std::shared_ptr<FileIO>& file_io,
343344 const std::string& warehouse_location,
344345 const std::unordered_map<std::string, std::string>& properties) {
345- return std::make_shared<InMemoryCatalog>(name, file_io, warehouse_location, properties);
346+ std::shared_ptr<MetricsReporter> reporter;
347+ auto it = properties.find (std::string (kMetricsReporterImpl ));
348+ if (it != properties.end () && !it->second .empty () &&
349+ it->second != kMetricsReporterTypeNoop ) {
350+ ICEBERG_ASSIGN_OR_RAISE (reporter, MetricsReporters::Load (properties));
351+ }
352+ return std::make_shared<InMemoryCatalog>(name, file_io, warehouse_location, properties,
353+ std::move (reporter));
346354}
347355
348- InMemoryCatalog::InMemoryCatalog (
349- const std::string& name, const std::shared_ptr<FileIO>& file_io ,
350- const std::string& warehouse_location ,
351- const std::unordered_map<std::string, std::string>& properties )
356+ InMemoryCatalog::InMemoryCatalog (std::string name, std::shared_ptr<FileIO> file_io,
357+ std::string warehouse_location ,
358+ std::unordered_map<std:: string, std::string> properties ,
359+ std::shared_ptr<MetricsReporter> reporter )
352360 : catalog_name_(std::move(name)),
353361 properties_ (std::move(properties)),
354362 file_io_(std::move(file_io)),
355363 warehouse_location_(std::move(warehouse_location)),
356- root_namespace_(std::make_unique<InMemoryNamespace>()) {
357- auto it = properties_.find (std::string (kMetricsReporterImpl ));
358- if (it != properties_.end () && !it->second .empty () &&
359- it->second != kMetricsReporterTypeNoop ) {
360- ICEBERG_ASSIGN_OR_THROW (auto reporter, MetricsReporters::Load (properties_));
361- reporter_ = std::shared_ptr<MetricsReporter>(std::move (reporter));
362- }
363- }
364+ root_namespace_(std::make_unique<InMemoryNamespace>()),
365+ reporter_(std::move(reporter)) {}
364366
365367InMemoryCatalog::~InMemoryCatalog () = default ;
366368
@@ -438,7 +440,7 @@ Result<std::shared_ptr<Table>> InMemoryCatalog::CreateTable(
438440 root_namespace_->UpdateTableMetadataLocation (identifier, metadata_file_location));
439441 return Table::Make (identifier, std::move (table_metadata),
440442 std::move (metadata_file_location), file_io_, shared_from_this (),
441- reporter_);
443+ CatalogUtil::FullTableName ( name (), identifier), reporter_);
442444}
443445
444446Result<std::shared_ptr<Table>> InMemoryCatalog::UpdateTable (
@@ -489,7 +491,8 @@ Result<std::shared_ptr<Table>> InMemoryCatalog::UpdateTable(
489491 TableMetadataUtil::DeleteRemovedMetadataFiles (*file_io_, base.get (), *updated);
490492
491493 return Table::Make (identifier, std::move (updated), std::move (new_metadata_location),
492- file_io_, shared_from_this (), reporter_);
494+ file_io_, shared_from_this (),
495+ CatalogUtil::FullTableName (name (), identifier), reporter_);
493496}
494497
495498Result<std::shared_ptr<Transaction>> InMemoryCatalog::StageCreateTable (
@@ -509,8 +512,10 @@ Result<std::shared_ptr<Transaction>> InMemoryCatalog::StageCreateTable(
509512 auto table_metadata,
510513 TableMetadata::Make (*schema, *spec, *order, base_location, properties));
511514 ICEBERG_ASSIGN_OR_RAISE (
512- auto table, StagedTable::Make (identifier, std::move (table_metadata), " " , file_io_,
513- shared_from_this (), reporter_));
515+ auto table,
516+ StagedTable::Make (identifier, std::move (table_metadata), " " , file_io_,
517+ shared_from_this (),
518+ CatalogUtil::FullTableName (name (), identifier), reporter_));
514519 return Transaction::Make (std::move (table), TransactionKind::kCreate );
515520}
516521
@@ -590,7 +595,8 @@ Result<std::shared_ptr<Table>> InMemoryCatalog::LoadTable(
590595 ICEBERG_ASSIGN_OR_RAISE (auto metadata,
591596 TableMetadataUtil::Read (*file_io_, metadata_location));
592597 return Table::Make (identifier, std::move (metadata), std::move (metadata_location),
593- file_io_, shared_from_this (), reporter_);
598+ file_io_, shared_from_this (),
599+ CatalogUtil::FullTableName (name (), identifier), reporter_);
594600}
595601
596602Result<std::shared_ptr<Table>> InMemoryCatalog::RegisterTable (
@@ -610,7 +616,8 @@ Result<std::shared_ptr<Table>> InMemoryCatalog::RegisterTable(
610616 return UnknownError (" The registry failed." );
611617 }
612618 return Table::Make (identifier, std::move (metadata), metadata_file_location, file_io_,
613- shared_from_this (), reporter_);
619+ shared_from_this (), CatalogUtil::FullTableName (name (), identifier),
620+ reporter_);
614621}
615622
616623} // namespace iceberg
0 commit comments