2222#include < algorithm>
2323#include < iterator>
2424
25+ #include " iceberg/catalog/catalog_util.h"
2526#include " iceberg/file_io.h"
27+ #include " iceberg/metrics/metrics_reporters.h"
2628#include " iceberg/table.h"
2729#include " iceberg/table_identifier.h"
2830#include " iceberg/table_metadata.h"
@@ -337,22 +339,30 @@ Status InMemoryNamespace::UpdateTableMetadataLocation(
337339 return {};
338340}
339341
340- std::shared_ptr<InMemoryCatalog> InMemoryCatalog::Make (
342+ Result< std::shared_ptr<InMemoryCatalog> > InMemoryCatalog::Make (
341343 const std::string& name, const std::shared_ptr<FileIO>& file_io,
342344 const std::string& warehouse_location,
343345 const std::unordered_map<std::string, std::string>& properties) {
344- 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));
345354}
346355
347- InMemoryCatalog::InMemoryCatalog (
348- const std::string& name, const std::shared_ptr<FileIO>& file_io ,
349- const std::string& warehouse_location ,
350- 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 )
351360 : catalog_name_(std::move(name)),
352361 properties_ (std::move(properties)),
353362 file_io_(std::move(file_io)),
354363 warehouse_location_(std::move(warehouse_location)),
355- root_namespace_(std::make_unique<InMemoryNamespace>()) {}
364+ root_namespace_(std::make_unique<InMemoryNamespace>()),
365+ reporter_(std::move(reporter)) {}
356366
357367InMemoryCatalog::~InMemoryCatalog () = default ;
358368
@@ -429,7 +439,8 @@ Result<std::shared_ptr<Table>> InMemoryCatalog::CreateTable(
429439 ICEBERG_RETURN_UNEXPECTED (
430440 root_namespace_->UpdateTableMetadataLocation (identifier, metadata_file_location));
431441 return Table::Make (identifier, std::move (table_metadata),
432- std::move (metadata_file_location), file_io_, shared_from_this ());
442+ std::move (metadata_file_location), file_io_, shared_from_this (),
443+ CatalogUtil::FullTableName (name (), identifier), reporter_);
433444}
434445
435446Result<std::shared_ptr<Table>> InMemoryCatalog::UpdateTable (
@@ -480,7 +491,8 @@ Result<std::shared_ptr<Table>> InMemoryCatalog::UpdateTable(
480491 TableMetadataUtil::DeleteRemovedMetadataFiles (*file_io_, base.get (), *updated);
481492
482493 return Table::Make (identifier, std::move (updated), std::move (new_metadata_location),
483- file_io_, shared_from_this ());
494+ file_io_, shared_from_this (),
495+ CatalogUtil::FullTableName (name (), identifier), reporter_);
484496}
485497
486498Result<std::shared_ptr<Transaction>> InMemoryCatalog::StageCreateTable (
@@ -500,8 +512,10 @@ Result<std::shared_ptr<Transaction>> InMemoryCatalog::StageCreateTable(
500512 auto table_metadata,
501513 TableMetadata::Make (*schema, *spec, *order, base_location, properties));
502514 ICEBERG_ASSIGN_OR_RAISE (
503- auto table, StagedTable::Make (identifier, std::move (table_metadata), " " , file_io_,
504- shared_from_this ()));
515+ auto table,
516+ StagedTable::Make (identifier, std::move (table_metadata), " " , file_io_,
517+ shared_from_this (),
518+ CatalogUtil::FullTableName (name (), identifier), reporter_));
505519 return Transaction::Make (std::move (table), TransactionKind::kCreate );
506520}
507521
@@ -581,7 +595,8 @@ Result<std::shared_ptr<Table>> InMemoryCatalog::LoadTable(
581595 ICEBERG_ASSIGN_OR_RAISE (auto metadata,
582596 TableMetadataUtil::Read (*file_io_, metadata_location));
583597 return Table::Make (identifier, std::move (metadata), std::move (metadata_location),
584- file_io_, shared_from_this ());
598+ file_io_, shared_from_this (),
599+ CatalogUtil::FullTableName (name (), identifier), reporter_);
585600}
586601
587602Result<std::shared_ptr<Table>> InMemoryCatalog::RegisterTable (
@@ -601,7 +616,8 @@ Result<std::shared_ptr<Table>> InMemoryCatalog::RegisterTable(
601616 return UnknownError (" The registry failed." );
602617 }
603618 return Table::Make (identifier, std::move (metadata), metadata_file_location, file_io_,
604- shared_from_this ());
619+ shared_from_this (), CatalogUtil::FullTableName (name (), identifier),
620+ reporter_);
605621}
606622
607623} // namespace iceberg
0 commit comments