Skip to content

Commit 6cb5a40

Browse files
committed
feat(mosaic): support Mosaic file format
1 parent 05d6497 commit 6cb5a40

32 files changed

Lines changed: 1758 additions & 18 deletions

.github/workflows/build_and_test.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ jobs:
7575
- name: asan-ubsan-x86_64
7676
build_args: --enable_asan --enable_ubsan
7777
- name: tsan-x86_64
78-
skip_rust: true
7978
build_args: --enable_tsan
8079
- name: gcc-debug-aarch64
8180
runner: ubuntu-24.04-arm
@@ -96,7 +95,6 @@ jobs:
9695
build_args: --build_type Release
9796
- name: tsan-aarch64
9897
runner: ubuntu-24.04-arm
99-
skip_rust: true
10098
build_args: --enable_tsan
10199
steps:
102100
- name: Checkout paimon-cpp
@@ -108,8 +106,7 @@ jobs:
108106
uses: ./.github/actions/setup-ccache
109107
with:
110108
cache-key-prefix: ccache-${{ matrix.name }}
111-
- name: Install Rust toolchain (tantivy-fts)
112-
if: ${{ !matrix.skip_rust }}
109+
- name: Install Rust toolchain (Mosaic and tantivy-fts)
113110
shell: bash
114111
run: ci/scripts/setup_rust.sh
115112
- name: Install HTTP and TLS development dependencies

.github/workflows/gcc8_test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ jobs:
6060
ls -la
6161
- name: Checkout paimon-cpp
6262
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
63+
- name: Install Rust toolchain (Mosaic)
64+
shell: bash
65+
run: ci/scripts/setup_rust.sh
6366
- name: Setup ccache
6467
uses: ./.github/actions/setup-ccache
6568
with:

.github/workflows/release_candidate.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
name: source-archive
132132
path: release/ci
133133

134-
- name: Install Rust toolchain (tantivy-fts)
134+
- name: Install Rust toolchain (Mosaic and tantivy-fts)
135135
shell: bash
136136
run: ci/scripts/setup_rust.sh
137137

CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ option(PAIMON_USE_UBSAN "Use Undefined Behavior Sanitizer" OFF)
6060
option(PAIMON_USE_CXX11_ABI "Use C++11 ABI" ON)
6161
option(PAIMON_ENABLE_AVRO "Whether to enable avro file format" ON)
6262
option(PAIMON_ENABLE_ORC "Whether to enable orc file format" ON)
63+
option(PAIMON_ENABLE_MOSAIC "Whether to enable mosaic file format (Rust FFI)" OFF)
6364
option(PAIMON_ENABLE_JINDO "Whether to enable jindo file system" OFF)
6465
option(PAIMON_ENABLE_S3 "Whether to enable S3 file system" OFF)
6566
option(PAIMON_ENABLE_NETWORK_TESTS
@@ -82,6 +83,9 @@ endif()
8283
if(PAIMON_ENABLE_AVRO)
8384
add_definitions(-DPAIMON_ENABLE_AVRO)
8485
endif()
86+
if(PAIMON_ENABLE_MOSAIC)
87+
add_definitions(-DPAIMON_ENABLE_MOSAIC)
88+
endif()
8589
if(PAIMON_ENABLE_JINDO)
8690
add_definitions(-DPAIMON_ENABLE_JINDO)
8791
endif()
@@ -384,6 +388,11 @@ if(PAIMON_BUILD_TESTS OR PAIMON_BUILD_BENCHMARKS)
384388
paimon_link_libraries_whole_archive(PAIMON_PARQUET_FILE_FORMAT_STATIC_LINK_LIBS
385389
paimon_parquet_file_format_static)
386390
391+
if(PAIMON_ENABLE_MOSAIC)
392+
paimon_link_libraries_whole_archive(PAIMON_MOSAIC_FILE_FORMAT_STATIC_LINK_LIBS
393+
paimon_mosaic_file_format_static)
394+
endif()
395+
387396
if(PAIMON_ENABLE_ORC)
388397
paimon_link_libraries_whole_archive(PAIMON_ORC_FILE_FORMAT_STATIC_LINK_LIBS
389398
paimon_orc_file_format_static)
@@ -435,6 +444,14 @@ if(PAIMON_BUILD_TESTS)
435444
paimon_link_libraries_whole_archive(PAIMON_PARQUET_FILE_FORMAT_STATIC_LINK_LIBS
436445
paimon_parquet_file_format_static)
437446
447+
if(PAIMON_ENABLE_MOSAIC)
448+
paimon_link_libraries_no_as_needed(TEST_PLUGIN_LINK_LIBS
449+
paimon_mosaic_file_format_shared)
450+
list(APPEND TEST_STATIC_LINK_LIBS ${TEST_PLUGIN_LINK_LIBS})
451+
paimon_link_libraries_whole_archive(PAIMON_MOSAIC_FILE_FORMAT_STATIC_LINK_LIBS
452+
paimon_mosaic_file_format_static)
453+
endif()
454+
438455
if(PAIMON_ENABLE_ORC)
439456
paimon_link_libraries_no_as_needed(TEST_PLUGIN_LINK_LIBS
440457
paimon_orc_file_format_shared)
@@ -516,6 +533,9 @@ add_subdirectory(src/paimon/format/blob)
516533
add_subdirectory(src/paimon/format/orc)
517534
add_subdirectory(src/paimon/format/parquet)
518535
add_subdirectory(src/paimon/format/avro)
536+
if(PAIMON_ENABLE_MOSAIC)
537+
add_subdirectory(src/paimon/format/mosaic)
538+
endif()
519539
if(PAIMON_ENABLE_LUMINA)
520540
add_subdirectory(src/paimon/global_index/lumina)
521541
endif()

ci/scripts/build_paimon.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ CMAKE_ARGS=(
147147
"-G Ninja"
148148
"-DCMAKE_BUILD_TYPE=${build_type}"
149149
"-DPAIMON_BUILD_TESTS=ON"
150+
"-DPAIMON_ENABLE_MOSAIC=ON"
150151
"-DPAIMON_ENABLE_JINDO=ON"
151152
"-DPAIMON_ENABLE_S3=ON"
152153
"-DPAIMON_ENABLE_LUMINA=${ENABLE_LUMINA}"

ci/scripts/setup_rust.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18-
# Install the Rust toolchain + cbindgen required to build the
19-
# tantivy-fts FFI crate (crates/tantivy_ffi) from CI.
18+
# Install the Rust toolchain used by the Mosaic and tantivy-fts FFI builds, plus cbindgen required
19+
# by tantivy-fts.
2020
#
2121
# The dev container (see .devcontainer/) already has these preinstalled;
22-
# this script is for the GitHub Actions runners. Called by
23-
# .github/workflows/build_and_test.yaml before ci/scripts/build_paimon.sh.
22+
# this script is for the GitHub Actions runners and is called before ci/scripts/build_paimon.sh.
2423
#
2524
# Idempotent: a second invocation is a no-op when the tools already exist.
2625

cmake_modules/ThirdpartyToolchain.cmake

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ else()
9191
endif()
9292
endif()
9393

94+
if(DEFINED ENV{PAIMON_MOSAIC_URL})
95+
set(MOSAIC_SOURCE_URL "$ENV{PAIMON_MOSAIC_URL}")
96+
else()
97+
if(EXISTS "${THIRDPARTY_DIR}/${PAIMON_MOSAIC_PKG_NAME}")
98+
set_urls(MOSAIC_SOURCE_URL "${THIRDPARTY_DIR}/${PAIMON_MOSAIC_PKG_NAME}")
99+
else()
100+
set_urls(MOSAIC_SOURCE_URL
101+
"https://downloads.apache.org/paimon/paimon-mosaic-${PAIMON_MOSAIC_BUILD_VERSION}/${PAIMON_MOSAIC_PKG_NAME}"
102+
)
103+
endif()
104+
endif()
105+
94106
if(DEFINED ENV{PAIMON_RAPIDJSON_URL})
95107
set(RAPIDJSON_SOURCE_URL "$ENV{PAIMON_RAPIDJSON_URL}")
96108
else()
@@ -1314,6 +1326,51 @@ macro(build_lumina)
13141326
install(FILES "${LUMINA_DYNAMIC_LIB}" DESTINATION ${CMAKE_INSTALL_LIBDIR})
13151327
endmacro()
13161328

1329+
macro(build_mosaic)
1330+
message(STATUS "Building Apache Paimon Mosaic Rust FFI from source")
1331+
find_program(PAIMON_CARGO_EXECUTABLE cargo REQUIRED)
1332+
1333+
set(MOSAIC_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/mosaic_ep-install")
1334+
set(MOSAIC_INCLUDE_DIR "${MOSAIC_PREFIX}/include")
1335+
set(MOSAIC_LIB_DIR "${MOSAIC_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
1336+
set(MOSAIC_DYNAMIC_LIB
1337+
"${MOSAIC_LIB_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}paimon_mosaic_ffi${CMAKE_SHARED_LIBRARY_SUFFIX}"
1338+
)
1339+
set(MOSAIC_CARGO_TARGET_DIR "${CMAKE_CURRENT_BINARY_DIR}/mosaic_ep-cargo")
1340+
set(MOSAIC_CARGO_DYNAMIC_LIB
1341+
"${MOSAIC_CARGO_TARGET_DIR}/release/${CMAKE_SHARED_LIBRARY_PREFIX}paimon_mosaic_ffi${CMAKE_SHARED_LIBRARY_SUFFIX}"
1342+
)
1343+
1344+
file(MAKE_DIRECTORY "${MOSAIC_INCLUDE_DIR}")
1345+
file(MAKE_DIRECTORY "${MOSAIC_LIB_DIR}")
1346+
1347+
externalproject_add(
1348+
mosaic_ep
1349+
URL ${MOSAIC_SOURCE_URL}
1350+
URL_HASH "SHA256=${PAIMON_MOSAIC_BUILD_SHA256_CHECKSUM}"
1351+
${THIRDPARTY_LOG_OPTIONS}
1352+
CONFIGURE_COMMAND ""
1353+
BUILD_COMMAND
1354+
${CMAKE_COMMAND} -E env CARGO_TARGET_DIR=${MOSAIC_CARGO_TARGET_DIR}
1355+
${PAIMON_CARGO_EXECUTABLE} build --release --manifest-path
1356+
<SOURCE_DIR>/ffi/Cargo.toml
1357+
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${MOSAIC_CARGO_DYNAMIC_LIB}
1358+
${MOSAIC_DYNAMIC_LIB}
1359+
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy_directory <SOURCE_DIR>/include
1360+
${MOSAIC_INCLUDE_DIR}
1361+
BUILD_BYPRODUCTS "${MOSAIC_DYNAMIC_LIB}")
1362+
1363+
add_library(paimon_mosaic_ffi SHARED IMPORTED GLOBAL)
1364+
set_target_properties(
1365+
paimon_mosaic_ffi
1366+
PROPERTIES IMPORTED_LOCATION "${MOSAIC_DYNAMIC_LIB}"
1367+
IMPORTED_NO_SONAME TRUE
1368+
INTERFACE_INCLUDE_DIRECTORIES "${MOSAIC_INCLUDE_DIR}")
1369+
add_dependencies(paimon_mosaic_ffi mosaic_ep)
1370+
1371+
install(FILES "${MOSAIC_DYNAMIC_LIB}" DESTINATION ${CMAKE_INSTALL_LIBDIR})
1372+
endmacro()
1373+
13171374
macro(build_jindosdk_nextarch)
13181375
message(STATUS "Building jindosdk-nextarch from local source")
13191376

@@ -1953,6 +2010,9 @@ paimon_warn_if_mixed_arrow_dependencies()
19532010
resolve_dependency(TBB)
19542011
resolve_dependency(glog)
19552012

2013+
if(PAIMON_ENABLE_MOSAIC)
2014+
build_mosaic()
2015+
endif()
19562016
if(PAIMON_ENABLE_AVRO)
19572017
resolve_dependency(Avro)
19582018
endif()

include/paimon/defs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ struct PAIMON_EXPORT Options {
156156
/// 9, but the read and write speed will significantly decrease. Default value is 1.
157157
static const char FILE_COMPRESSION_ZSTD_LEVEL[];
158158

159+
/// "file.block-size" - File block size of format, default value of orc stripe is 64 MB, and
160+
/// parquet row group is 128 MB.
161+
static const char FILE_BLOCK_SIZE[];
162+
159163
/// "manifest.target-file-size" - Suggested file size of a manifest file.
160164
/// Default value is 8MB.
161165
static const char MANIFEST_TARGET_FILE_SIZE[];

src/paimon/common/defs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const char Options::PAGE_SIZE[] = "page-size";
4646
const char Options::PARTITION_DEFAULT_NAME[] = "partition.default-name";
4747
const char Options::FILE_COMPRESSION[] = "file.compression";
4848
const char Options::FILE_COMPRESSION_ZSTD_LEVEL[] = "file.compression.zstd-level";
49+
const char Options::FILE_BLOCK_SIZE[] = "file.block-size";
4950
const char Options::MANIFEST_TARGET_FILE_SIZE[] = "manifest.target-file-size";
5051
const char Options::MANIFEST_FORMAT[] = "manifest.format";
5152
const char Options::MANIFEST_COMPRESSION[] = "manifest.compression";
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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(PAIMON_MOSAIC_FILE_FORMAT
19+
mosaic_file_batch_reader.cpp
20+
mosaic_file_format.cpp
21+
mosaic_file_format_factory.cpp
22+
mosaic_format_writer.cpp
23+
mosaic_stream.cpp
24+
mosaic_writer_builder.cpp)
25+
26+
add_paimon_lib(paimon_mosaic_file_format
27+
SOURCES
28+
${PAIMON_MOSAIC_FILE_FORMAT}
29+
DEPENDENCIES
30+
paimon_shared
31+
paimon_mosaic_ffi
32+
STATIC_LINK_LIBS
33+
arrow
34+
fmt
35+
paimon_mosaic_ffi
36+
Threads::Threads
37+
SHARED_LINK_LIBS
38+
paimon_shared
39+
paimon_mosaic_ffi
40+
SHARED_LINK_FLAGS
41+
${PAIMON_VERSION_SCRIPT_FLAGS})
42+
43+
target_link_libraries(paimon_mosaic_file_format_objlib PUBLIC paimon_mosaic_ffi)
44+
45+
if(PAIMON_BUILD_TESTS)
46+
add_paimon_test(mosaic_format_test
47+
SOURCES
48+
mosaic_file_format_test.cpp
49+
STATIC_LINK_LIBS
50+
paimon_shared
51+
test_utils_static
52+
${PAIMON_MOSAIC_FILE_FORMAT_STATIC_LINK_LIBS}
53+
${PAIMON_LOCAL_FILE_SYSTEM_STATIC_LINK_LIBS}
54+
paimon_mosaic_ffi
55+
${GTEST_LINK_TOOLCHAIN})
56+
endif()

0 commit comments

Comments
 (0)