Skip to content

Commit 1831078

Browse files
committed
fix comments
1 parent a7a680f commit 1831078

File tree

4 files changed

+261
-30
lines changed

4 files changed

+261
-30
lines changed

src/iceberg/catalog.h

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <string>
2424
#include <string_view>
2525
#include <unordered_map>
26+
#include <unordered_set>
2627
#include <vector>
2728

2829
#include "iceberg/result.h"
@@ -42,6 +43,67 @@ class ICEBERG_EXPORT Catalog {
4243
/// \brief Return the name for this catalog
4344
virtual std::string_view name() const = 0;
4445

46+
/// \brief Create a namespace with associated properties.
47+
///
48+
/// \param ns the namespace to create
49+
/// \param properties a key-value map of metadata for the namespace
50+
/// \return Status::OK if created successfully;
51+
/// ErrorKind::kAlreadyExists if the namespace already exists;
52+
/// ErrorKind::kNotSupported if the operation is not supported
53+
virtual Status CreateNamespace(
54+
const Namespace& ns,
55+
const std::unordered_map<std::string, std::string>& properties) = 0;
56+
57+
/// \brief List child namespaces from the given namespace.
58+
///
59+
/// \param ns the parent namespace
60+
/// \return a list of child namespaces;
61+
/// ErrorKind::kNoSuchNamespace if the given namespace does not exist
62+
virtual Result<std::vector<Namespace>> ListNamespaces(const Namespace& ns) const = 0;
63+
64+
/// \brief Get metadata properties for a namespace.
65+
///
66+
/// \param ns the namespace to look up
67+
/// \return a key-value map of metadata properties;
68+
/// ErrorKind::kNoSuchNamespace if the namespace does not exist
69+
virtual Result<std::unordered_map<std::string, std::string>> GetNamespaceProperties(
70+
const Namespace& ns) const = 0;
71+
72+
/// \brief Drop a namespace.
73+
///
74+
/// \param ns the namespace to drop
75+
/// \return Status::OK if dropped successfully;
76+
/// ErrorKind::kNoSuchNamespace if the namespace does not exist;
77+
/// ErrorKind::kNotAllowed if the namespace is not empty
78+
virtual Status DropNamespace(const Namespace& ns) = 0;
79+
80+
/// \brief Check whether the namespace exists.
81+
///
82+
/// \param ns the namespace to check
83+
/// \return true if the namespace exists, false otherwise
84+
virtual Result<bool> NamespaceExists(const Namespace& ns) const = 0;
85+
86+
/// \brief Set metadata properties on a namespace.
87+
///
88+
/// \param ns the namespace to modify
89+
/// \param properties the properties to set or update
90+
/// \return Status::OK if updated successfully;
91+
/// ErrorKind::kNoSuchNamespace if the namespace does not exist;
92+
/// ErrorKind::kNotSupported if the operation is not supported
93+
virtual Status SetNamespaceProperties(
94+
const Namespace& ns,
95+
const std::unordered_map<std::string, std::string>& properties) = 0;
96+
97+
/// \brief Remove a set of metadata properties from a namespace.
98+
///
99+
/// \param ns the namespace to modify
100+
/// \param properties the set of property keys to remove
101+
/// \return Status::OK if removed successfully;
102+
/// ErrorKind::kNoSuchNamespace if the namespace does not exist;
103+
/// ErrorKind::kNotSupported if the operation is not supported
104+
virtual Status RemoveNamespaceProperties(
105+
const Namespace& ns, const std::unordered_set<std::string>& properties) = 0;
106+
45107
/// \brief Return all the identifiers under this namespace
46108
///
47109
/// \param ns a namespace
@@ -80,8 +142,8 @@ class ICEBERG_EXPORT Catalog {
80142
/// \param spec a partition spec
81143
/// \param location a location for the table; leave empty if unspecified
82144
/// \param properties a string map of table properties
83-
/// \return a Transaction to create the table or ErrorKind::kAlreadyExists if the table
84-
/// already exists
145+
/// \return a Transaction to create the table or ErrorKind::kAlreadyExists if the
146+
/// table already exists
85147
virtual Result<std::shared_ptr<Transaction>> StageCreateTable(
86148
const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
87149
const std::string& location,
@@ -91,8 +153,8 @@ class ICEBERG_EXPORT Catalog {
91153
///
92154
/// \param identifier a table identifier
93155
/// \return Result<bool> indicating table exists or not.
94-
/// - On success, the table existence was successfully checked (actual existence
95-
/// may be inferred elsewhere).
156+
/// - On success, the table existence was successfully checked (actual
157+
/// existence may be inferred elsewhere).
96158
/// - On failure, contains error information.
97159
virtual Result<bool> TableExists(const TableIdentifier& identifier) const = 0;
98160

src/iceberg/catalog/in_memory_catalog.cc

Lines changed: 140 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@ class ICEBERG_EXPORT InMemoryNamespace {
4747
* \param[in] namespace_ident The namespace to check.
4848
* \return Status indicating success or failure.
4949
*/
50-
Status NamespaceExists(const Namespace& namespace_ident) const;
50+
Result<bool> NamespaceExists(const Namespace& namespace_ident) const;
5151

5252
/**
5353
* \brief Lists immediate child namespaces under the given parent namespace.
54-
* \param[in] parent_namespace_ident The optional parent namespace. If not provided,
55-
* the children of the root are returned.
56-
* \return A vector of child namespace names.
54+
* \param[in] parent_namespace_ident The optional parent namespace.
55+
* \return A vector of child namespaces.
5756
*/
58-
Result<std::vector<std::string>> ListChildrenNamespaces(
59-
const std::optional<Namespace>& parent_namespace_ident = std::nullopt) const;
57+
Result<std::vector<Namespace>> ListNamespaces(
58+
const Namespace& parent_namespace_ident) const;
6059

6160
/**
6261
* \brief Creates a new namespace with the specified properties.
@@ -72,7 +71,7 @@ class ICEBERG_EXPORT InMemoryNamespace {
7271
* \param[in] namespace_ident The namespace to delete.
7372
* \return Status indicating success or failure.
7473
*/
75-
Status DeleteNamespace(const Namespace& namespace_ident);
74+
Status DropNamespace(const Namespace& namespace_ident);
7675

7776
/**
7877
* \brief Retrieves the properties of the specified namespace.
@@ -89,10 +88,20 @@ class ICEBERG_EXPORT InMemoryNamespace {
8988
* \param[in] properties The new properties map.
9089
* \return Status indicating success or failure.
9190
*/
92-
Status ReplaceProperties(
91+
Status SetNamespaceProperties(
9392
const Namespace& namespace_ident,
9493
const std::unordered_map<std::string, std::string>& properties);
9594

95+
/// \brief Remove a set of metadata properties from a namespace.
96+
///
97+
/// \param namespace_ident the namespace to modify
98+
/// \param properties the set of property keys to remove
99+
/// \return Status::OK if removed successfully;
100+
/// ErrorKind::kNoSuchNamespace if the namespace does not exist;
101+
/// ErrorKind::kNotSupported if the operation is not supported
102+
Status RemoveNamespaceProperties(const Namespace& namespace_ident,
103+
const std::unordered_set<std::string>& properties);
104+
96105
/**
97106
* \brief Lists all table names under the specified namespace.
98107
* \param[in] namespace_ident The namespace from which to list tables.
@@ -166,26 +175,31 @@ Result<const InMemoryNamespace*> GetNamespace(const InMemoryNamespace* root,
166175
return InMemoryNamespace::GetNamespaceImpl(root, namespace_ident);
167176
}
168177

169-
Status InMemoryNamespace::NamespaceExists(const Namespace& namespace_ident) const {
170-
const auto ns = GetNamespace(this, namespace_ident);
171-
ICEBERG_RETURN_UNEXPECTED(ns);
172-
return {};
178+
Result<bool> InMemoryNamespace::NamespaceExists(const Namespace& namespace_ident) const {
179+
const auto& ns = GetNamespace(this, namespace_ident);
180+
if (ns.has_value()) {
181+
return true;
182+
}
183+
if (ns.error().kind == ErrorKind::kNoSuchNamespace) {
184+
return false;
185+
}
186+
return unexpected<Error>(ns.error());
173187
}
174188

175-
Result<std::vector<std::string>> InMemoryNamespace::ListChildrenNamespaces(
176-
const std::optional<Namespace>& parent_namespace_ident) const {
177-
auto ns = this;
178-
if (parent_namespace_ident.has_value()) {
179-
const auto nsRs = GetNamespace(this, *parent_namespace_ident);
180-
ICEBERG_RETURN_UNEXPECTED(nsRs);
181-
ns = *nsRs;
182-
}
189+
Result<std::vector<Namespace>> InMemoryNamespace::ListNamespaces(
190+
const Namespace& parent_namespace_ident) const {
191+
const auto nsRs = GetNamespace(this, parent_namespace_ident);
192+
ICEBERG_RETURN_UNEXPECTED(nsRs);
193+
auto ns = *nsRs;
183194

184-
std::vector<std::string> names;
195+
std::vector<Namespace> names;
185196
auto const& children = ns->children_;
186197
names.reserve(children.size());
187-
std::ranges::transform(children, std::back_inserter(names),
188-
[](const auto& pair) { return pair.first; });
198+
std::ranges::transform(children, std::back_inserter(names), [&](const auto& pair) {
199+
auto childNs = parent_namespace_ident;
200+
childNs.levels.emplace_back(pair.first);
201+
return childNs;
202+
});
189203
return names;
190204
}
191205

@@ -214,7 +228,7 @@ Status InMemoryNamespace::CreateNamespace(
214228
return {};
215229
}
216230

217-
Status InMemoryNamespace::DeleteNamespace(const Namespace& namespace_ident) {
231+
Status InMemoryNamespace::DropNamespace(const Namespace& namespace_ident) {
218232
if (namespace_ident.levels.empty()) {
219233
return InvalidArgument("namespace identifier is empty");
220234
}
@@ -247,7 +261,7 @@ Result<std::unordered_map<std::string, std::string>> InMemoryNamespace::GetPrope
247261
return ns.value()->properties_;
248262
}
249263

250-
Status InMemoryNamespace::ReplaceProperties(
264+
Status InMemoryNamespace::SetNamespaceProperties(
251265
const Namespace& namespace_ident,
252266
const std::unordered_map<std::string, std::string>& properties) {
253267
const auto ns = GetNamespace(this, namespace_ident);
@@ -256,6 +270,15 @@ Status InMemoryNamespace::ReplaceProperties(
256270
return {};
257271
}
258272

273+
Status InMemoryNamespace::RemoveNamespaceProperties(
274+
const Namespace& namespace_ident, const std::unordered_set<std::string>& properties) {
275+
const auto ns = GetNamespace(this, namespace_ident);
276+
ICEBERG_RETURN_UNEXPECTED(ns);
277+
std::ranges::for_each(properties,
278+
[&](const auto& prop) { ns.value()->properties_.erase(prop); });
279+
return {};
280+
}
281+
259282
Result<std::vector<std::string>> InMemoryNamespace::ListTables(
260283
const Namespace& namespace_ident) const {
261284
const auto ns = GetNamespace(this, namespace_ident);
@@ -317,6 +340,25 @@ class ICEBERG_EXPORT InMemoryCatalogImpl {
317340

318341
std::string_view name() const;
319342

343+
Status CreateNamespace(const Namespace& ns,
344+
const std::unordered_map<std::string, std::string>& properties);
345+
346+
Result<std::vector<Namespace>> ListNamespaces(const Namespace& ns) const;
347+
348+
Status DropNamespace(const Namespace& ns);
349+
350+
Result<bool> NamespaceExists(const Namespace& ns) const;
351+
352+
Result<std::unordered_map<std::string, std::string>> GetNamespaceProperties(
353+
const Namespace& ns) const;
354+
355+
Status SetNamespaceProperties(
356+
const Namespace& ns,
357+
const std::unordered_map<std::string, std::string>& properties);
358+
359+
Status RemoveNamespaceProperties(const Namespace& ns,
360+
const std::unordered_set<std::string>& properties);
361+
320362
Result<std::vector<TableIdentifier>> ListTables(const Namespace& ns) const;
321363

322364
Result<std::unique_ptr<Table>> CreateTable(
@@ -366,6 +408,46 @@ InMemoryCatalogImpl::InMemoryCatalogImpl(
366408

367409
std::string_view InMemoryCatalogImpl::name() const { return catalog_name_; }
368410

411+
Status InMemoryCatalogImpl::CreateNamespace(
412+
const Namespace& ns, const std::unordered_map<std::string, std::string>& properties) {
413+
std::unique_lock lock(mutex_);
414+
return root_namespace_->CreateNamespace(ns, properties);
415+
}
416+
417+
Result<std::vector<Namespace>> InMemoryCatalogImpl::ListNamespaces(
418+
const Namespace& ns) const {
419+
std::unique_lock lock(mutex_);
420+
return root_namespace_->ListNamespaces(ns);
421+
}
422+
423+
Status InMemoryCatalogImpl::DropNamespace(const Namespace& ns) {
424+
std::unique_lock lock(mutex_);
425+
return root_namespace_->DropNamespace(ns);
426+
}
427+
428+
Result<bool> InMemoryCatalogImpl::NamespaceExists(const Namespace& ns) const {
429+
std::unique_lock lock(mutex_);
430+
return root_namespace_->NamespaceExists(ns);
431+
}
432+
433+
Result<std::unordered_map<std::string, std::string>>
434+
InMemoryCatalogImpl::GetNamespaceProperties(const Namespace& ns) const {
435+
std::unique_lock lock(mutex_);
436+
return root_namespace_->GetProperties(ns);
437+
}
438+
439+
Status InMemoryCatalogImpl::SetNamespaceProperties(
440+
const Namespace& ns, const std::unordered_map<std::string, std::string>& properties) {
441+
std::unique_lock lock(mutex_);
442+
return root_namespace_->SetNamespaceProperties(ns, properties);
443+
}
444+
445+
Status InMemoryCatalogImpl::RemoveNamespaceProperties(
446+
const Namespace& ns, const std::unordered_set<std::string>& properties) {
447+
std::unique_lock lock(mutex_);
448+
return root_namespace_->RemoveNamespaceProperties(ns, properties);
449+
}
450+
369451
Result<std::vector<TableIdentifier>> InMemoryCatalogImpl::ListTables(
370452
const Namespace& ns) const {
371453
std::unique_lock lock(mutex_);
@@ -444,6 +526,39 @@ InMemoryCatalog::~InMemoryCatalog() = default;
444526

445527
std::string_view InMemoryCatalog::name() const { return impl_->name(); }
446528

529+
Status InMemoryCatalog::CreateNamespace(
530+
const Namespace& ns, const std::unordered_map<std::string, std::string>& properties) {
531+
return impl_->CreateNamespace(ns, properties);
532+
}
533+
534+
Result<std::unordered_map<std::string, std::string>>
535+
InMemoryCatalog::GetNamespaceProperties(const Namespace& ns) const {
536+
return impl_->GetNamespaceProperties(ns);
537+
}
538+
539+
Result<std::vector<Namespace>> InMemoryCatalog::ListNamespaces(
540+
const Namespace& ns) const {
541+
return impl_->ListNamespaces(ns);
542+
}
543+
544+
Status InMemoryCatalog::DropNamespace(const Namespace& ns) {
545+
return impl_->DropNamespace(ns);
546+
}
547+
548+
Result<bool> InMemoryCatalog::NamespaceExists(const Namespace& ns) const {
549+
return impl_->NamespaceExists(ns);
550+
}
551+
552+
Status InMemoryCatalog::RemoveNamespaceProperties(
553+
const Namespace& ns, const std::unordered_set<std::string>& properties) {
554+
return impl_->RemoveNamespaceProperties(ns, properties);
555+
}
556+
557+
Status InMemoryCatalog::SetNamespaceProperties(
558+
const Namespace& ns, const std::unordered_map<std::string, std::string>& properties) {
559+
return impl_->SetNamespaceProperties(ns, properties);
560+
}
561+
447562
Result<std::vector<TableIdentifier>> InMemoryCatalog::ListTables(
448563
const Namespace& ns) const {
449564
return impl_->ListTables(ns);

src/iceberg/catalog/in_memory_catalog.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@
2222
#include "iceberg/catalog.h"
2323

2424
namespace iceberg {
25-
25+
/**
26+
* @brief An in-memory implementation of the Iceberg Catalog interface.
27+
*
28+
* This catalog stores all metadata purely in memory, with no persistence to disk
29+
* or external systems. It is primarily intended for unit tests, prototyping, or
30+
* demonstration purposes.
31+
*
32+
* @note This class is **not** suitable for production use.
33+
* All data will be lost when the process exits.
34+
*/
2635
class ICEBERG_EXPORT InMemoryCatalog : public Catalog {
2736
public:
2837
InMemoryCatalog(std::string const& name, std::shared_ptr<FileIO> const& file_io,
@@ -32,6 +41,26 @@ class ICEBERG_EXPORT InMemoryCatalog : public Catalog {
3241

3342
std::string_view name() const override;
3443

44+
Status CreateNamespace(
45+
const Namespace& ns,
46+
const std::unordered_map<std::string, std::string>& properties) override;
47+
48+
Result<std::vector<Namespace>> ListNamespaces(const Namespace& ns) const override;
49+
50+
Status DropNamespace(const Namespace& ns) override;
51+
52+
Result<bool> NamespaceExists(const Namespace& ns) const override;
53+
54+
Result<std::unordered_map<std::string, std::string>> GetNamespaceProperties(
55+
const Namespace& ns) const override;
56+
57+
Status SetNamespaceProperties(
58+
const Namespace& ns,
59+
const std::unordered_map<std::string, std::string>& properties) override;
60+
61+
Status RemoveNamespaceProperties(
62+
const Namespace& ns, const std::unordered_set<std::string>& properties) override;
63+
3564
Result<std::vector<TableIdentifier>> ListTables(const Namespace& ns) const override;
3665

3766
Result<std::unique_ptr<Table>> CreateTable(

0 commit comments

Comments
 (0)