1717 * under the License.
1818 */
1919
20- #include " iceberg/catalog/memory_catalog .h"
20+ #include " iceberg/catalog/in_memory_catalog .h"
2121
2222#include < algorithm>
2323#include < iterator> // IWYU pragma: keep
@@ -42,19 +42,15 @@ Result<const InMemoryNamespace*> GetNamespace(const InMemoryNamespace* root,
4242
4343} // namespace
4444
45- InMemoryCatalog::InMemoryCatalog (std::shared_ptr<FileIO> file_io,
46- std::string warehouse_location)
47- : file_io_(std::move(file_io)),
45+ InMemoryCatalog::InMemoryCatalog (std::string name, std::shared_ptr<FileIO> file_io,
46+ std::string warehouse_location,
47+ std::unordered_map<std::string, std::string> properties)
48+ : catalog_name_(std::move(name)),
49+ properties_ (std::move(properties)),
50+ file_io_(std::move(file_io)),
4851 warehouse_location_(std::move(warehouse_location)),
4952 root_namespace_(std::make_unique<InMemoryNamespace>()) {}
5053
51- void InMemoryCatalog::Initialize (
52- const std::string& name,
53- const std::unordered_map<std::string, std::string>& properties) {
54- catalog_name_ = name;
55- properties_ = properties;
56- }
57-
5854std::string_view InMemoryCatalog::name () const { return catalog_name_; }
5955
6056Result<std::vector<TableIdentifier>> InMemoryCatalog::ListTables (
@@ -74,27 +70,24 @@ Result<std::unique_ptr<Table>> InMemoryCatalog::CreateTable(
7470 const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
7571 const std::string& location,
7672 const std::unordered_map<std::string, std::string>& properties) {
77- return unexpected<Error>(
78- {.kind = ErrorKind::kNotImplemented , .message = " CreateTable" });
73+ return NotImplemented (" create table" );
7974}
8075
8176Result<std::unique_ptr<Table>> InMemoryCatalog::UpdateTable (
8277 const TableIdentifier& identifier,
8378 const std::vector<std::unique_ptr<UpdateRequirement>>& requirements,
8479 const std::vector<std::unique_ptr<MetadataUpdate>>& updates) {
85- return unexpected<Error>(
86- {.kind = ErrorKind::kNotImplemented , .message = " UpdateTable" });
80+ return NotImplemented (" update table" );
8781}
8882
8983Result<std::shared_ptr<Transaction>> InMemoryCatalog::StageCreateTable (
9084 const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
9185 const std::string& location,
9286 const std::unordered_map<std::string, std::string>& properties) {
93- return unexpected<Error>(
94- {.kind = ErrorKind::kNotImplemented , .message = " StageCreateTable" });
87+ return NotImplemented (" stage create table" );
9588}
9689
97- Status InMemoryCatalog::TableExists (const TableIdentifier& identifier) const {
90+ Result< bool > InMemoryCatalog::TableExists (const TableIdentifier& identifier) const {
9891 std::unique_lock lock (mutex_);
9992 return root_namespace_->TableExists (identifier);
10093}
@@ -107,19 +100,17 @@ Status InMemoryCatalog::DropTable(const TableIdentifier& identifier, bool purge)
107100
108101Result<std::shared_ptr<Table>> InMemoryCatalog::LoadTable (
109102 const TableIdentifier& identifier) const {
110- return unexpected<Error>({. kind = ErrorKind:: kNotImplemented , . message = " LoadTable " } );
103+ return NotImplemented ( " load table " );
111104}
112105
113106Result<std::shared_ptr<Table>> InMemoryCatalog::RegisterTable (
114107 const TableIdentifier& identifier, const std::string& metadata_file_location) {
115108 std::unique_lock lock (mutex_);
116109 if (!root_namespace_->NamespaceExists (identifier.ns )) {
117- return unexpected<Error>({.kind = ErrorKind::kNoSuchNamespace ,
118- .message = " table namespace does not exist" });
110+ return NoSuchNamespace (" table namespace does not exist." );
119111 }
120112 if (!root_namespace_->RegisterTable (identifier, metadata_file_location)) {
121- return unexpected<Error>(
122- {.kind = ErrorKind::kUnknownError , .message = " The registry failed." });
113+ return UnknownError (" The registry failed." );
123114 }
124115 return LoadTable (identifier);
125116}
@@ -253,13 +244,10 @@ Status InMemoryNamespace::UnregisterTable(TableIdentifier const& table_ident) {
253244 return {};
254245}
255246
256- Status InMemoryNamespace::TableExists (TableIdentifier const & table_ident) const {
247+ Result< bool > InMemoryNamespace::TableExists (TableIdentifier const & table_ident) const {
257248 const auto ns = GetNamespace (this , table_ident.ns );
258249 ICEBERG_RETURN_UNEXPECTED (ns);
259- if (!ns.value ()->table_metadata_locations_ .contains (table_ident.name )) {
260- return NotFound (" {} does not exist" , table_ident.name );
261- }
262- return {};
250+ return ns.value ()->table_metadata_locations_ .contains (table_ident.name );
263251}
264252
265253Result<std::string> InMemoryNamespace::GetTableMetadataLocation (
0 commit comments