Skip to content

Commit 991b852

Browse files
ColinLeeoclaude
andcommitted
TsFile C++: batch read/write optimization + parallel decode
Squashed PR snapshot of the long-lived `final` work, rebased on top of current develop (2a864c5). Combines the original "TsFile C++ batch read/write optimization" (5f12115) snapshot with subsequent build / platform fixes and a follow-up read-path optimization commit (c902b2b). ═════════════════════════════════════════════════════════════════════ Read path ═════════════════════════════════════════════════════════════════════ - Decoder base gains batch APIs (read_batch_int32 / int64 / float / double, skip_*); PLAIN, TS2DIFF, Gorilla decoders implement them. TS2DIFF has block-level peeking so time filters can skip blocks without decoding. Gorilla adds a raw-pointer GorillaBitReader that bypasses ByteStream overhead. - ChunkReader / AlignedChunkReader add *_DECODE_TV_BATCH methods that decode time + value into a TsBlock in one pass, applying batch time filters before append. - AlignedChunkReader supports a multi-value mode: one time chunk + N value chunks decoded in a single pass, sharing the decoded timestamps and filter mask. SingleDeviceTsBlockReader auto-detects same-device measurements via VectorMeasurementColumnContext. - Optional page-level parallel decompression via a DecodeThreadPool when ENABLE_THREADS is set. Page-plan classification (SKIP / FULL_PASS / BOUNDARY) lets a scatter-free memcpy fast path fire when every row passes and no column has nulls. Additional optimizations (from c902b2b, ported from `final`): - Aligned fast path: enable_dense_aligned_fast_path defaults true and compute_dense_row_count falls back to the TimeseriesIndex top-level statistic for single-chunk timeseries (chunk-level stat is omitted during serialization for those). Re-enables the bulk-copy SSI --> caller path that was defensively disabled. - Chunk-level parallel decode: per-column tasks own all that column's pages and write into a per-(col,page) PageDecodedState slot; one wait_all per chunk amortizes thread-pool overhead. Hybrid dispatch in get_next_page_multi — chunk-level for narrow chunks (<= 6 value columns), 4/6 thesis path otherwise to avoid cache thrash. - Per-worker time decoder/compressor pool (via ThreadPool:: current_worker_id) parallelizes the previously-serial time-page decode loop. - Pre-decode int64/float/double values in the parallel worker into ValueColumnState::pending_decoded_values; multi_DECODE_TV_BATCH then memcpys the per-batch slice instead of calling the decoder inline. - Partial-page bulk scatter: bulk-memcpy path now copies min(budget, remaining_in_page) rows from page_time_cursor_ so the tail page of every SSI tsblock takes the memcpy fast path instead of bleeding into the row-by-row scatter loop. - tsblock_max_memory_ 64KB -> 2MB so a 10K-row page fits in one SSI tsblock and bulk_copy_into doesn't fragment into many tiny batches. ═════════════════════════════════════════════════════════════════════ Write path ═════════════════════════════════════════════════════════════════════ - ValuePageWriter gains write_batch / write_string_batch that take timestamp + value + nullness arrays directly, removing the per-value append loop. Tablet exposes set_timestamps / set_column_values / set_column_string_repeated / reset for bulk reuse and switches StringColumn to an Arrow-compatible offset+buffer layout. - TS2DIFFEncoder::flush packs all deltas with a single pack_bits_msb + write_buf instead of per-value write_bits, falling back to the scalar path for the rare bit_width > 56 case. - Int64Statistic::update_batch (NEON-accelerated min/max/sum). ═════════════════════════════════════════════════════════════════════ Encoding / SIMD ═════════════════════════════════════════════════════════════════════ - TS2DIFF batch decode adds AVX2 helpers via SIMDe (already on develop) for both i32 and i64; scalar fallback unchanged. - PLAIN byte-swap path uses ARM NEON (vrev64q_u8 / vrev32q_u8) when available, falling back to __builtin_bswap. - CMakeLists adds ENABLE_SIMD; Release builds turn on -O3 -march=native -flto (off when ASan is on or on Windows/MinGW). ═════════════════════════════════════════════════════════════════════ Allocator / ByteStream / ThreadPool ═════════════════════════════════════════════════════════════════════ - ByteStream caches page_mask_ (= page_size - 1) so the hot path uses a bitmask instead of modulo; wrap_from rounds buffer sizes up to a power of two for correctness. - common::ThreadPool gets a thread_local current_worker_id() accessor (set by worker_loop) and a num_threads() getter, letting callers attach per-worker state without contention. ═════════════════════════════════════════════════════════════════════ Build / platform ═════════════════════════════════════════════════════════════════════ - Linux Release: -march=native + -flto by default, automatically dropped under ASan to keep leak detection accurate. - MSVC / MinGW: replace GCC-only intrinsics, restore lost includes, disable LTO + -march=native there. - Restore tag_filter_create/between, metadata test, and segment behavior; restore cwrapper metadata + tag_filter/batch_size args on table query C APIs that the batch-opt snapshot had dropped. - Disable QueryByRowPerformanceTest and the flaky QueryByRowFasterThanManualNext test. ═════════════════════════════════════════════════════════════════════ Python binding ═════════════════════════════════════════════════════════════════════ - read_series_by_row: pull TsBlocks via Arrow IPC instead of the row-by-row Python loop. Aligns reader query plumbing with develop so the binding sees the same parameter set. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2a864c5 commit 991b852

174 files changed

Lines changed: 10233 additions & 6146 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

RELEASE_NOTES.md

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,6 @@
1818
under the License.
1919
2020
-->
21-
# Apache TsFile 2.3.1
22-
23-
## New Features
24-
25-
- Added scripts to convert CSV, Parquet and Arrow formats to TsFile.
26-
- Adapted TsFile for the MSVC compiler.
27-
28-
## Bugs
29-
30-
- Fixed the issue that the format conversion scripts did not support date and timestamp data types.
31-
- Fixed garbled characters when using Chinese table names in the conversion scripts.
32-
- Fixed the issue where TsFile displayed empty when converting with uppercase column names.
33-
3421
# Apache TsFile 2.3.0
3522

3623
## New Features
@@ -200,7 +187,7 @@
200187
* Added accountable function to measurementSchema by @Caideyipi in #509
201188
* Correct the retained size calculation for BinaryColumn and BinaryColumnBuilder by @JackieTien97 in #514
202189
* add switch to disable native lz4 (#480) by @jt2594838 in #515
203-
* Correct the memory calculation of BinaryColumnBuilder by @JackieTien97 in #530
190+
* Correct the memroy calculation of BinaryColumnBuilder by @JackieTien97 in #530
204191
* Fetch max tsblock line number each time from TSFileConfig by @JackieTien97 in #535
205192
* Support set default compression by data type & Bump org.apache.commons:commons-lang3 from 3.15.0 to 3.18.0 by @jt2594838 in #547
206193
* Avoid calculating shallow size of map by @shuwenwei in #566

cpp/CLAUDE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ cpp/src/
9292
## Code Style
9393

9494
- **Formatter**: clang-format (Google style), configured in `.clang-format`
95-
- After modifying C++ code, run from the repo root to format: `./mvnw spotless:apply -P with-cpp`
9695

9796
## Testing
9897

cpp/CMakeLists.txt

100755100644
Lines changed: 48 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,10 @@ endif ()
3232
set(TsFile_CPP_VERSION 2.2.1.dev)
3333

3434
if (MSVC)
35-
# MSVC does not provide a /std:c++11 flag; C++11 is its implicit baseline.
36-
# The lowest explicitly settable standard is /std:c++14. Without this flag,
37-
# the default varies by VS version (VS2017+ defaults to C++14 mode with some
38-
# C++17 extensions), so we pin it explicitly for reproducibility.
35+
# MSVC has no /std:c++11 flag; pin the closest supported standard mode.
3936
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} /W3 /utf-8 /EHsc /bigobj /Zc:__cplusplus /std:c++14")
4037
add_definitions(-DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS
4138
-D_SCL_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS)
42-
# Export all symbols of the tsfile shared library automatically so that
43-
# consumers do not need __declspec(dllexport) annotations.
4439
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
4540
else ()
4641
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -Wall")
@@ -51,8 +46,6 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
5146
endif ()
5247

5348
message("cmake using: USE_CPP11=${USE_CPP11}")
54-
# MSVC has no /std:c++11; CMake maps this to the closest supported standard
55-
# (C++14 default on MSVC), which compiles the C++11 codebase fine.
5649
set(CMAKE_CXX_STANDARD 11)
5750
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
5851
if (NOT MSVC)
@@ -80,13 +73,6 @@ if (${COV_ENABLED})
8073
message("add_definitions -DCOV_ENABLED=1")
8174
endif ()
8275

83-
option(ENABLE_MEM_STAT "Enable memory status" ON)
84-
85-
if (ENABLE_MEM_STAT)
86-
add_definitions(-DENABLE_MEM_STAT)
87-
message("add_definitions -DENABLE_MEM_STAT")
88-
endif ()
89-
9076

9177
if (NOT CMAKE_BUILD_TYPE)
9278
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
@@ -105,37 +91,25 @@ else ()
10591
endif ()
10692

10793
message("CMAKE BUILD TYPE " ${CMAKE_BUILD_TYPE})
108-
# Keep optimization policy external by default (caller/toolchain/CMake defaults).
109-
set(TSFILE_OPTIMIZATION_FLAGS ""
110-
CACHE STRING
111-
"Optional extra optimization flags for tsfile-cpp (e.g. -O3). Empty means inherit caller defaults.")
112-
if (TSFILE_OPTIMIZATION_FLAGS)
113-
# Apply after CMake defaults for each config so explicit optimization can
114-
# override default -O flags in Release/RelWithDebInfo/Debug/MinSizeRel.
115-
set(CMAKE_CXX_FLAGS_DEBUG
116-
"${CMAKE_CXX_FLAGS_DEBUG} ${TSFILE_OPTIMIZATION_FLAGS}")
117-
set(CMAKE_CXX_FLAGS_RELEASE
118-
"${CMAKE_CXX_FLAGS_RELEASE} ${TSFILE_OPTIMIZATION_FLAGS}")
119-
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO
120-
"${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ${TSFILE_OPTIMIZATION_FLAGS}")
121-
set(CMAKE_CXX_FLAGS_MINSIZEREL
122-
"${CMAKE_CXX_FLAGS_MINSIZEREL} ${TSFILE_OPTIMIZATION_FLAGS}")
123-
message("cmake using: TSFILE_OPTIMIZATION_FLAGS=${TSFILE_OPTIMIZATION_FLAGS}")
124-
else ()
125-
message("cmake using: TSFILE_OPTIMIZATION_FLAGS=<inherit>")
126-
# MSVC provides sensible per-configuration optimization flags by default; the
127-
# GCC-style flags below would be rejected by cl.exe, so skip them on MSVC.
128-
if (NOT MSVC)
129-
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
130-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
131-
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
132-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2")
133-
elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
134-
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g")
135-
elseif (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
136-
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -ffunction-sections -fdata-sections -Os")
137-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
94+
if (NOT MSVC)
95+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
96+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
97+
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
98+
# -flto + MinGW gcc + statically-linked antlr4_static produces
99+
# unresolved-reference errors at link time (LTO intermediate objects
100+
# can't see the .a's vtable thunks). -march=native is also a poor
101+
# default for CI binaries shipped to other machines. Keep both on
102+
# Linux/macOS where the optimization actually pays off.
103+
if (MINGW OR WIN32)
104+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
105+
else ()
106+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march=native -flto")
138107
endif ()
108+
elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
109+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O2 -g")
110+
elseif (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
111+
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -ffunction-sections -fdata-sections -Os")
112+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections")
139113
endif ()
140114
endif ()
141115
message("CMAKE DEBUG: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}")
@@ -146,22 +120,11 @@ option(ENABLE_ASAN "Enable Address Sanitizer" OFF)
146120
if (ENABLE_ASAN)
147121
message("Address Sanitizer is enabled.")
148122
if (MSVC)
149-
# MSVC ships AddressSanitizer; it requires Visual Studio 2019 16.9 or
150-
# newer (MSVC_VERSION >= 1928). Only the address sanitizer is available
151-
# (there is no UndefinedBehaviorSanitizer for MSVC).
152123
if (MSVC_VERSION LESS 1928)
153124
message(FATAL_ERROR
154125
"ENABLE_ASAN requires MSVC 19.28+ (Visual Studio 2019 16.9); "
155126
"detected MSVC_VERSION=${MSVC_VERSION}.")
156127
endif ()
157-
# /fsanitize=address is incompatible with the /RTC* runtime checks that
158-
# CMake injects into Debug builds, and with incremental linking. Strip
159-
# /RTC* from the per-config flags and force non-incremental linking.
160-
#
161-
# ASan also needs debug info: /Zi (compile) + /DEBUG (link). Without it
162-
# MSVC emits warning C5072 ("ASAN enabled without debug information
163-
# emission"), which the bundled googletest build promotes to an error
164-
# via /WX in Release builds, and ASan reports lose symbol/line info.
165128
add_compile_options(/fsanitize=address /Zi)
166129
foreach (flagsVar
167130
CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG
@@ -172,6 +135,19 @@ if (ENABLE_ASAN)
172135
elseif (NOT WIN32)
173136
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address,undefined -fno-omit-frame-pointer")
174137

138+
# -flto + libstdc++ <regex> produces spurious ODR-violation reports
139+
# under ASan (globals like __classnames / __collatenames in
140+
# bits/regex.tcc show up once per LTO partition).
141+
#
142+
# -march=native lets gcc autovectorize tight byte-stride loops
143+
# (e.g. Int64Packer::unpack_8values) into AVX2 32-byte gathers
144+
# that overread by up to one SIMD lane past the end of the input
145+
# buffer; the read sits inside ASan's redzone and ASan traps it
146+
# as SEGV. The non-vectorized scalar code is correct, so just
147+
# drop the aggressive flags whenever ASan is on.
148+
string(REGEX REPLACE "(^| )-flto( |$)" " " CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
149+
string(REGEX REPLACE "(^| )-march=native( |$)" " " CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
150+
175151
if (NOT APPLE)
176152
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libasan")
177153
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address,undefined -static-libasan -static-libubsan")
@@ -222,6 +198,10 @@ if (ENABLE_ZLIB)
222198
add_definitions(-DENABLE_GZIP)
223199
endif()
224200

201+
option(ENABLE_SIMD "Enable SIMD acceleration via SIMDe" ON)
202+
message("cmake using: ENABLE_SIMD=${ENABLE_SIMD}")
203+
set(ENABLE_SIMDE ${ENABLE_SIMD} CACHE BOOL "Enable SIMDe (SIMD Everywhere)" FORCE)
204+
225205
option(ENABLE_THREADS "Enable multi-threaded read/write (requires pthreads)" ON)
226206
message("cmake using: ENABLE_THREADS=${ENABLE_THREADS}")
227207

@@ -231,11 +211,11 @@ if (ENABLE_THREADS)
231211
link_libraries(Threads::Threads)
232212
endif()
233213

234-
option(ENABLE_SIMDE "Enable SIMDe (SIMD Everywhere)" OFF)
235-
message("cmake using: ENABLE_SIMDE=${ENABLE_SIMDE}")
214+
option(ENABLE_MEM_STAT "Enable per-module memory allocation statistics" ON)
215+
message("cmake using: ENABLE_MEM_STAT=${ENABLE_MEM_STAT}")
236216

237-
if (ENABLE_SIMDE)
238-
add_definitions(-DENABLE_SIMDE)
217+
if (ENABLE_MEM_STAT)
218+
add_definitions(-DENABLE_MEM_STAT)
239219
endif()
240220

241221
# All libs will be stored here, including libtsfile, compress-encoding lib.
@@ -251,15 +231,12 @@ set(THIRD_PARTY_INCLUDE ${PROJECT_BINARY_DIR}/third_party)
251231

252232
set(SAVED_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
253233
if (MSVC)
254-
# MSVC does not provide a /std:c++11 flag; C++11 is its implicit baseline.
255-
# The lowest explicitly settable standard is /std:c++14. Without this flag,
256-
# the default varies by VS version (VS2017+ defaults to C++14 mode with some
257-
# C++17 extensions), so we pin it explicitly for reproducibility.
258234
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} /W3 /utf-8 /EHsc /bigobj /Zc:__cplusplus /std:c++14")
259235
else ()
260236
set(CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -Wall -std=c++11")
261237
endif ()
262238
add_subdirectory(third_party)
239+
set(CMAKE_CXX_FLAGS "${SAVED_CXX_FLAGS}")
263240

264241
add_subdirectory(src)
265242
if (BUILD_TEST)
@@ -271,5 +248,11 @@ else()
271248
message("BUILD_TEST is OFF, skipping test directory")
272249
endif ()
273250

274-
add_subdirectory(examples)
251+
option(BUILD_EXAMPLES "Build examples (requires Arrow/Parquet)" OFF)
252+
if (BUILD_EXAMPLES)
253+
add_subdirectory(examples)
254+
endif()
275255

256+
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/experiment/CMakeLists.txt")
257+
add_subdirectory(experiment)
258+
endif()

cpp/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ then
149149
cd build/minsizerel
150150
else
151151
echo ""
152-
echo "unknown build type: ${build_type}, valid build types(case insensitive): Debug, Release, RelWithDebInfo, MinSizeRel"
152+
echo "unknow build type: ${build_type}, valid build types(case intensive): Debug, Release, RelWithDebInfo, MinSizeRel"
153153
echo ""
154154
exit 1
155155
fi

cpp/examples/CMakeLists.txt

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,30 @@ message("Running in examples directory")
2222

2323
if (NOT MSVC)
2424
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
25-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
2625
endif ()
2726

28-
# TsFile include dir
27+
# TsFile include dirs
2928
set(SDK_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/../src/)
30-
message("SDK_INCLUDE_DIR: ${SDK_INCLUDE_DIR}")
31-
32-
# TsFile shared object dir
33-
set(SDK_LIB_DIR_RELEASE ${PROJECT_SOURCE_DIR}/../build/Release/lib)
34-
message("SDK_LIB_DIR_RELEASE: ${SDK_LIB_DIR_RELEASE}")
35-
36-
set(SDK_LIB_DIR_DEBUG ${PROJECT_SOURCE_DIR}/../build/Debug/lib)
37-
message("SDK_LIB_DIR_DEBUG: ${SDK_LIB_DIR_DEBUG}")
38-
include_directories(${PROJECT_SOURCE_DIR}/../third_party/antlr4-cpp-runtime-4/runtime/src)
39-
40-
set(BUILD_TYPE "Release")
4129
include_directories(${SDK_INCLUDE_DIR})
30+
include_directories(${PROJECT_SOURCE_DIR}/../third_party/antlr4-cpp-runtime-4/runtime/src)
4231

43-
if (DEFINED TSFILE_OPTIMIZATION_FLAGS AND NOT "${TSFILE_OPTIMIZATION_FLAGS}" STREQUAL "")
44-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TSFILE_OPTIMIZATION_FLAGS}")
45-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TSFILE_OPTIMIZATION_FLAGS}")
46-
message("examples using: TSFILE_OPTIMIZATION_FLAGS=${TSFILE_OPTIMIZATION_FLAGS}")
47-
else ()
48-
message("examples using: TSFILE_OPTIMIZATION_FLAGS=<inherit>")
49-
if (NOT MSVC)
50-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
51-
endif ()
32+
if (NOT MSVC)
33+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -DNDEBUG")
5234
endif ()
5335

36+
# Arrow + Parquet are required (for bench_read)
37+
if(APPLE)
38+
list(APPEND CMAKE_PREFIX_PATH
39+
"/opt/homebrew/opt/apache-arrow/lib/cmake"
40+
"/usr/local/opt/apache-arrow/lib/cmake")
41+
endif()
42+
find_package(Arrow CONFIG REQUIRED)
43+
find_package(Parquet CONFIG REQUIRED)
44+
5445
add_subdirectory(cpp_examples)
5546
add_subdirectory(c_examples)
5647

5748
add_executable(examples examples.cc)
5849
target_link_libraries(examples cpp_examples_obj c_examples_obj)
59-
target_link_libraries(examples tsfile)
50+
find_package(Threads REQUIRED)
51+
target_link_libraries(examples tsfile Arrow::arrow_shared Parquet::parquet_shared Threads::Threads)

cpp/examples/README.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,6 @@ target_link_libraries(your_target ${TSFILE_LIB})
5555

5656
Note: Set ${SDK_LIB} to your TSFile library directory.
5757

58-
### Optional Optimization Control
59-
60-
By default, `tsfile-cpp` inherits optimization settings from the caller/toolchain.
61-
If you want to override optimization for `tsfile-cpp`, pass
62-
`TSFILE_OPTIMIZATION_FLAGS` during configure:
63-
64-
Leave `TSFILE_OPTIMIZATION_FLAGS` empty to keep inherited behavior.
65-
6658
## 3. Implementation Examples
6759

6860
### Directory Structure

cpp/examples/cpp_examples/CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,17 @@ under the License.
1818
]]
1919

2020
message("Running in examples/cpp_examples directory")
21-
aux_source_directory(. cpp_SRC_LIST)
22-
add_library(cpp_examples_obj OBJECT ${cpp_SRC_LIST})
21+
22+
add_library(cpp_examples_obj OBJECT
23+
demo_read.cpp
24+
demo_write.cpp
25+
bench_read.cpp)
26+
27+
# bench_read.cpp requires C++17 (TsFile headers use [[maybe_unused]])
28+
# and Arrow/Parquet headers. Both are provided by the parent scope.
29+
set_target_properties(cpp_examples_obj PROPERTIES
30+
CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
31+
target_compile_options(cpp_examples_obj PRIVATE -std=c++17)
32+
target_link_libraries(cpp_examples_obj PRIVATE
33+
Arrow::arrow_shared
34+
Parquet::parquet_shared)

0 commit comments

Comments
 (0)