Skip to content

Commit 9bb7ee9

Browse files
committed
fix: Merge the latest commits from the main branch
1 parent 832452b commit 9bb7ee9

File tree

3 files changed

+145
-146
lines changed

3 files changed

+145
-146
lines changed

src/iceberg/catalog/memory_catalog.cc

Lines changed: 72 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,37 @@ namespace iceberg {
2929

3030
namespace {
3131

32-
NamespaceContainer* GetNamespaceContainer(NamespaceContainer* root,
33-
const Namespace& namespace_ident) {
34-
return NamespaceContainer::GetNamespaceContainerImpl(root, namespace_ident);
32+
InMemoryNamespace* GetNamespace(InMemoryNamespace* root,
33+
const Namespace& namespace_ident) {
34+
return InMemoryNamespace::GetNamespaceImpl(root, namespace_ident);
3535
}
3636

37-
const NamespaceContainer* GetNamespaceContainer(const NamespaceContainer* root,
38-
const Namespace& namespace_ident) {
39-
return NamespaceContainer::GetNamespaceContainerImpl(root, namespace_ident);
37+
const InMemoryNamespace* GetNamespace(const InMemoryNamespace* root,
38+
const Namespace& namespace_ident) {
39+
return InMemoryNamespace::GetNamespaceImpl(root, namespace_ident);
4040
}
4141

4242
} // namespace
4343

44-
MemoryCatalog::MemoryCatalog(std::shared_ptr<FileIO> file_io,
45-
std::string warehouse_location)
44+
InMemoryCatalog::InMemoryCatalog(std::shared_ptr<FileIO> file_io,
45+
std::string warehouse_location)
4646
: file_io_(std::move(file_io)),
4747
warehouse_location_(std::move(warehouse_location)),
48-
root_container_(std::make_unique<NamespaceContainer>()) {}
48+
root_namespace_(std::make_unique<InMemoryNamespace>()) {}
4949

50-
void MemoryCatalog::Initialize(
50+
void InMemoryCatalog::Initialize(
5151
const std::string& name,
5252
const std::unordered_map<std::string, std::string>& properties) {
5353
catalog_name_ = name;
5454
properties_ = properties;
5555
}
5656

57-
std::string_view MemoryCatalog::name() const { return catalog_name_; }
57+
std::string_view InMemoryCatalog::name() const { return catalog_name_; }
5858

59-
Result<std::vector<TableIdentifier>> MemoryCatalog::ListTables(
59+
Result<std::vector<TableIdentifier>> InMemoryCatalog::ListTables(
6060
const Namespace& ns) const {
6161
std::unique_lock lock(mutex_);
62-
const auto& table_names = root_container_->ListTables(ns);
62+
const auto& table_names = root_namespace_->ListTables(ns);
6363
std::vector<TableIdentifier> table_idents;
6464
table_idents.reserve(table_names.size());
6565
std::ranges::transform(
@@ -68,117 +68,116 @@ Result<std::vector<TableIdentifier>> MemoryCatalog::ListTables(
6868
return table_idents;
6969
}
7070

71-
Result<std::unique_ptr<Table>> MemoryCatalog::CreateTable(
71+
Result<std::unique_ptr<Table>> InMemoryCatalog::CreateTable(
7272
const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
7373
const std::string& location,
7474
const std::unordered_map<std::string, std::string>& properties) {
7575
return unexpected<Error>(
7676
{.kind = ErrorKind::kNotImplemented, .message = "CreateTable"});
7777
}
7878

79-
Result<std::unique_ptr<Table>> MemoryCatalog::UpdateTable(
79+
Result<std::unique_ptr<Table>> InMemoryCatalog::UpdateTable(
8080
const TableIdentifier& identifier,
8181
const std::vector<std::unique_ptr<UpdateRequirement>>& requirements,
8282
const std::vector<std::unique_ptr<MetadataUpdate>>& updates) {
8383
return unexpected<Error>(
8484
{.kind = ErrorKind::kNotImplemented, .message = "UpdateTable"});
8585
}
8686

87-
Result<std::shared_ptr<Transaction>> MemoryCatalog::StageCreateTable(
87+
Result<std::shared_ptr<Transaction>> InMemoryCatalog::StageCreateTable(
8888
const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
8989
const std::string& location,
9090
const std::unordered_map<std::string, std::string>& properties) {
9191
return unexpected<Error>(
9292
{.kind = ErrorKind::kNotImplemented, .message = "StageCreateTable"});
9393
}
9494

95-
bool MemoryCatalog::TableExists(const TableIdentifier& identifier) const {
95+
bool InMemoryCatalog::TableExists(const TableIdentifier& identifier) const {
9696
std::unique_lock lock(mutex_);
97-
return root_container_->TableExists(identifier);
97+
return root_namespace_->TableExists(identifier);
9898
}
9999

100-
bool MemoryCatalog::DropTable(const TableIdentifier& identifier, bool purge) {
100+
bool InMemoryCatalog::DropTable(const TableIdentifier& identifier, bool purge) {
101101
std::unique_lock lock(mutex_);
102102
// TODO(Guotao): Delete all metadata files if purge is true.
103-
return root_container_->UnregisterTable(identifier);
103+
return root_namespace_->UnregisterTable(identifier);
104104
}
105105

106-
Result<std::shared_ptr<Table>> MemoryCatalog::LoadTable(
106+
Result<std::shared_ptr<Table>> InMemoryCatalog::LoadTable(
107107
const TableIdentifier& identifier) const {
108108
return unexpected<Error>({.kind = ErrorKind::kNotImplemented, .message = "LoadTable"});
109109
}
110110

111-
Result<std::shared_ptr<Table>> MemoryCatalog::RegisterTable(
111+
Result<std::shared_ptr<Table>> InMemoryCatalog::RegisterTable(
112112
const TableIdentifier& identifier, const std::string& metadata_file_location) {
113113
std::unique_lock lock(mutex_);
114-
if (!root_container_->NamespaceExists(identifier.ns)) {
114+
if (!root_namespace_->NamespaceExists(identifier.ns)) {
115115
return unexpected<Error>({.kind = ErrorKind::kNoSuchNamespace,
116116
.message = "table namespace does not exist"});
117117
}
118-
if (!root_container_->RegisterTable(identifier, metadata_file_location)) {
118+
if (!root_namespace_->RegisterTable(identifier, metadata_file_location)) {
119119
return unexpected<Error>(
120120
{.kind = ErrorKind::kUnknownError, .message = "The registry failed."});
121121
}
122122
return LoadTable(identifier);
123123
}
124124

125-
std::unique_ptr<TableBuilder> MemoryCatalog::BuildTable(const TableIdentifier& identifier,
126-
const Schema& schema) const {
125+
std::unique_ptr<TableBuilder> InMemoryCatalog::BuildTable(
126+
const TableIdentifier& identifier, const Schema& schema) const {
127127
throw IcebergError("not implemented");
128128
}
129129

130-
bool NamespaceContainer::NamespaceExists(const Namespace& namespace_ident) const {
131-
return GetNamespaceContainer(this, namespace_ident) != nullptr;
130+
bool InMemoryNamespace::NamespaceExists(const Namespace& namespace_ident) const {
131+
return GetNamespace(this, namespace_ident) != nullptr;
132132
}
133133

134-
std::vector<std::string> NamespaceContainer::ListChildrenNamespaces(
134+
std::vector<std::string> InMemoryNamespace::ListChildrenNamespaces(
135135
const std::optional<Namespace>& parent_namespace_ident) const {
136-
auto container = this;
136+
auto ns = this;
137137
if (parent_namespace_ident.has_value()) {
138-
container = GetNamespaceContainer(this, *parent_namespace_ident);
139-
if (!container) return {};
138+
ns = GetNamespace(this, *parent_namespace_ident);
139+
if (!ns) return {};
140140
}
141141

142142
std::vector<std::string> names;
143-
auto const& children = container->children_;
143+
auto const& children = ns->children_;
144144
names.reserve(children.size());
145145
std::ranges::transform(children, std::back_inserter(names),
146146
[](const auto& pair) { return pair.first; });
147147
return names;
148148
}
149149

150-
bool NamespaceContainer::CreateNamespace(
150+
bool InMemoryNamespace::CreateNamespace(
151151
const Namespace& namespace_ident,
152152
const std::unordered_map<std::string, std::string>& properties) {
153-
auto container = this;
153+
auto ns = this;
154154
bool newly_created = false;
155155

156156
for (const auto& part_level : namespace_ident.levels) {
157-
if (auto it = container->children_.find(part_level);
158-
it == container->children_.end()) {
159-
container = &container->children_[part_level];
157+
if (auto it = ns->children_.find(part_level); it == ns->children_.end()) {
158+
ns = &ns->children_[part_level];
160159
newly_created = true;
161160
} else {
162-
container = &it->second;
161+
ns = &it->second;
163162
}
164163
}
165164

166165
if (!newly_created) {
167166
return false;
168167
}
169168

170-
container->properties_ = properties;
169+
ns->properties_ = properties;
171170
return true;
172171
}
173172

174-
bool NamespaceContainer::DeleteNamespace(const Namespace& namespace_ident) {
173+
bool InMemoryNamespace::DeleteNamespace(const Namespace& namespace_ident) {
175174
if (namespace_ident.levels.empty()) return false;
176175

177176
auto parent_namespace_ident = namespace_ident;
178177
const auto to_delete = parent_namespace_ident.levels.back();
179178
parent_namespace_ident.levels.pop_back();
180179

181-
auto* parent = GetNamespaceContainer(this, parent_namespace_ident);
180+
auto* parent = GetNamespace(this, parent_namespace_ident);
182181
if (!parent) return false;
183182

184183
auto it = parent->children_.find(to_delete);
@@ -193,27 +192,27 @@ bool NamespaceContainer::DeleteNamespace(const Namespace& namespace_ident) {
193192
}
194193

195194
std::optional<std::unordered_map<std::string, std::string>>
196-
NamespaceContainer::GetProperties(const Namespace& namespace_ident) const {
197-
const auto container = GetNamespaceContainer(this, namespace_ident);
198-
if (!container) return std::nullopt;
199-
return container->properties_;
195+
InMemoryNamespace::GetProperties(const Namespace& namespace_ident) const {
196+
const auto ns = GetNamespace(this, namespace_ident);
197+
if (!ns) return std::nullopt;
198+
return ns->properties_;
200199
}
201200

202-
bool NamespaceContainer::ReplaceProperties(
201+
bool InMemoryNamespace::ReplaceProperties(
203202
const Namespace& namespace_ident,
204203
const std::unordered_map<std::string, std::string>& properties) {
205-
const auto container = GetNamespaceContainer(this, namespace_ident);
206-
if (!container) return false;
207-
container->properties_ = properties;
204+
const auto ns = GetNamespace(this, namespace_ident);
205+
if (!ns) return false;
206+
ns->properties_ = properties;
208207
return true;
209208
}
210209

211-
std::vector<std::string> NamespaceContainer::ListTables(
210+
std::vector<std::string> InMemoryNamespace::ListTables(
212211
const Namespace& namespace_ident) const {
213-
const auto container = GetNamespaceContainer(this, namespace_ident);
214-
if (!container) return {};
212+
const auto ns = GetNamespace(this, namespace_ident);
213+
if (!ns) return {};
215214

216-
const auto& locations = container->table_metadata_locations_;
215+
const auto& locations = ns->table_metadata_locations_;
217216
std::vector<std::string> table_names;
218217
table_names.reserve(locations.size());
219218

@@ -224,33 +223,33 @@ std::vector<std::string> NamespaceContainer::ListTables(
224223
return table_names;
225224
}
226225

227-
bool NamespaceContainer::RegisterTable(TableIdentifier const& table_ident,
228-
const std::string& metadata_location) {
229-
const auto container = GetNamespaceContainer(this, table_ident.ns);
230-
if (!container) return false;
231-
if (container->table_metadata_locations_.contains(table_ident.name)) return false;
232-
container->table_metadata_locations_[table_ident.name] = metadata_location;
226+
bool InMemoryNamespace::RegisterTable(TableIdentifier const& table_ident,
227+
const std::string& metadata_location) {
228+
const auto ns = GetNamespace(this, table_ident.ns);
229+
if (!ns) return false;
230+
if (ns->table_metadata_locations_.contains(table_ident.name)) return false;
231+
ns->table_metadata_locations_[table_ident.name] = metadata_location;
233232
return true;
234233
}
235234

236-
bool NamespaceContainer::UnregisterTable(TableIdentifier const& table_ident) {
237-
const auto container = GetNamespaceContainer(this, table_ident.ns);
238-
if (!container) return false;
239-
return container->table_metadata_locations_.erase(table_ident.name) > 0;
235+
bool InMemoryNamespace::UnregisterTable(TableIdentifier const& table_ident) {
236+
const auto ns = GetNamespace(this, table_ident.ns);
237+
if (!ns) return false;
238+
return ns->table_metadata_locations_.erase(table_ident.name) > 0;
240239
}
241240

242-
bool NamespaceContainer::TableExists(TableIdentifier const& table_ident) const {
243-
const auto container = GetNamespaceContainer(this, table_ident.ns);
244-
if (!container) return false;
245-
return container->table_metadata_locations_.contains(table_ident.name);
241+
bool InMemoryNamespace::TableExists(TableIdentifier const& table_ident) const {
242+
const auto ns = GetNamespace(this, table_ident.ns);
243+
if (!ns) return false;
244+
return ns->table_metadata_locations_.contains(table_ident.name);
246245
}
247246

248-
std::optional<std::string> NamespaceContainer::GetTableMetadataLocation(
247+
std::optional<std::string> InMemoryNamespace::GetTableMetadataLocation(
249248
TableIdentifier const& table_ident) const {
250-
const auto container = GetNamespaceContainer(this, table_ident.ns);
251-
if (!container) return std::nullopt;
252-
const auto it = container->table_metadata_locations_.find(table_ident.name);
253-
if (it == container->table_metadata_locations_.end()) return std::nullopt;
249+
const auto ns = GetNamespace(this, table_ident.ns);
250+
if (!ns) return std::nullopt;
251+
const auto it = ns->table_metadata_locations_.find(table_ident.name);
252+
if (it == ns->table_metadata_locations_.end()) return std::nullopt;
254253
return it->second;
255254
}
256255
} // namespace iceberg

src/iceberg/catalog/memory_catalog.h

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

2828
namespace iceberg {
2929

30-
class NamespaceContainer;
30+
class InMemoryNamespace;
3131

32-
class ICEBERG_EXPORT MemoryCatalog : public Catalog {
32+
class ICEBERG_EXPORT InMemoryCatalog : public Catalog {
3333
public:
34-
MemoryCatalog(std::shared_ptr<FileIO> file_io, std::string warehouse_location);
34+
InMemoryCatalog(std::shared_ptr<FileIO> file_io, std::string warehouse_location);
3535

3636
void Initialize(
3737
const std::string& name,
@@ -75,18 +75,18 @@ class ICEBERG_EXPORT MemoryCatalog : public Catalog {
7575
std::unordered_map<std::string, std::string> properties_;
7676
std::shared_ptr<FileIO> file_io_;
7777
std::string warehouse_location_;
78-
std::unique_ptr<NamespaceContainer> root_container_;
78+
std::unique_ptr<InMemoryNamespace> root_namespace_;
7979
mutable std::recursive_mutex mutex_;
8080
};
8181

8282
/**
83-
* \brief A hierarchical container that manages namespaces and table metadata in-memory.
83+
* \brief A hierarchical namespace that manages namespaces and table metadata in-memory.
8484
*
85-
* Each NamespaceContainer represents a namespace level and can contain properties,
85+
* Each InMemoryNamespace represents a namespace level and can contain properties,
8686
* tables, and child namespaces. This structure enables a tree-like representation
8787
* of nested namespaces.
8888
*/
89-
class ICEBERG_EXPORT NamespaceContainer {
89+
class ICEBERG_EXPORT InMemoryNamespace {
9090
public:
9191
/**
9292
* \brief Checks whether the given namespace exists.
@@ -177,9 +177,9 @@ class ICEBERG_EXPORT NamespaceContainer {
177177
std::optional<std::string> GetTableMetadataLocation(
178178
TableIdentifier const& table_ident) const;
179179

180-
template <typename ContainerPtr>
181-
static ContainerPtr GetNamespaceContainerImpl(ContainerPtr root,
182-
const Namespace& namespace_ident) {
180+
template <typename NamespacePtr>
181+
static NamespacePtr GetNamespaceImpl(NamespacePtr root,
182+
const Namespace& namespace_ident) {
183183
auto node = root;
184184
for (const auto& part_level : namespace_ident.levels) {
185185
auto it = node->children_.find(part_level);
@@ -192,8 +192,8 @@ class ICEBERG_EXPORT NamespaceContainer {
192192
}
193193

194194
private:
195-
/// Map of child namespace names to their corresponding container instances.
196-
std::unordered_map<std::string, NamespaceContainer> children_;
195+
/// Map of child namespace names to their corresponding namespace instances.
196+
std::unordered_map<std::string, InMemoryNamespace> children_;
197197

198198
/// Key-value property map for this namespace.
199199
std::unordered_map<std::string, std::string> properties_;

0 commit comments

Comments
 (0)