Skip to content

Commit 52e0c5b

Browse files
committed
rename memory catalog
1 parent c7b9533 commit 52e0c5b

File tree

6 files changed

+32
-59
lines changed

6 files changed

+32
-59
lines changed

src/iceberg/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set(ICEBERG_INCLUDES "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>"
1919
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>")
2020
set(ICEBERG_SOURCES
2121
arrow_c_data_internal.cc
22-
catalog/memory_catalog.cc
22+
catalog/in_memory_catalog.cc
2323
demo.cc
2424
expression/expression.cc
2525
file_reader.cc

src/iceberg/catalog.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ class ICEBERG_EXPORT Catalog {
9090
/// \brief Check whether table exists
9191
///
9292
/// \param identifier a table identifier
93-
/// \return Status indicating success or failure.
93+
/// \return Result<bool> indicating table exists or not.
9494
/// - On success, the table existence was successfully checked (actual existence
9595
/// may be inferred elsewhere).
9696
/// - On failure, contains error information.
97-
virtual Status TableExists(const TableIdentifier& identifier) const = 0;
97+
virtual Result<bool> TableExists(const TableIdentifier& identifier) const = 0;
9898

9999
/// \brief Drop a table; optionally delete data and metadata files
100100
///
@@ -124,18 +124,6 @@ class ICEBERG_EXPORT Catalog {
124124
virtual Result<std::shared_ptr<Table>> RegisterTable(
125125
const TableIdentifier& identifier, const std::string& metadata_file_location) = 0;
126126

127-
/// \brief Initialize a catalog given a custom name and a map of catalog properties
128-
///
129-
/// A custom Catalog implementation must have a default constructor. A compute engine
130-
/// will first initialize the catalog without any arguments, and then call this method
131-
/// to complete catalog initialization with properties passed into the engine.
132-
///
133-
/// \param name a custom name for the catalog
134-
/// \param properties catalog properties
135-
virtual void Initialize(
136-
const std::string& name,
137-
const std::unordered_map<std::string, std::string>& properties) = 0;
138-
139127
/// \brief Instantiate a builder to either create a table or start a create/replace
140128
/// transaction
141129
///

src/iceberg/catalog/memory_catalog.cc renamed to src/iceberg/catalog/in_memory_catalog.cc

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
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-
5854
std::string_view InMemoryCatalog::name() const { return catalog_name_; }
5955

6056
Result<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

8176
Result<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

8983
Result<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

108101
Result<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

113106
Result<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

265253
Result<std::string> InMemoryNamespace::GetTableMetadataLocation(

src/iceberg/catalog/memory_catalog.h renamed to src/iceberg/catalog/in_memory_catalog.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@
2727

2828
namespace iceberg {
2929

30-
class InMemoryNamespace;
31-
3230
class ICEBERG_EXPORT InMemoryCatalog : public Catalog {
3331
public:
34-
InMemoryCatalog(std::shared_ptr<FileIO> file_io, std::string warehouse_location);
35-
36-
void Initialize(
37-
const std::string& name,
38-
const std::unordered_map<std::string, std::string>& properties) override;
32+
InMemoryCatalog(std::string name, std::shared_ptr<FileIO> file_io,
33+
std::string warehouse_location,
34+
std::unordered_map<std::string, std::string> properties);
3935

4036
std::string_view name() const override;
4137

@@ -56,7 +52,7 @@ class ICEBERG_EXPORT InMemoryCatalog : public Catalog {
5652
const std::string& location,
5753
const std::unordered_map<std::string, std::string>& properties) override;
5854

59-
Status TableExists(const TableIdentifier& identifier) const override;
55+
Result<bool> TableExists(const TableIdentifier& identifier) const override;
6056

6157
Status DropTable(const TableIdentifier& identifier, bool purge) override;
6258

@@ -75,7 +71,7 @@ class ICEBERG_EXPORT InMemoryCatalog : public Catalog {
7571
std::unordered_map<std::string, std::string> properties_;
7672
std::shared_ptr<FileIO> file_io_;
7773
std::string warehouse_location_;
78-
std::unique_ptr<InMemoryNamespace> root_namespace_;
74+
std::unique_ptr<class InMemoryNamespace> root_namespace_;
7975
mutable std::recursive_mutex mutex_;
8076
};
8177

@@ -165,9 +161,9 @@ class ICEBERG_EXPORT InMemoryNamespace {
165161
/**
166162
* \brief Checks if a table exists in the specified namespace.
167163
* \param[in] table_ident The identifier of the table to check.
168-
* \return Status indicating success or failure.
164+
* \return Result<bool> indicating table exists or not.
169165
*/
170-
Status TableExists(TableIdentifier const& table_ident) const;
166+
Result<bool> TableExists(TableIdentifier const& table_ident) const;
171167

172168
/**
173169
* \brief Gets the metadata location for the specified table.

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ target_link_libraries(schema_test PRIVATE iceberg_static GTest::gtest_main GTest
4343
add_test(NAME schema_test COMMAND schema_test)
4444

4545
add_executable(catalog_test)
46-
target_sources(catalog_test PRIVATE memory_catalog_test.cc)
46+
target_sources(catalog_test PRIVATE in_memory_catalog_test.cc)
4747
target_link_libraries(catalog_test PRIVATE iceberg_static GTest::gtest_main GTest::gmock)
4848
add_test(NAME catalog_test COMMAND catalog_test)
4949

test/memory_catalog_test.cc renamed to test/in_memory_catalog_test.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
#include "iceberg/catalog/memory_catalog.h"
20+
#include "iceberg/catalog/in_memory_catalog.h"
2121

2222
#include <gmock/gmock.h>
2323
#include <gtest/gtest.h>
@@ -100,7 +100,7 @@ TEST_F(InMemoryNamespaceTest, UnregisterTable) {
100100
const auto t = MakeTable(ns.levels, "t2");
101101
EXPECT_TRUE(root_namespace_.RegisterTable(t, "meta2"));
102102
EXPECT_TRUE(root_namespace_.UnregisterTable(t));
103-
EXPECT_FALSE(root_namespace_.TableExists(t));
103+
EXPECT_FALSE(root_namespace_.TableExists(t).value());
104104
}
105105

106106
TEST_F(InMemoryNamespaceTest, RegisterTableOnNonExistingNamespaceFails) {
@@ -133,8 +133,9 @@ class MemoryCatalogTest : public ::testing::Test {
133133
protected:
134134
void SetUp() override {
135135
file_io_ = nullptr; // TODO(Guotao): A real FileIO instance needs to be constructed.
136-
catalog_ = std::make_unique<InMemoryCatalog>(file_io_, "/tmp/warehouse/");
137-
catalog_->Initialize("test_catalog", {{"prop1", "val1"}});
136+
std::unordered_map<std::string, std::string> properties = {{"prop1", "val1"}};
137+
catalog_ = std::make_unique<InMemoryCatalog>("test_catalog", file_io_,
138+
"/tmp/warehouse/", properties);
138139
}
139140

140141
std::shared_ptr<FileIO> file_io_;

0 commit comments

Comments
 (0)