Skip to content

Commit 5a95ca5

Browse files
HeartLinkedwgtmac
authored andcommitted
feat: add cpr and curl dependency for REST catalog
1 parent 3b945a0 commit 5a95ca5

9 files changed

Lines changed: 201 additions & 2 deletions

File tree

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
- name: Install dependencies
8686
shell: cmd
8787
run: |
88-
vcpkg install zlib:x64-windows nlohmann-json:x64-windows nanoarrow:x64-windows roaring:x64-windows
88+
vcpkg install zlib:x64-windows nlohmann-json:x64-windows nanoarrow:x64-windows roaring:x64-windows cpr:x64-windows
8989
- name: Build Iceberg
9090
shell: cmd
9191
run: |

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ option(ICEBERG_BUILD_STATIC "Build static library" ON)
3838
option(ICEBERG_BUILD_SHARED "Build shared library" OFF)
3939
option(ICEBERG_BUILD_TESTS "Build tests" ON)
4040
option(ICEBERG_BUILD_BUNDLE "Build the battery included library" ON)
41+
option(ICEBERG_BUILD_REST "Build rest catalog client" ON)
4142
option(ICEBERG_ENABLE_ASAN "Enable Address Sanitizer" OFF)
4243
option(ICEBERG_ENABLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF)
4344

cmake_modules/IcebergThirdpartyToolchain.cmake

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,58 @@ function(resolve_zlib_dependency)
430430

431431
endfunction()
432432

433+
# ----------------------------------------------------------------------
434+
# cpr (C++ Requests)
435+
436+
function(resolve_cpr_dependency)
437+
prepare_fetchcontent()
438+
439+
set(CPR_BUILD_TESTS OFF)
440+
set(CPR_BUILD_TESTS_SSL OFF)
441+
set(CPR_ENABLE_CURL_HTTP_ONLY ON)
442+
set(CPR_ENABLE_SSL ON)
443+
set(CPR_USE_SYSTEM_CURL OFF)
444+
445+
fetchcontent_declare(cpr
446+
${FC_DECLARE_COMMON_OPTIONS}
447+
URL https://github.com/libcpr/cpr/archive/refs/tags/1.12.0.tar.gz
448+
FIND_PACKAGE_ARGS
449+
NAMES
450+
cpr
451+
CONFIG)
452+
453+
fetchcontent_makeavailable(cpr)
454+
455+
if(cpr_SOURCE_DIR)
456+
if(NOT TARGET cpr::cpr)
457+
add_library(cpr::cpr INTERFACE IMPORTED)
458+
target_link_libraries(cpr::cpr INTERFACE cpr)
459+
target_include_directories(cpr::cpr INTERFACE ${cpr_BINARY_DIR}
460+
${cpr_SOURCE_DIR}/include)
461+
endif()
462+
463+
set(CPR_VENDORED TRUE)
464+
set_target_properties(cpr PROPERTIES OUTPUT_NAME "iceberg_vendored_cpr"
465+
POSITION_INDEPENDENT_CODE ON)
466+
add_library(Iceberg::cpr ALIAS cpr)
467+
install(TARGETS cpr
468+
EXPORT iceberg_targets
469+
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
470+
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
471+
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
472+
else()
473+
set(CPR_VENDORED FALSE)
474+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES cpr)
475+
endif()
476+
477+
set(ICEBERG_SYSTEM_DEPENDENCIES
478+
${ICEBERG_SYSTEM_DEPENDENCIES}
479+
PARENT_SCOPE)
480+
set(CPR_VENDORED
481+
${CPR_VENDORED}
482+
PARENT_SCOPE)
483+
endfunction()
484+
433485
# ----------------------------------------------------------------------
434486
# Zstd
435487

@@ -455,3 +507,7 @@ if(ICEBERG_BUILD_BUNDLE)
455507
resolve_avro_dependency()
456508
resolve_zstd_dependency()
457509
endif()
510+
511+
if(ICEBERG_BUILD_REST)
512+
resolve_cpr_dependency()
513+
endif()

example/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ find_package(Iceberg CONFIG REQUIRED)
2626

2727
add_executable(demo_example demo_example.cc)
2828

29-
target_link_libraries(demo_example PRIVATE Iceberg::iceberg_bundle_static)
29+
target_link_libraries(demo_example PRIVATE Iceberg::iceberg_bundle_static
30+
Iceberg::iceberg_rest_static)

src/iceberg/IcebergConfig.cmake.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ if(NOT TARGET roaring::roaring-headers-cpp)
7979
add_library(roaring::roaring-headers-cpp INTERFACE IMPORTED)
8080
endif()
8181

82+
if(NOT TARGET CURL::libcurl)
83+
add_library(CURL::libcurl INTERFACE IMPORTED)
84+
endif()
85+
8286
include("${CMAKE_CURRENT_LIST_DIR}/IcebergTargets.cmake")
8387

8488
if(TARGET Iceberg::arrow_static)

src/iceberg/catalog/CMakeLists.txt

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

1818
iceberg_install_all_headers(iceberg/catalog)
19+
20+
if(ICEBERG_BUILD_REST)
21+
add_subdirectory(rest)
22+
endif()
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
set(ICEBERG_REST_SOURCES rest_catalog.cc)
19+
20+
set(ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS)
21+
set(ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS)
22+
set(ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS)
23+
set(ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS)
24+
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)
29+
list(APPEND
30+
ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS
31+
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_static>,Iceberg::iceberg_static,Iceberg::iceberg_shared>"
32+
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>")
33+
list(APPEND
34+
ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS
35+
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_shared>,Iceberg::iceberg_shared,Iceberg::iceberg_static>"
36+
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>")
37+
38+
add_iceberg_lib(iceberg_rest
39+
SOURCES
40+
${ICEBERG_REST_SOURCES}
41+
SHARED_LINK_LIBS
42+
${ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS}
43+
STATIC_LINK_LIBS
44+
${ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS}
45+
STATIC_INSTALL_INTERFACE_LIBS
46+
${ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS}
47+
SHARED_INSTALL_INTERFACE_LIBS
48+
${ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS})
49+
50+
iceberg_install_all_headers(iceberg/catalog/rest)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
#include "iceberg/catalog/rest/rest_catalog.h"
21+
22+
#include <utility>
23+
24+
#include <cpr/cpr.h>
25+
26+
namespace iceberg::catalog::rest {
27+
28+
RestCatalog::RestCatalog(const std::string& base_url) : base_url_(std::move(base_url)) {}
29+
30+
cpr::Response RestCatalog::GetConfig() {
31+
cpr::Url url = cpr::Url{base_url_ + "/v1/config"};
32+
cpr::Response r = cpr::Get(url);
33+
return r;
34+
}
35+
36+
cpr::Response RestCatalog::ListNamespaces() {
37+
cpr::Url url = cpr::Url{base_url_ + "/v1/namespaces"};
38+
cpr::Response r = cpr::Get(url);
39+
return r;
40+
}
41+
42+
} // namespace iceberg::catalog::rest
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
#pragma once
19+
20+
#include <string>
21+
22+
#include <cpr/cpr.h>
23+
24+
#include "iceberg/catalog/rest/iceberg_rest_export.h"
25+
26+
namespace iceberg::catalog::rest {
27+
28+
class ICEBERG_REST_EXPORT RestCatalog {
29+
public:
30+
explicit RestCatalog(const std::string& base_url);
31+
~RestCatalog() = default;
32+
33+
cpr::Response GetConfig();
34+
35+
cpr::Response ListNamespaces();
36+
37+
private:
38+
std::string base_url_;
39+
};
40+
41+
} // namespace iceberg::catalog::rest

0 commit comments

Comments
 (0)