Skip to content

Commit ff37b54

Browse files
committed
my first version
1 parent e69ff70 commit ff37b54

File tree

16 files changed

+1413
-39
lines changed

16 files changed

+1413
-39
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ project(Iceberg
2828
DESCRIPTION "Iceberg C++ Project"
2929
LANGUAGES CXX)
3030

31+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/src/iceberg/version.h.in"
32+
"${CMAKE_BINARY_DIR}/src/iceberg/version.h")
33+
3134
set(CMAKE_CXX_STANDARD 23)
3235
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3336
set(CMAKE_CXX_EXTENSIONS OFF)

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/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

src/iceberg/catalog/rest/error.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
#include <optional>
22+
#include <string>
23+
#include <vector>
24+
25+
#include <nlohmann/json.hpp>
26+
27+
#include "iceberg/result.h"
28+
29+
namespace iceberg::rest {
30+
31+
struct ApiErrorModel {
32+
std::string message;
33+
std::string type;
34+
uint16_t code;
35+
std::optional<std::vector<std::string>> stack;
36+
37+
// 转换到项目统一的 Error 类型
38+
operator Error() const;
39+
};
40+
41+
// 嵌套的 ErrorResponse 结构
42+
struct ApiErrorResponse {
43+
ApiErrorModel error;
44+
operator Error() const { return error; }
45+
};
46+
47+
void from_json(const nlohmann::json& j, ApiErrorModel& e);
48+
void from_json(const nlohmann::json& j, ApiErrorResponse& e);
49+
50+
} // namespace iceberg::rest

0 commit comments

Comments
 (0)