Skip to content

Commit 52eb7d6

Browse files
committed
feat: first version of rest catalog
1 parent 01ff1b9 commit 52eb7d6

23 files changed

Lines changed: 1539 additions & 44 deletions

example/demo_example.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#include "iceberg/arrow/arrow_file_io.h"
2323
#include "iceberg/avro/avro_register.h"
24-
#include "iceberg/catalog/in_memory_catalog.h"
24+
#include "iceberg/catalog/memory/in_memory_catalog.h"
2525
#include "iceberg/parquet/parquet_register.h"
2626
#include "iceberg/table.h"
2727
#include "iceberg/table_scan.h"

src/iceberg/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
set(ICEBERG_INCLUDES "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/src>"
1919
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src>")
2020
set(ICEBERG_SOURCES
21-
catalog/in_memory_catalog.cc
21+
catalog/memory/in_memory_catalog.cc
2222
expression/expression.cc
2323
expression/literal.cc
2424
file_reader.cc

src/iceberg/catalog.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <unordered_set>
2727
#include <vector>
2828

29+
#include "iceberg/iceberg_export.h"
2930
#include "iceberg/result.h"
3031
#include "iceberg/table_identifier.h"
3132
#include "iceberg/type_fwd.h"
@@ -43,6 +44,13 @@ class ICEBERG_EXPORT Catalog {
4344
/// \brief Return the name for this catalog
4445
virtual std::string_view name() const = 0;
4546

47+
/// \brief List child namespaces from the given namespace.
48+
///
49+
/// \param ns the parent namespace
50+
/// \return a list of child namespaces;
51+
/// ErrorKind::kNoSuchNamespace if the given namespace does not exist
52+
virtual Result<std::vector<Namespace>> ListNamespaces(const Namespace& ns) const = 0;
53+
4654
/// \brief Create a namespace with associated properties.
4755
///
4856
/// \param ns the namespace to create
@@ -54,13 +62,6 @@ class ICEBERG_EXPORT Catalog {
5462
const Namespace& ns,
5563
const std::unordered_map<std::string, std::string>& properties) = 0;
5664

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-
6465
/// \brief Get metadata properties for a namespace.
6566
///
6667
/// \param ns the namespace to look up
@@ -69,6 +70,12 @@ class ICEBERG_EXPORT Catalog {
6970
virtual Result<std::unordered_map<std::string, std::string>> GetNamespaceProperties(
7071
const Namespace& ns) const = 0;
7172

73+
/// \brief Check whether the namespace exists.
74+
///
75+
/// \param ns the namespace to check
76+
/// \return true if the namespace exists, false otherwise
77+
virtual Result<bool> NamespaceExists(const Namespace& ns) const = 0;
78+
7279
/// \brief Drop a namespace.
7380
///
7481
/// \param ns the namespace to drop
@@ -77,12 +84,6 @@ class ICEBERG_EXPORT Catalog {
7784
/// ErrorKind::kNotAllowed if the namespace is not empty
7885
virtual Status DropNamespace(const Namespace& ns) = 0;
7986

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-
8687
/// \brief Update a namespace's properties by applying additions and removals.
8788
///
8889
/// \param ns the namespace to update

src/iceberg/catalog/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717

1818
iceberg_install_all_headers(iceberg/catalog)
19+
add_subdirectory(memory)
1920

2021
if(ICEBERG_BUILD_REST)
2122
add_subdirectory(rest)
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/memory)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

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

2222
#include <algorithm>
2323
#include <iterator> // IWYU pragma: keep
File renamed without changes.

src/iceberg/catalog/rest/CMakeLists.txt

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,28 @@ set(ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS)
2222
set(ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS)
2323
set(ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS)
2424

25-
list(APPEND ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS
26-
"$<IF:$<TARGET_EXISTS:iceberg_static>,iceberg_static,iceberg_shared>" cpr::cpr)
27-
list(APPEND ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS
28-
"$<IF:$<TARGET_EXISTS:iceberg_shared>,iceberg_shared,iceberg_static>" cpr::cpr)
25+
list(APPEND
26+
ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS
27+
"$<IF:$<TARGET_EXISTS:iceberg_static>,iceberg_static,iceberg_shared>"
28+
cpr::cpr
29+
nlohmann_json::nlohmann_json)
30+
list(APPEND
31+
ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS
32+
"$<IF:$<TARGET_EXISTS:iceberg_shared>,iceberg_shared,iceberg_static>"
33+
cpr::cpr
34+
nlohmann_json::nlohmann_json)
2935
list(APPEND
3036
ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS
3137
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_static>,Iceberg::iceberg_static,Iceberg::iceberg_shared>"
32-
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>")
38+
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>"
39+
"$<IF:$<BOOL:${NLOHMANN_JSON_VENDORED}>,Iceberg::nlohmann_json,nlohmann_json::nlohmann_json>"
40+
)
3341
list(APPEND
3442
ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS
3543
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_shared>,Iceberg::iceberg_shared,Iceberg::iceberg_static>"
36-
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>")
44+
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>"
45+
"$<IF:$<BOOL:${NLOHMANN_JSON_VENDORED}>,Iceberg::nlohmann_json,nlohmann_json::nlohmann_json>"
46+
)
3747

3848
add_iceberg_lib(iceberg_rest
3949
SOURCES

src/iceberg/catalog/rest/config.h

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
// namespace iceberg::rest {
21+
22+
// class ICEBERG_REST_EXPORT RestCatalogConfig {
23+
// public:
24+
// std::string uri;
25+
// std::optional<std::string> warehouse;
26+
// std::map<std::string, std::string> props;
27+
28+
// // Endpoint builder methods
29+
// std::string config_endpoint() const;
30+
// std::string namespaces_endpoint() const;
31+
// std::string namespace_endpoint(const Namespace& ns) const;
32+
// std::string tables_endpoint(const Namespace& ns) const;
33+
// std::string table_endpoint(const TableIdentifier& table) const;
34+
// std::string rename_table_endpoint() const;
35+
// };
36+
37+
// } // namespace iceberg::rest
38+
39+
#pragma once
40+
41+
#include <format>
42+
#include <map>
43+
#include <optional>
44+
#include <string>
45+
46+
#include "constant.h"
47+
#include "iceberg/catalog/rest/iceberg_rest_export.h"
48+
#include "iceberg/table_identifier.h"
49+
#include "iceberg/util/config.h"
50+
#include "util.h"
51+
52+
/// \file iceberg/catalog/rest/config.h
53+
/// RestCatalogConfig implementation for Iceberg REST API.
54+
55+
namespace iceberg::rest {
56+
57+
class ICEBERG_REST_EXPORT RestCatalogConfig : public ConfigBase<RestCatalogConfig> {
58+
public:
59+
const std::string& GetUri() const { return uri_; }
60+
61+
const std::optional<std::string>& GetWarehouse() const { return warehouse_; }
62+
63+
RestCatalogConfig& SetUri(std::string uri) {
64+
uri_ = std::move(uri);
65+
return *this;
66+
}
67+
68+
RestCatalogConfig& SetWarehouse(std::string warehouse) {
69+
warehouse_ = std::move(warehouse);
70+
return *this;
71+
}
72+
73+
std::string GetConfigEndpoint() const {
74+
return std::format("{}/{}/config", TrimTrailingSlash(uri_), kPathV1);
75+
}
76+
77+
/// \brief Get the namespaces endpoint
78+
std::string GetNamespacesEndpoint() const {
79+
return std::format("{}/{}/namespaces", TrimTrailingSlash(uri_), kPathV1);
80+
}
81+
82+
/// \brief Get the namespace endpoint
83+
std::string GetNamespaceEndpoint(const Namespace& ns) const {
84+
return std::format("{}/{}/namespaces/{}", TrimTrailingSlash(uri_), kPathV1,
85+
EncodeNamespaceForUrl(ns));
86+
}
87+
88+
/// \brief Get the tables endpoint
89+
std::string GetTablesEndpoint(const Namespace& ns) const {
90+
return std::format("{}/{}/namespaces/{}/tables", TrimTrailingSlash(uri_), kPathV1,
91+
EncodeNamespaceForUrl(ns));
92+
}
93+
94+
/// \brief Get the rename table endpoint
95+
std::string GetRenameTableEndpoint() const {
96+
return std::format("{}/{}/tables/rename", TrimTrailingSlash(uri_), kPathV1);
97+
}
98+
99+
/// \brief Get the table endpoint
100+
std::string GetTableEndpoint(const TableIdentifier& table) const {
101+
return std::format("{}/{}/namespaces/{}/tables/{}", TrimTrailingSlash(uri_), kPathV1,
102+
EncodeNamespaceForUrl(table.ns), table.name);
103+
}
104+
105+
private:
106+
std::string uri_;
107+
std::optional<std::string> warehouse_;
108+
};
109+
110+
} // namespace iceberg::rest
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
22+
#include <string_view>
23+
24+
#include "iceberg/version.h"
25+
26+
/// \file iceberg/catalog/rest/constant.h
27+
/// Constant values for Iceberg REST API.
28+
29+
namespace iceberg::rest {
30+
31+
constexpr std::string_view kHeaderContentType = "Content-Type";
32+
constexpr std::string_view kHeaderAccept = "Accept";
33+
constexpr std::string_view kHeaderXClientVersion = "X-Client-Version";
34+
constexpr std::string_view kHeaderUserAgent = "User-Agent";
35+
36+
constexpr std::string_view kMimeTypeApplicationJson = "application/json";
37+
constexpr std::string_view kClientVersion = "0.14.1";
38+
constexpr std::string_view kUserAgentPrefix = "iceberg-cpp/";
39+
constexpr std::string_view kUserAgent = "iceberg-cpp/" ICEBERG_VERSION_STRING;
40+
41+
constexpr std::string_view kPathV1 = "v1";
42+
43+
} // namespace iceberg::rest

0 commit comments

Comments
 (0)