Skip to content

Commit 4ae2907

Browse files
committed
add iceberg-rest-catalog library and basic code for POC
1 parent 6a88541 commit 4ae2907

File tree

6 files changed

+228
-0
lines changed

6 files changed

+228
-0
lines changed

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_CATALOG "Build REST catalog library" 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: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,75 @@ function(resolve_avro_dependency)
229229
PARENT_SCOPE)
230230
endfunction()
231231

232+
# ----------------------------------------------------------------------
233+
# cpr (C++ Requests)
234+
235+
function(resolve_cpr_dependency)
236+
prepare_fetchcontent()
237+
238+
set(CPR_BUILD_TESTS
239+
OFF
240+
CACHE BOOL "" FORCE)
241+
242+
set(CPR_BUILD_STATIC
243+
ON
244+
CACHE BOOL "" FORCE)
245+
246+
set(CPR_USE_SYSTEM_CURL
247+
OFF
248+
CACHE BOOL "" FORCE)
249+
250+
set(CPR_USE_SYSTEM_LIB_PSL
251+
ON
252+
CACHE BOOL "" FORCE)
253+
254+
# Disable IDN support in curl to avoid linking issues
255+
set(CURL_DISABLE_LDAP
256+
ON
257+
CACHE BOOL "" FORCE)
258+
259+
set(CURL_DISABLE_LDAPS
260+
ON
261+
CACHE BOOL "" FORCE)
262+
263+
set(USE_LIBIDN2
264+
OFF
265+
CACHE BOOL "" FORCE)
266+
267+
set(USE_IDN
268+
OFF
269+
CACHE BOOL "" FORCE)
270+
271+
fetchcontent_declare(cpr
272+
${FC_DECLARE_COMMON_OPTIONS}
273+
GIT_REPOSITORY https://github.com/libcpr/cpr.git
274+
GIT_TAG "1.11.0")
275+
276+
fetchcontent_makeavailable(cpr)
277+
278+
if(cpr_SOURCE_DIR)
279+
set_target_properties(cpr PROPERTIES OUTPUT_NAME "iceberg_vendored_cpr"
280+
POSITION_INDEPENDENT_CODE ON)
281+
282+
install(TARGETS cpr
283+
EXPORT iceberg_targets
284+
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
285+
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
286+
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
287+
set(CPR_VENDORED TRUE)
288+
else()
289+
set(CPR_VENDORED FALSE)
290+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES cpr)
291+
endif()
292+
293+
set(CPR_VENDORED
294+
${CPR_VENDORED}
295+
PARENT_SCOPE)
296+
set(ICEBERG_SYSTEM_DEPENDENCIES
297+
${ICEBERG_SYSTEM_DEPENDENCIES}
298+
PARENT_SCOPE)
299+
endfunction()
300+
232301
# ----------------------------------------------------------------------
233302
# Nanoarrow
234303

@@ -373,3 +442,7 @@ if(ICEBERG_BUILD_BUNDLE)
373442
resolve_avro_dependency()
374443
resolve_zstd_dependency()
375444
endif()
445+
446+
if(ICEBERG_BUILD_REST_CATALOG)
447+
resolve_cpr_dependency()
448+
endif()

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_CATALOG)
21+
add_subdirectory(rest)
22+
endif()
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
if(NOT ICEBERG_BUILD_REST_CATALOG)
19+
return()
20+
endif()
21+
22+
set(ICEBERG_REST_CATALOG_SOURCES rest_catalog.cc)
23+
24+
set(ICEBERG_REST_CATALOG_STATIC_BUILD_INTERFACE_LIBS)
25+
set(ICEBERG_REST_CATALOG_SHARED_BUILD_INTERFACE_LIBS)
26+
set(ICEBERG_REST_CATALOG_STATIC_INSTALL_INTERFACE_LIBS)
27+
set(ICEBERG_REST_CATALOG_SHARED_INSTALL_INTERFACE_LIBS)
28+
29+
list(APPEND ICEBERG_REST_CATALOG_STATIC_BUILD_INTERFACE_LIBS
30+
"$<IF:$<TARGET_EXISTS:iceberg_static>,iceberg_static,iceberg_shared>" cpr::cpr)
31+
list(APPEND ICEBERG_REST_CATALOG_SHARED_BUILD_INTERFACE_LIBS
32+
"$<IF:$<TARGET_EXISTS:iceberg_shared>,iceberg_shared,iceberg_static>" cpr::cpr)
33+
list(APPEND
34+
ICEBERG_REST_CATALOG_STATIC_INSTALL_INTERFACE_LIBS
35+
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_static>,Iceberg::iceberg_static,Iceberg::iceberg_shared>"
36+
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>")
37+
list(APPEND
38+
ICEBERG_REST_CATALOG_SHARED_INSTALL_INTERFACE_LIBS
39+
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_shared>,Iceberg::iceberg_shared,Iceberg::iceberg_static>"
40+
"$<IF:$<BOOL:${CPR_VENDORED}>,Iceberg::cpr,cpr::cpr>")
41+
42+
add_iceberg_lib(iceberg_rest_catalog
43+
SOURCES
44+
${ICEBERG_REST_CATALOG_SOURCES}
45+
SHARED_LINK_LIBS
46+
${ICEBERG_REST_CATALOG_SHARED_BUILD_INTERFACE_LIBS}
47+
STATIC_LINK_LIBS
48+
${ICEBERG_REST_CATALOG_STATIC_BUILD_INTERFACE_LIBS}
49+
STATIC_INSTALL_INTERFACE_LIBS
50+
${ICEBERG_REST_CATALOG_STATIC_INSTALL_INTERFACE_LIBS}
51+
SHARED_INSTALL_INTERFACE_LIBS
52+
${ICEBERG_REST_CATALOG_SHARED_INSTALL_INTERFACE_LIBS})
53+
54+
iceberg_install_all_headers(iceberg/catalog/rest)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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+
#include "iceberg/catalog/rest/rest_catalog.h"
19+
20+
#include <iostream>
21+
22+
#include <cpr/cpr.h>
23+
24+
namespace iceberg {
25+
namespace catalog {
26+
namespace rest {
27+
28+
RestCatalog::RestCatalog(const std::string& base_url) : base_url_(std::move(base_url)) {}
29+
30+
void RestCatalog::testCprIntegration() {
31+
std::cout << "Testing CPR integration with base URL: " << base_url_ << std::endl;
32+
33+
// Simple GET request demo
34+
cpr::Response r =
35+
cpr::Get(cpr::Url{"https://httpbin.org/get"}, cpr::Parameters{{"hello", "world"}});
36+
37+
std::cout << "Status code: " << r.status_code << std::endl;
38+
std::cout << "Content-Type: " << r.header["content-type"] << std::endl;
39+
std::cout << "Response text (first 200 chars): "
40+
<< r.text.substr(0, std::min<size_t>(200, r.text.size())) << "..."
41+
<< std::endl;
42+
43+
// Simulated REST catalog API request
44+
std::string catalog_url = base_url_ + "/v1/namespaces";
45+
std::cout << "\nSimulated catalog request to: " << catalog_url << std::endl;
46+
47+
// In real implementation, this would be:
48+
// cpr::Response catalog_r = cpr::Get(cpr::Url{catalog_url},
49+
// cpr::Header{{"Content-Type", "application/json"}});
50+
}
51+
52+
} // namespace rest
53+
} // namespace catalog
54+
} // namespace iceberg
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
#ifndef ICEBERG_CATALOG_REST_REST_CATALOG_H
19+
#define ICEBERG_CATALOG_REST_REST_CATALOG_H
20+
21+
#include <string>
22+
23+
namespace iceberg {
24+
namespace catalog {
25+
namespace rest {
26+
27+
class RestCatalog {
28+
public:
29+
RestCatalog(const std::string& base_url);
30+
~RestCatalog() = default;
31+
32+
void testCprIntegration();
33+
34+
private:
35+
std::string base_url_;
36+
};
37+
38+
} // namespace rest
39+
} // namespace catalog
40+
} // namespace iceberg
41+
42+
#endif // ICEBERG_CATALOG_REST_REST_CATALOG_H

0 commit comments

Comments
 (0)