Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/cpp-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
- name: Install dependencies
shell: bash
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev
- name: Run build
run: |
mkdir build && cd build
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/sanitizer_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ jobs:
steps:
- name: Checkout iceberg-cpp
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- name: Install dependencies
shell: bash
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev
- name: Configure and Build with ASAN & UBSAN
run: |
mkdir build && cd build
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
- name: Install dependencies
shell: bash
run: sudo apt-get update && sudo apt-get install -y libcurl4-openssl-dev
- name: Build Iceberg
shell: bash
run: ci/scripts/build_iceberg.sh $(pwd)
Expand Down Expand Up @@ -85,7 +88,7 @@ jobs:
- name: Install dependencies
shell: cmd
run: |
vcpkg install zlib:x64-windows nlohmann-json:x64-windows nanoarrow:x64-windows roaring:x64-windows
vcpkg install zlib:x64-windows nlohmann-json:x64-windows nanoarrow:x64-windows roaring:x64-windows cpr:x64-windows
- name: Build Iceberg
shell: cmd
run: |
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ option(ICEBERG_BUILD_STATIC "Build static library" ON)
option(ICEBERG_BUILD_SHARED "Build shared library" OFF)
option(ICEBERG_BUILD_TESTS "Build tests" ON)
option(ICEBERG_BUILD_BUNDLE "Build the battery included library" ON)
option(ICEBERG_BUILD_REST "Build rest catalog client" ON)
option(ICEBERG_ENABLE_ASAN "Enable Address Sanitizer" OFF)
option(ICEBERG_ENABLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF)

Expand Down
56 changes: 56 additions & 0 deletions cmake_modules/IcebergThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,58 @@ function(resolve_zlib_dependency)

endfunction()

# ----------------------------------------------------------------------
# cpr (C++ Requests)

function(resolve_cpr_dependency)
prepare_fetchcontent()

set(CPR_BUILD_TESTS OFF)
set(CPR_ENABLE_CURL_HTTP_ONLY ON)
set(CPR_ENABLE_SSL ON)
set(CPR_USE_SYSTEM_CURL ON)

fetchcontent_declare(cpr
${FC_DECLARE_COMMON_OPTIONS}
URL https://github.com/libcpr/cpr/archive/refs/tags/1.12.0.tar.gz
FIND_PACKAGE_ARGS
NAMES
cpr
CONFIG)

fetchcontent_makeavailable(cpr)

if(cpr_SOURCE_DIR)
if(NOT TARGET cpr::cpr)
add_library(cpr::cpr INTERFACE IMPORTED)
target_link_libraries(cpr::cpr INTERFACE cpr)
target_include_directories(cpr::cpr INTERFACE ${cpr_BINARY_DIR}
${cpr_SOURCE_DIR}/include)
endif()

set(CPR_VENDORED TRUE)
set_target_properties(cpr PROPERTIES OUTPUT_NAME "iceberg_vendored_cpr"
POSITION_INDEPENDENT_CODE ON)
add_library(Iceberg::cpr ALIAS cpr)
install(TARGETS cpr
EXPORT iceberg_targets
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES OpenSSL)
else()
set(CPR_VENDORED FALSE)
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES cpr)
endif()

set(ICEBERG_SYSTEM_DEPENDENCIES
${ICEBERG_SYSTEM_DEPENDENCIES}
PARENT_SCOPE)
set(CPR_VENDORED
${CPR_VENDORED}
PARENT_SCOPE)
endfunction()

# ----------------------------------------------------------------------
# Zstd

Expand All @@ -455,3 +507,7 @@ if(ICEBERG_BUILD_BUNDLE)
resolve_avro_dependency()
resolve_zstd_dependency()
endif()

if(ICEBERG_BUILD_REST)
resolve_cpr_dependency()
endif()
3 changes: 2 additions & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ find_package(Iceberg CONFIG REQUIRED)

add_executable(demo_example demo_example.cc)

target_link_libraries(demo_example PRIVATE Iceberg::iceberg_bundle_static)
target_link_libraries(demo_example PRIVATE Iceberg::iceberg_bundle_static
Iceberg::iceberg_rest_static)
6 changes: 6 additions & 0 deletions src/iceberg/IcebergConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
# Iceberg::iceberg_static
# Iceberg::iceberg_bundle_shared
# Iceberg::iceberg_bundle_static
# Iceberg::iceberg_rest_shared
# Iceberg::iceberg_rest_static

@PACKAGE_INIT@

Expand Down Expand Up @@ -79,6 +81,10 @@ if(NOT TARGET roaring::roaring-headers-cpp)
add_library(roaring::roaring-headers-cpp INTERFACE IMPORTED)
endif()

if(NOT TARGET CURL::libcurl)
add_library(CURL::libcurl INTERFACE IMPORTED)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/IcebergTargets.cmake")

if(TARGET Iceberg::arrow_static)
Expand Down
4 changes: 4 additions & 0 deletions src/iceberg/catalog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@
# under the License.

iceberg_install_all_headers(iceberg/catalog)

if(ICEBERG_BUILD_REST)
add_subdirectory(rest)
endif()
50 changes: 50 additions & 0 deletions src/iceberg/catalog/rest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

set(ICEBERG_REST_SOURCES rest_catalog.cc)

set(ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS)
set(ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS)
set(ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS)
set(ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS)

list(APPEND ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS
"$<IF:$<TARGET_EXISTS:iceberg_static>,iceberg_static,iceberg_shared>" cpr::cpr)
list(APPEND ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS
"$<IF:$<TARGET_EXISTS:iceberg_shared>,iceberg_shared,iceberg_static>" cpr::cpr)
list(APPEND
ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_static>,Iceberg::iceberg_static,Iceberg::iceberg_shared>"
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>")
list(APPEND
ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_shared>,Iceberg::iceberg_shared,Iceberg::iceberg_static>"
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>")

add_iceberg_lib(iceberg_rest
SOURCES
${ICEBERG_REST_SOURCES}
SHARED_LINK_LIBS
${ICEBERG_REST_SHARED_BUILD_INTERFACE_LIBS}
STATIC_LINK_LIBS
${ICEBERG_REST_STATIC_BUILD_INTERFACE_LIBS}
STATIC_INSTALL_INTERFACE_LIBS
${ICEBERG_REST_STATIC_INSTALL_INTERFACE_LIBS}
SHARED_INSTALL_INTERFACE_LIBS
${ICEBERG_REST_SHARED_INSTALL_INTERFACE_LIBS})

iceberg_install_all_headers(iceberg/catalog/rest)
42 changes: 42 additions & 0 deletions src/iceberg/catalog/rest/rest_catalog.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#include "iceberg/catalog/rest/rest_catalog.h"

#include <utility>

#include <cpr/cpr.h>

namespace iceberg::catalog::rest {

RestCatalog::RestCatalog(const std::string& base_url) : base_url_(std::move(base_url)) {}

cpr::Response RestCatalog::GetConfig() {
cpr::Url url = cpr::Url{base_url_ + "/v1/config"};
cpr::Response r = cpr::Get(url);
return r;
}

cpr::Response RestCatalog::ListNamespaces() {
cpr::Url url = cpr::Url{base_url_ + "/v1/namespaces"};
cpr::Response r = cpr::Get(url);
return r;
}

} // namespace iceberg::catalog::rest
41 changes: 41 additions & 0 deletions src/iceberg/catalog/rest/rest_catalog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

#pragma once

#include <string>

#include <cpr/cpr.h>

#include "iceberg/catalog/rest/iceberg_rest_export.h"

namespace iceberg::catalog::rest {

class ICEBERG_REST_EXPORT RestCatalog {
public:
explicit RestCatalog(const std::string& base_url);
~RestCatalog() = default;

cpr::Response GetConfig();

cpr::Response ListNamespaces();

private:
std::string base_url_;
};

} // namespace iceberg::catalog::rest
Loading