Skip to content

Commit 44b0d28

Browse files
committed
fix: some review suggestions
1 parent 296ee31 commit 44b0d28

File tree

5 files changed

+85
-82
lines changed

5 files changed

+85
-82
lines changed

src/iceberg/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ add_iceberg_lib(iceberg
6969

7070
iceberg_install_all_headers(iceberg)
7171

72+
add_subdirectory(catalog)
7273
add_subdirectory(expression)
7374
add_subdirectory(util)
7475

src/iceberg/catalog/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
iceberg_install_all_headers(iceberg/catalog)

src/iceberg/catalog/memory_catalog.cc

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,22 @@
2727

2828
namespace iceberg {
2929

30+
namespace {
31+
32+
NamespaceContainer* GetNamespaceContainer(NamespaceContainer* root,
33+
const Namespace& namespace_ident) {
34+
return NamespaceContainer::GetNamespaceContainerImpl(root, namespace_ident);
35+
}
36+
37+
const NamespaceContainer* GetNamespaceContainer(const NamespaceContainer* root,
38+
const Namespace& namespace_ident) {
39+
return NamespaceContainer::GetNamespaceContainerImpl(root, namespace_ident);
40+
}
41+
42+
} // namespace
43+
3044
MemoryCatalog::MemoryCatalog(std::shared_ptr<FileIO> file_io,
31-
std::optional<std::string> warehouse_location)
45+
std::string warehouse_location)
3246
: file_io_(std::move(file_io)),
3347
warehouse_location_(std::move(warehouse_location)),
3448
root_container_(std::make_unique<NamespaceContainer>()) {}
@@ -58,21 +72,24 @@ Result<std::unique_ptr<Table>> MemoryCatalog::CreateTable(
5872
const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
5973
const std::string& location,
6074
const std::unordered_map<std::string, std::string>& properties) {
61-
throw IcebergError("not implemented");
75+
return unexpected<Error>(
76+
{.kind = ErrorKind::kNotImplemented, .message = "CreateTable"});
6277
}
6378

6479
Result<std::unique_ptr<Table>> MemoryCatalog::UpdateTable(
6580
const TableIdentifier& identifier,
6681
const std::vector<std::unique_ptr<UpdateRequirement>>& requirements,
6782
const std::vector<std::unique_ptr<MetadataUpdate>>& updates) {
68-
throw IcebergError("not implemented");
83+
return unexpected<Error>(
84+
{.kind = ErrorKind::kNotImplemented, .message = "UpdateTable"});
6985
}
7086

7187
Result<std::shared_ptr<Transaction>> MemoryCatalog::StageCreateTable(
7288
const TableIdentifier& identifier, const Schema& schema, const PartitionSpec& spec,
7389
const std::string& location,
7490
const std::unordered_map<std::string, std::string>& properties) {
75-
throw IcebergError("not implemented");
91+
return unexpected<Error>(
92+
{.kind = ErrorKind::kNotImplemented, .message = "StageCreateTable"});
7693
}
7794

7895
bool MemoryCatalog::TableExists(const TableIdentifier& identifier) const {
@@ -88,7 +105,7 @@ bool MemoryCatalog::DropTable(const TableIdentifier& identifier, bool purge) {
88105

89106
Result<std::shared_ptr<Table>> MemoryCatalog::LoadTable(
90107
const TableIdentifier& identifier) const {
91-
throw IcebergError("not implemented");
108+
return unexpected<Error>({.kind = ErrorKind::kNotImplemented, .message = "LoadTable"});
92109
}
93110

94111
Result<std::shared_ptr<Table>> MemoryCatalog::RegisterTable(
@@ -110,17 +127,6 @@ std::unique_ptr<TableBuilder> MemoryCatalog::BuildTable(const TableIdentifier& i
110127
throw IcebergError("not implemented");
111128
}
112129

113-
/// Implementation of NamespaceContainer
114-
NamespaceContainer* NamespaceContainer::GetNamespaceContainer(
115-
NamespaceContainer* root, const Namespace& namespace_ident) {
116-
return GetNamespaceContainerImpl(root, namespace_ident);
117-
}
118-
119-
const NamespaceContainer* NamespaceContainer::GetNamespaceContainer(
120-
const NamespaceContainer* root, const Namespace& namespace_ident) {
121-
return GetNamespaceContainerImpl(root, namespace_ident);
122-
}
123-
124130
bool NamespaceContainer::NamespaceExists(const Namespace& namespace_ident) const {
125131
return GetNamespaceContainer(this, namespace_ident) != nullptr;
126132
}
@@ -157,7 +163,9 @@ bool NamespaceContainer::CreateNamespace(
157163
}
158164
}
159165

160-
if (!newly_created) return false;
166+
if (!newly_created) {
167+
return false;
168+
}
161169

162170
container->properties_ = properties;
163171
return true;

src/iceberg/catalog/memory_catalog.h

Lines changed: 40 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ class NamespaceContainer;
3131

3232
class ICEBERG_EXPORT MemoryCatalog : public Catalog {
3333
public:
34-
MemoryCatalog(std::shared_ptr<FileIO> file_io,
35-
std::optional<std::string> warehouse_location);
34+
MemoryCatalog(std::shared_ptr<FileIO> file_io, std::string warehouse_location);
3635

3736
void Initialize(
3837
const std::string& name,
@@ -75,13 +74,13 @@ class ICEBERG_EXPORT MemoryCatalog : public Catalog {
7574
std::string catalog_name_;
7675
std::unordered_map<std::string, std::string> properties_;
7776
std::shared_ptr<FileIO> file_io_;
78-
std::optional<std::string> warehouse_location_;
77+
std::string warehouse_location_;
7978
std::unique_ptr<NamespaceContainer> root_container_;
8079
mutable std::recursive_mutex mutex_;
8180
};
8281

8382
/**
84-
* @brief A hierarchical container that manages namespaces and table metadata in-memory.
83+
* \brief A hierarchical container that manages namespaces and table metadata in-memory.
8584
*
8685
* Each NamespaceContainer represents a namespace level and can contain properties,
8786
* tables, and child namespaces. This structure enables a tree-like representation
@@ -90,118 +89,94 @@ class ICEBERG_EXPORT MemoryCatalog : public Catalog {
9089
class ICEBERG_EXPORT NamespaceContainer {
9190
public:
9291
/**
93-
* @brief Checks whether the given namespace exists.
94-
* @param namespace_ident The namespace to check.
95-
* @return True if the namespace exists; false otherwise.
92+
* \brief Checks whether the given namespace exists.
93+
* \param[in] namespace_ident The namespace to check.
94+
* \return True if the namespace exists; false otherwise.
9695
*/
9796
bool NamespaceExists(const Namespace& namespace_ident) const;
9897

9998
/**
100-
* @brief Lists immediate child namespaces under the given parent namespace.
101-
* @param parent_namespace_ident The optional parent namespace. If not provided,
99+
* \brief Lists immediate child namespaces under the given parent namespace.
100+
* \param[in] parent_namespace_ident The optional parent namespace. If not provided,
102101
* the children of the root are returned.
103-
* @return A vector of child namespace names.
102+
* \return A vector of child namespace names.
104103
*/
105104
std::vector<std::string> ListChildrenNamespaces(
106105
const std::optional<Namespace>& parent_namespace_ident = std::nullopt) const;
107106

108107
/**
109-
* @brief Creates a new namespace with the specified properties.
110-
* @param namespace_ident The namespace to create.
111-
* @param properties A map of key-value pairs to associate with the namespace.
112-
* @return True if the namespace was successfully created; false if it already exists.
108+
* \brief Creates a new namespace with the specified properties.
109+
* \param[in] namespace_ident The namespace to create.
110+
* \param[in] properties A map of key-value pairs to associate with the namespace.
111+
* \return True if the namespace was successfully created; false if it already exists.
113112
*/
114113
bool CreateNamespace(const Namespace& namespace_ident,
115114
const std::unordered_map<std::string, std::string>& properties);
116115

117116
/**
118-
* @brief Deletes an existing namespace.
119-
* @param namespace_ident The namespace to delete.
120-
* @return True if the namespace was successfully deleted; false if it does not exist.
117+
* \brief Deletes an existing namespace.
118+
* \param[in] namespace_ident The namespace to delete.
119+
* \return True if the namespace was successfully deleted; false if it does not exist.
121120
*/
122121
bool DeleteNamespace(const Namespace& namespace_ident);
123122

124123
/**
125-
* @brief Retrieves the properties of the specified namespace.
126-
* @param namespace_ident The namespace whose properties to retrieve.
127-
* @return An optional containing the properties map if the namespace exists;
124+
* \brief Retrieves the properties of the specified namespace.
125+
* \param[in] namespace_ident The namespace whose properties to retrieve.
126+
* \return An optional containing the properties map if the namespace exists;
128127
* std::nullopt otherwise.
129128
*/
130129
std::optional<std::unordered_map<std::string, std::string>> GetProperties(
131130
const Namespace& namespace_ident) const;
132131

133132
/**
134-
* @brief Replaces all properties of the given namespace.
135-
* @param namespace_ident The namespace whose properties will be replaced.
136-
* @param properties The new properties map.
137-
* @return True if the namespace exists and properties were replaced; false otherwise.
133+
* \brief Replaces all properties of the given namespace.
134+
* \param[in] namespace_ident The namespace whose properties will be replaced.
135+
* \param[in] properties The new properties map.
136+
* \return True if the namespace exists and properties were replaced; false otherwise.
138137
*/
139138
bool ReplaceProperties(const Namespace& namespace_ident,
140139
const std::unordered_map<std::string, std::string>& properties);
141140

142141
/**
143-
* @brief Lists all table names under the specified namespace.
144-
* @param namespace_ident The namespace from which to list tables.
145-
* @return A vector of table names.
142+
* \brief Lists all table names under the specified namespace.
143+
* \param[in] namespace_ident The namespace from which to list tables.
144+
* \return A vector of table names.
146145
*/
147146
std::vector<std::string> ListTables(const Namespace& namespace_ident) const;
148147

149148
/**
150-
* @brief Registers a table in the given namespace with a metadata location.
151-
* @param table_ident The fully qualified identifier of the table.
152-
* @param metadata_location The path to the table's metadata.
153-
* @return True if the table was registered successfully; false otherwise.
149+
* \brief Registers a table in the given namespace with a metadata location.
150+
* \param[in] table_ident The fully qualified identifier of the table.
151+
* \param[in] metadata_location The path to the table's metadata.
152+
* \return True if the table was registered successfully; false otherwise.
154153
*/
155154
bool RegisterTable(TableIdentifier const& table_ident,
156155
const std::string& metadata_location);
157156

158157
/**
159-
* @brief Unregisters a table from the specified namespace.
160-
* @param table_ident The identifier of the table to unregister.
161-
* @return True if the table existed and was removed; false otherwise.
158+
* \brief Unregisters a table from the specified namespace.
159+
* \param[in] table_ident The identifier of the table to unregister.
160+
* \return True if the table existed and was removed; false otherwise.
162161
*/
163162
bool UnregisterTable(TableIdentifier const& table_ident);
164163

165164
/**
166-
* @brief Checks if a table exists in the specified namespace.
167-
* @param table_ident The identifier of the table to check.
168-
* @return True if the table exists; false otherwise.
165+
* \brief Checks if a table exists in the specified namespace.
166+
* \param[in] table_ident The identifier of the table to check.
167+
* \return True if the table exists; false otherwise.
169168
*/
170169
bool TableExists(TableIdentifier const& table_ident) const;
171170

172171
/**
173-
* @brief Gets the metadata location for the specified table.
174-
* @param table_ident The identifier of the table.
175-
* @return An optional string containing the metadata location if the table exists;
172+
* \brief Gets the metadata location for the specified table.
173+
* \param[in] table_ident The identifier of the table.
174+
* \return An optional string containing the metadata location if the table exists;
176175
* std::nullopt otherwise.
177176
*/
178177
std::optional<std::string> GetTableMetadataLocation(
179178
TableIdentifier const& table_ident) const;
180179

181-
private:
182-
/**
183-
* @brief Helper function to retrieve the container node for a given namespace.
184-
* @param root The root of the tree to search.
185-
* @param namespace_ident The namespace path to traverse.
186-
* @return A pointer to the corresponding NamespaceContainer if it exists; nullptr
187-
* otherwise.
188-
*/
189-
static NamespaceContainer* GetNamespaceContainer(NamespaceContainer* root,
190-
const Namespace& namespace_ident);
191-
192-
/**
193-
* @brief Const version of GetNamespaceContainer.
194-
*/
195-
static const NamespaceContainer* GetNamespaceContainer(
196-
const NamespaceContainer* root, const Namespace& namespace_ident);
197-
198-
/**
199-
* @brief Templated implementation for retrieving a NamespaceContainer node.
200-
* @tparam ContainerPtr Pointer type to NamespaceContainer (const or non-const).
201-
* @param root The root node.
202-
* @param namespace_ident The namespace path.
203-
* @return A pointer to the container node if found; nullptr otherwise.
204-
*/
205180
template <typename ContainerPtr>
206181
static ContainerPtr GetNamespaceContainerImpl(ContainerPtr root,
207182
const Namespace& namespace_ident) {
@@ -216,6 +191,7 @@ class ICEBERG_EXPORT NamespaceContainer {
216191
return node;
217192
}
218193

194+
private:
219195
/// Map of child namespace names to their corresponding container instances.
220196
std::unordered_map<std::string, NamespaceContainer> children_;
221197

test/memory_catalog_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class MemoryCatalogTest : public ::testing::Test {
131131
protected:
132132
void SetUp() override {
133133
file_io_ = nullptr; // TODO(Guotao): A real FileIO instance needs to be constructed.
134-
catalog_ = std::make_unique<MemoryCatalog>(file_io_, std::nullopt);
134+
catalog_ = std::make_unique<MemoryCatalog>(file_io_, "/tmp/warehouse/");
135135
catalog_->Initialize("test_catalog", {{"prop1", "val1"}});
136136
}
137137

0 commit comments

Comments
 (0)