Skip to content

Commit df19415

Browse files
author
nullccxsy
committed
feat: add CRoaring dependency
- Integrated CRoaring library into the project by adding a new function to resolve its dependency in `IcebergThirdpartyToolchain.cmake`. - Updated the CMakeLists to include CRoaring in both static and shared build interfaces.
1 parent 9b69e45 commit df19415

File tree

5 files changed

+116
-1
lines changed

5 files changed

+116
-1
lines changed

.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
88+
vcpkg install zlib:x64-windows nlohmann-json:x64-windows nanoarrow:x64-windows roaring:x64-windows
8989
- name: Build Iceberg
9090
shell: cmd
9191
run: |

cmake_modules/IcebergThirdpartyToolchain.cmake

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,54 @@ function(resolve_nanoarrow_dependency)
261261
PARENT_SCOPE)
262262
endfunction()
263263

264+
# ----------------------------------------------------------------------
265+
# CRoaring
266+
267+
function(resolve_croaring_dependency)
268+
prepare_fetchcontent()
269+
270+
set(BUILD_TESTING
271+
OFF
272+
CACHE BOOL "Disable CRoaring tests" FORCE)
273+
274+
fetchcontent_declare(croaring
275+
${FC_DECLARE_COMMON_OPTIONS}
276+
URL "https://github.com/RoaringBitmap/CRoaring/archive/refs/tags/v4.3.11.tar.gz"
277+
FIND_PACKAGE_ARGS
278+
NAMES
279+
roaring
280+
CONFIG)
281+
fetchcontent_makeavailable(croaring)
282+
283+
if(croaring_SOURCE_DIR)
284+
if(NOT TARGET roaring::roaring)
285+
add_library(roaring::roaring INTERFACE IMPORTED)
286+
target_link_libraries(roaring::roaring INTERFACE roaring)
287+
target_include_directories(roaring::roaring INTERFACE ${croaring_BINARY_DIR}
288+
${croaring_SOURCE_DIR}/cpp)
289+
endif()
290+
291+
set(CROARING_VENDORED TRUE)
292+
set_target_properties(roaring PROPERTIES OUTPUT_NAME "iceberg_vendored_croaring"
293+
POSITION_INDEPENDENT_CODE ON)
294+
install(TARGETS roaring
295+
EXPORT iceberg_targets
296+
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
297+
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
298+
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
299+
else()
300+
set(CROARING_VENDORED FALSE)
301+
list(APPEND ICEBERG_SYSTEM_DEPENDENCIES roaring)
302+
endif()
303+
304+
set(ICEBERG_SYSTEM_DEPENDENCIES
305+
${ICEBERG_SYSTEM_DEPENDENCIES}
306+
PARENT_SCOPE)
307+
set(CROARING_VENDORED
308+
${CROARING_VENDORED}
309+
PARENT_SCOPE)
310+
endfunction()
311+
264312
# ----------------------------------------------------------------------
265313
# nlohmann-json
266314

@@ -398,6 +446,7 @@ endfunction()
398446

399447
resolve_zlib_dependency()
400448
resolve_nanoarrow_dependency()
449+
resolve_croaring_dependency()
401450
resolve_nlohmann_json_dependency()
402451
resolve_spdlog_dependency()
403452

src/iceberg/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,27 @@ set(ICEBERG_SHARED_INSTALL_INTERFACE_LIBS)
6161
list(APPEND
6262
ICEBERG_STATIC_BUILD_INTERFACE_LIBS
6363
nanoarrow::nanoarrow_static
64+
roaring::roaring
6465
nlohmann_json::nlohmann_json
6566
spdlog::spdlog
6667
ZLIB::ZLIB)
6768
list(APPEND
6869
ICEBERG_SHARED_BUILD_INTERFACE_LIBS
6970
nanoarrow::nanoarrow_shared
71+
roaring::roaring
7072
nlohmann_json::nlohmann_json
7173
spdlog::spdlog
7274
ZLIB::ZLIB)
7375
list(APPEND
7476
ICEBERG_STATIC_INSTALL_INTERFACE_LIBS
7577
"$<IF:$<BOOL:${NANOARROW_VENDORED}>,Iceberg::nanoarrow_static,$<IF:$<TARGET_EXISTS:nanoarrow::nanoarrow_static>,nanoarrow::nanoarrow_static,nanoarrow::nanoarrow_shared>>"
78+
"$<IF:$<BOOL:${CROARING_VENDORED}>,Iceberg::roaring,$<IF:$<TARGET_EXISTS:roaring::roaring>,roaring::roaring,roaring::roaring>>"
7679
"$<IF:$<BOOL:${NLOHMANN_JSON_VENDORED}>,Iceberg::nlohmann_json,$<IF:$<TARGET_EXISTS:nlohmann_json::nlohmann_json>,nlohmann_json::nlohmann_json,nlohmann_json::nlohmann_json>>"
7780
"$<IF:$<BOOL:${SPDLOG_VENDORED}>,Iceberg::spdlog,spdlog::spdlog>")
7881
list(APPEND
7982
ICEBERG_SHARED_INSTALL_INTERFACE_LIBS
8083
"$<IF:$<BOOL:${NANOARROW_VENDORED}>,Iceberg::nanoarrow_shared,$<IF:$<TARGET_EXISTS:nanoarrow::nanoarrow_shared>,nanoarrow::nanoarrow_shared,nanoarrow::nanoarrow_static>>"
84+
"$<IF:$<BOOL:${CROARING_VENDORED}>,Iceberg::roaring,$<IF:$<TARGET_EXISTS:roaring::roaring>,roaring::roaring,roaring::roaring>>"
8185
"$<IF:$<BOOL:${NLOHMANN_JSON_VENDORED}>,Iceberg::nlohmann_json,$<IF:$<TARGET_EXISTS:nlohmann_json::nlohmann_json>,nlohmann_json::nlohmann_json,nlohmann_json::nlohmann_json>>"
8286
"$<IF:$<BOOL:${SPDLOG_VENDORED}>,Iceberg::spdlog,spdlog::spdlog>")
8387

test/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ add_iceberg_test(util_test
9292
string_util_test.cc
9393
visit_type_test.cc)
9494

95+
add_iceberg_test(roaring_test SOURCES roaring_test.cc)
96+
9597
if(ICEBERG_BUILD_BUNDLE)
9698
add_iceberg_test(avro_test
9799
USE_BUNDLE

test/roaring_test.cc

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
#include "roaring/roaring.hh"
20+
21+
#include <gtest/gtest.h>
22+
23+
#include "roaring/roaring64map.hh"
24+
25+
namespace iceberg {
26+
27+
TEST(CRoaringTest, Basic32Bit) {
28+
roaring::Roaring r1;
29+
for (uint32_t i = 100; i < 1000; i++) {
30+
r1.add(i);
31+
}
32+
ASSERT_EQ(r1.cardinality(), 900);
33+
ASSERT_TRUE(r1.contains(500));
34+
ASSERT_FALSE(r1.contains(50));
35+
ASSERT_FALSE(r1.isEmpty());
36+
}
37+
38+
TEST(CRoaringTest, Basic64Bit) {
39+
roaring::Roaring64Map r2;
40+
for (uint64_t i = 18000000000000000100ull; i < 18000000000000001000ull; i++) {
41+
r2.add(i);
42+
}
43+
ASSERT_EQ(r2.cardinality(), 900);
44+
ASSERT_TRUE(r2.contains(18000000000000000500ull));
45+
ASSERT_FALSE(r2.contains(18000000000000000050ull));
46+
ASSERT_FALSE(r2.isEmpty());
47+
}
48+
49+
TEST(CRoaringTest, ConstructorWithInitializerList) {
50+
roaring::Roaring r1 = roaring::Roaring::bitmapOf(5, 1, 2, 3, 5, 6);
51+
ASSERT_EQ(r1.cardinality(), 5);
52+
ASSERT_TRUE(r1.contains(1));
53+
ASSERT_TRUE(r1.contains(2));
54+
ASSERT_TRUE(r1.contains(3));
55+
ASSERT_TRUE(r1.contains(5));
56+
ASSERT_TRUE(r1.contains(6));
57+
ASSERT_FALSE(r1.contains(4));
58+
}
59+
60+
} // namespace iceberg

0 commit comments

Comments
 (0)