Skip to content

Commit e01f0fd

Browse files
author
shuxu.li
committed
feat: RegisterTable support for InMemoryCatalog
1 parent 0791f64 commit e01f0fd

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/iceberg/catalog.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ class ICEBERG_EXPORT Catalog {
166166
/// \param identifier a table identifier
167167
/// \return instance of Table implementation referred to by identifier or
168168
/// ErrorKind::kNoSuchTable if the table does not exist
169-
virtual Result<std::shared_ptr<Table>> LoadTable(
170-
const TableIdentifier& identifier) const = 0;
169+
virtual Result<std::shared_ptr<Table>> LoadTable(const TableIdentifier& identifier) = 0;
171170

172171
/// \brief Register a table with the catalog if it does not exist
173172
///

src/iceberg/catalog/in_memory_catalog.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -409,22 +409,24 @@ Status InMemoryCatalog::DropTable(const TableIdentifier& identifier, bool purge)
409409
}
410410

411411
Result<std::shared_ptr<Table>> InMemoryCatalog::LoadTable(
412-
const TableIdentifier& identifier) const {
412+
const TableIdentifier& identifier) {
413413
if (!file_io_) [[unlikely]] {
414414
return NotSupported("file_io is not set for catalog {}", catalog_name_);
415415
}
416416

417-
std::unique_lock lock(mutex_);
418-
auto metadata_location = root_namespace_->GetTableMetadataLocation(identifier);
419-
ICEBERG_RETURN_UNEXPECTED(metadata_location);
417+
Result<std::string> metadata_location;
418+
{
419+
std::unique_lock lock(mutex_);
420+
metadata_location = root_namespace_->GetTableMetadataLocation(identifier);
421+
ICEBERG_RETURN_UNEXPECTED(metadata_location);
422+
}
420423

421424
auto metadata = TableMetadataUtil::Read(*file_io_, metadata_location.value());
422425
ICEBERG_RETURN_UNEXPECTED(metadata);
423426

424-
return std::make_shared<Table>(
425-
identifier, std::move(metadata.value()), metadata_location.value(), file_io_,
426-
std::static_pointer_cast<Catalog>(
427-
std::const_pointer_cast<InMemoryCatalog>(shared_from_this())));
427+
return std::make_shared<Table>(identifier, std::move(metadata.value()),
428+
metadata_location.value(), file_io_,
429+
std::static_pointer_cast<Catalog>(shared_from_this()));
428430
}
429431

430432
Result<std::shared_ptr<Table>> InMemoryCatalog::RegisterTable(

src/iceberg/catalog/in_memory_catalog.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,7 @@ class ICEBERG_EXPORT InMemoryCatalog
8484

8585
Status DropTable(const TableIdentifier& identifier, bool purge) override;
8686

87-
Result<std::shared_ptr<Table>> LoadTable(
88-
const TableIdentifier& identifier) const override;
87+
Result<std::shared_ptr<Table>> LoadTable(const TableIdentifier& identifier) override;
8988

9089
Result<std::shared_ptr<Table>> RegisterTable(
9190
const TableIdentifier& identifier,

test/in_memory_catalog_test.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class InMemoryCatalogTest : public ::testing::Test {
5151
std::filesystem::remove_all(temp_filepath_, ec);
5252
}
5353

54+
// Used to generate a unique temporary metadata path for the test table
5455
std::string temp_filepath_;
5556
std::shared_ptr<FileIO> file_io_;
5657
std::shared_ptr<InMemoryCatalog> catalog_;

0 commit comments

Comments
 (0)