Skip to content

Commit 6100eb6

Browse files
authored
Merge branch 'main' into feature/columnar-row-ref
2 parents c131950 + 17ab0c3 commit 6100eb6

56 files changed

Lines changed: 2572 additions & 708 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.

CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,22 @@ if(PAIMON_ENABLE_LUMINA)
290290
DESTINATION ${CMAKE_INSTALL_LIBDIR})
291291
endif()
292292
293+
if(PAIMON_ENABLE_LUCENE)
294+
set(PAIMON_DICT_DEST "share/paimon/dict")
295+
296+
install(DIRECTORY ${JIEBA_DICT_DIR}/
297+
DESTINATION ${PAIMON_DICT_DEST}
298+
FILES_MATCHING
299+
PATTERN "jieba.dict.utf8"
300+
PATTERN "hmm_model.utf8"
301+
PATTERN "idf.utf8"
302+
PATTERN "stop_words.utf8"
303+
PATTERN "user.dict.utf8"
304+
PATTERN "pos_dict"
305+
PATTERN ".git*" EXCLUDE
306+
PATTERN "*.md" EXCLUDE)
307+
endif()
308+
293309
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
294310
DESTINATION "include"
295311
FILES_MATCHING
@@ -389,7 +405,6 @@ if(PAIMON_BUILD_TESTS)
389405
list(APPEND TEST_STATIC_LINK_LIBS paimon_lucene_index_shared)
390406
list(APPEND TEST_STATIC_LINK_LIBS "-Wl,--as-needed")
391407
endif()
392-
393408
endif()
394409
395410
include(CMakePackageConfigHelpers)

cmake_modules/ThirdpartyToolchain.cmake

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ macro(build_lucene)
322322
set(LUCENE_INCLUDE_DIR "${LUCENE_PREFIX}/include")
323323
# The include directory must exist before it is referenced by a target.
324324
file(MAKE_DIRECTORY "${LUCENE_INCLUDE_DIR}")
325-
include_directories(SYSTEM ${LUCENE_INCLUDE_DIR} ${BOOST_INCLUDE_DIR}
326-
${BOOST_EXTRA_INCLUDE_DIR})
325+
include_directories(SYSTEM ${LUCENE_INCLUDE_DIR} ${BOOST_INCLUDE_DIR})
327326
add_library(lucene INTERFACE IMPORTED)
328327
target_include_directories(lucene SYSTEM INTERFACE "${LUCENE_INCLUDE_DIR}")
329328
target_compile_options(lucene INTERFACE -pthread)
@@ -343,6 +342,43 @@ macro(build_lucene)
343342
add_dependencies(lucene lucene_ep)
344343
endmacro()
345344

345+
macro(build_jieba)
346+
message(STATUS "Building jieba from source")
347+
set(JIEBA_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/jieba_ep-prefix")
348+
set(JIEBA_INSTALL "${CMAKE_CURRENT_BINARY_DIR}/jieba_ep-install")
349+
set(JIEBA_INCLUDE_DIR "${JIEBA_INSTALL}/include")
350+
set(JIEBA_DICT_DIR "${JIEBA_INSTALL}/dict")
351+
file(MAKE_DIRECTORY ${JIEBA_INCLUDE_DIR})
352+
file(MAKE_DIRECTORY ${JIEBA_DICT_DIR})
353+
354+
set(JIEBA_CMAKE_ARGS
355+
${EP_COMMON_CMAKE_ARGS} "-DENABLE_TEST=OFF" "-DCPPJIEBA_TOP_LEVEL_PROJECT=OFF"
356+
"-DCMAKE_INSTALL_PREFIX=${JIEBA_INSTALL}")
357+
358+
set(PATCH_FILE "${CMAKE_CURRENT_LIST_DIR}/jieba.diff")
359+
externalproject_add(jieba_ep
360+
${EP_COMMON_OPTIONS}
361+
GIT_REPOSITORY https://github.com/yanyiwu/cppjieba.git
362+
GIT_TAG ${PAIMON_JIEBA_BUILD_VERSION}
363+
GIT_SHALLOW FALSE
364+
GIT_PROGRESS TRUE
365+
GIT_SUBMODULES_RECURSE TRUE
366+
CMAKE_ARGS ${JIEBA_CMAKE_ARGS}
367+
LOG_PATCH ON
368+
PATCH_COMMAND ${CMAKE_COMMAND} -E chdir <SOURCE_DIR> bash -c
369+
"[ -f .patched ] && echo '<SOURCE_DIR> patch already applied, ignore...' || patch -s -N -p1 -i '${PATCH_FILE}' && touch .patched"
370+
INSTALL_COMMAND bash -c
371+
"cp -r ${JIEBA_PREFIX}/src/jieba_ep/include/* ${JIEBA_INSTALL}/include/ && cp -r ${JIEBA_PREFIX}/src/jieba_ep/dict/* ${JIEBA_INSTALL}/dict/ && cp -r ${JIEBA_PREFIX}/src/jieba_ep/deps/limonp/include/* ${JIEBA_INSTALL}/include/"
372+
)
373+
374+
# The include directory must exist before it is referenced by a target.
375+
include_directories(SYSTEM ${JIEBA_INCLUDE_DIR} ${JIEBA_DICT_DIR})
376+
add_library(jieba INTERFACE IMPORTED)
377+
target_include_directories(jieba SYSTEM
378+
INTERFACE "${JIEBA_INCLUDE_DIR} ${JIEBA_DICT_DIR}")
379+
add_dependencies(jieba jieba_ep)
380+
endmacro()
381+
346382
macro(build_rapidjson)
347383
message(STATUS "Building RapidJSON from source")
348384
set(RAPIDJSON_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/rapidjson_ep-install")
@@ -1272,4 +1308,5 @@ endif()
12721308
if(PAIMON_ENABLE_LUCENE)
12731309
build_boost()
12741310
build_lucene()
1311+
build_jieba()
12751312
endif()

cmake_modules/jieba.diff

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
diff --git a/include/cppjieba/KeywordExtractor.hpp b/include/cppjieba/KeywordExtractor.hpp
2+
index 24b2c40..c7c6a94 100644
3+
--- a/include/cppjieba/KeywordExtractor.hpp
4+
+++ b/include/cppjieba/KeywordExtractor.hpp
5+
@@ -89,6 +89,11 @@ class KeywordExtractor {
6+
std::partial_sort(keywords.begin(), keywords.begin() + topN, keywords.end(), Compare);
7+
keywords.resize(topN);
8+
}
9+
+
10+
+ const std::unordered_set<std::string>& GetStopWords() const {
11+
+ return stopWords_;
12+
+ }
13+
+
14+
private:
15+
void LoadIdfDict(const std::string& idfPath) {
16+
std::ifstream ifs(idfPath.c_str());

include/paimon/defs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ struct PAIMON_EXPORT Options {
287287
/// "global-index.external-path" - Global index root directory, if not set, the global index
288288
/// files will be stored under the index directory.
289289
static const char GLOBAL_INDEX_EXTERNAL_PATH[];
290+
/// "scan.tag-name" - Optional tag name used in case of "from-snapshot" scan mode.
291+
static const char SCAN_TAG_NAME[];
290292
};
291293

292294
static constexpr int64_t BATCH_WRITE_COMMIT_IDENTIFIER = std::numeric_limits<int64_t>::max();

include/paimon/read_context.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class PAIMON_EXPORT ReadContext {
5353
const std::shared_ptr<Executor>& executor,
5454
const std::shared_ptr<FileSystem>& specific_file_system,
5555
const std::map<std::string, std::string>& fs_scheme_to_identifier_map,
56-
const std::map<std::string, std::string>& options, bool enable_prefetch_cache,
57-
const CacheConfig& cache_config);
56+
const std::map<std::string, std::string>& options,
57+
PrefetchCacheMode prefetch_cache_mode, const CacheConfig& cache_config);
5858
~ReadContext();
5959

6060
const std::string& GetPath() const {
@@ -116,8 +116,8 @@ class PAIMON_EXPORT ReadContext {
116116
return specific_file_system_;
117117
}
118118

119-
bool EnablePrefetchCache() const {
120-
return enable_prefetch_cache_;
119+
PrefetchCacheMode GetPrefetchCacheMode() const {
120+
return prefetch_cache_mode_;
121121
}
122122

123123
const CacheConfig& GetCacheConfig() const {
@@ -142,7 +142,7 @@ class PAIMON_EXPORT ReadContext {
142142
std::shared_ptr<FileSystem> specific_file_system_;
143143
std::map<std::string, std::string> fs_scheme_to_identifier_map_;
144144
std::map<std::string, std::string> options_;
145-
bool enable_prefetch_cache_;
145+
PrefetchCacheMode prefetch_cache_mode_;
146146
CacheConfig cache_config_;
147147
};
148148

@@ -226,13 +226,13 @@ class PAIMON_EXPORT ReadContextBuilder {
226226
/// @return Reference to this builder for method chaining.
227227
ReadContextBuilder& EnablePrefetch(bool enabled);
228228

229-
/// Enable or disable prefetch cache for read operations.
229+
/// Set prefetch cache mode for read operations.
230230
///
231-
/// When enabled, a prefetch cache is used to prebuffer data ranges before they are needed,
231+
/// A prefetch cache is used to prebuffer data ranges before they are needed,
232232
/// which can improve read performance by reducing redundant I/O operations.
233-
/// @param enabled Whether to enable prefetch cache (default: true)
233+
/// @param mode (default: PrefetchCacheMode::ALWAYS)
234234
/// @return Reference to this builder for method chaining.
235-
ReadContextBuilder& EnablePrefetchCache(bool enabled);
235+
ReadContextBuilder& SetPrefetchCacheMode(PrefetchCacheMode mode);
236236

237237
/// Set the cache configuration for prefetch read operations.
238238
///

include/paimon/utils/read_ahead_cache.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@
3434

3535
namespace paimon {
3636

37+
/// PrefetchCacheMode
38+
/// Cache prefetch switch modes.
39+
/// Controls whether to enable cache prefetching under different circumstances, such as queries with
40+
/// predicates or bitmap indexes.
41+
///
42+
/// - ALWAYS: Enable cache in all scenarios.
43+
/// - EXCLUDE_PREDICATE: Disable cache when query has predicates.
44+
/// - EXCLUDE_BITMAP: Disable cache when using bitmap index.
45+
/// - EXCLUDE_BITMAP_OR_PREDICATE: Disable cache if query has predicates or bitmap index.
46+
/// - NEVER: Always disable cache.
47+
enum class PAIMON_EXPORT PrefetchCacheMode {
48+
ALWAYS = 1,
49+
EXCLUDE_PREDICATE = 2,
50+
EXCLUDE_BITMAP = 3,
51+
EXCLUDE_BITMAP_OR_PREDICATE = 4,
52+
NEVER = 5
53+
};
54+
3755
/// Configuration parameters for the read-ahead cache behavior.
3856
///
3957
/// This struct controls various limits and prefetching strategies used by

src/paimon/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ set(PAIMON_CORE_SRCS
266266
core/table/source/table_read.cpp
267267
core/table/source/table_scan.cpp
268268
core/table/source/data_evolution_batch_scan.cpp
269+
core/tag/tag.cpp
269270
core/utils/field_mapping.cpp
270271
core/utils/fields_comparator.cpp
271272
core/utils/file_store_path_factory.cpp
@@ -274,7 +275,8 @@ set(PAIMON_CORE_SRCS
274275
core/utils/partition_path_utils.cpp
275276
core/utils/primary_key_table_utils.cpp
276277
core/utils/snapshot_manager.cpp
277-
core/utils/special_field_ids.cpp)
278+
core/utils/special_field_ids.cpp
279+
core/utils/tag_manager.cpp)
278280

279281
add_paimon_lib(paimon
280282
SOURCES
@@ -565,6 +567,7 @@ if(PAIMON_BUILD_TESTS)
565567
core/table/source/split_generator_test.cpp
566568
core/table/source/startup_mode_test.cpp
567569
core/table/source/table_scan_test.cpp
570+
core/tag/tag_test.cpp
568571
core/utils/branch_manager_test.cpp
569572
core/utils/field_mapping_test.cpp
570573
core/utils/fields_comparator_test.cpp
@@ -574,6 +577,7 @@ if(PAIMON_BUILD_TESTS)
574577
core/utils/offset_row_test.cpp
575578
core/utils/partition_path_utils_test.cpp
576579
core/utils/snapshot_manager_test.cpp
580+
core/utils/tag_manager_test.cpp
577581
core/utils/primary_key_table_utils_test.cpp
578582
core/utils/index_file_path_factories_test.cpp
579583
STATIC_LINK_LIBS

src/paimon/common/defs.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,5 @@ const char Options::PARTITION_GENERATE_LEGACY_NAME[] = "partition.legacy-name";
8181
const char Options::BLOB_AS_DESCRIPTOR[] = "blob-as-descriptor";
8282
const char Options::GLOBAL_INDEX_ENABLED[] = "global-index.enabled";
8383
const char Options::GLOBAL_INDEX_EXTERNAL_PATH[] = "global-index.external-path";
84+
const char Options::SCAN_TAG_NAME[] = "scan.tag-name";
8485
} // namespace paimon

src/paimon/common/file_index/bitmap/apply_bitmap_index_batch_reader_test.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,14 @@ class ApplyBitmapIndexBatchReaderTest : public ::testing::Test,
8888
bool enable_prefetch = GetParam();
8989
if (enable_prefetch) {
9090
MockFormatReaderBuilder reader_builder(data, target_type_, batch_size);
91-
ASSERT_OK_AND_ASSIGN(file_batch_reader,
92-
PrefetchFileBatchReaderImpl::Create(
93-
/*data_file_path=*/"DUMMY", &reader_builder, fs_,
94-
prefetch_batch_count, batch_size, prefetch_batch_count * 2,
95-
/*enable_adaptive_prefetch_strategy=*/false, executor_,
96-
/*initialize_read_ranges=*/true,
97-
/*enable_prefetch_cache=*/true, CacheConfig(), pool_));
91+
ASSERT_OK_AND_ASSIGN(
92+
file_batch_reader,
93+
PrefetchFileBatchReaderImpl::Create(
94+
/*data_file_path=*/"DUMMY", &reader_builder, fs_, prefetch_batch_count,
95+
batch_size, prefetch_batch_count * 2,
96+
/*enable_adaptive_prefetch_strategy=*/false, executor_,
97+
/*initialize_read_ranges=*/true,
98+
/*prefetch_cache_mode=*/PrefetchCacheMode::ALWAYS, CacheConfig(), pool_));
9899
} else {
99100
file_batch_reader =
100101
std::make_unique<MockFileBatchReader>(data, target_type_, batch_size);

src/paimon/common/reader/prefetch_file_batch_reader_impl.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Result<std::unique_ptr<PrefetchFileBatchReaderImpl>> PrefetchFileBatchReaderImpl
4545
const std::shared_ptr<FileSystem>& fs, uint32_t prefetch_max_parallel_num, int32_t batch_size,
4646
uint32_t prefetch_batch_count, bool enable_adaptive_prefetch_strategy,
4747
const std::shared_ptr<Executor>& executor, bool initialize_read_ranges,
48-
bool enable_prefetch_cache, const CacheConfig& cache_config,
48+
PrefetchCacheMode prefetch_cache_mode, const CacheConfig& cache_config,
4949
const std::shared_ptr<MemoryPool>& pool) {
5050
if (prefetch_max_parallel_num == 0) {
5151
return Status::Invalid("prefetch max parallel num should be greater than 0.");
@@ -67,7 +67,7 @@ Result<std::unique_ptr<PrefetchFileBatchReaderImpl>> PrefetchFileBatchReaderImpl
6767
}
6868

6969
std::shared_ptr<ReadAheadCache> cache;
70-
if (enable_prefetch_cache) {
70+
if (prefetch_cache_mode != PrefetchCacheMode::NEVER) {
7171
PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<InputStream> input_stream, fs->Open(data_file_path));
7272
cache = std::make_shared<ReadAheadCache>(input_stream, cache_config, pool);
7373
}
@@ -102,9 +102,9 @@ Result<std::unique_ptr<PrefetchFileBatchReaderImpl>> PrefetchFileBatchReaderImpl
102102
}
103103
uint32_t prefetch_queue_capacity = prefetch_batch_count / readers.size();
104104

105-
auto reader = std::unique_ptr<PrefetchFileBatchReaderImpl>(
106-
new PrefetchFileBatchReaderImpl(readers, batch_size, prefetch_queue_capacity,
107-
enable_adaptive_prefetch_strategy, executor, cache));
105+
auto reader = std::unique_ptr<PrefetchFileBatchReaderImpl>(new PrefetchFileBatchReaderImpl(
106+
readers, batch_size, prefetch_queue_capacity, enable_adaptive_prefetch_strategy, executor,
107+
cache, prefetch_cache_mode));
108108
if (initialize_read_ranges) {
109109
// normally initialize read ranges should be false, as set read schema will refresh read
110110
// ranges, and set read schema will always be called before read.
@@ -116,11 +116,13 @@ Result<std::unique_ptr<PrefetchFileBatchReaderImpl>> PrefetchFileBatchReaderImpl
116116
PrefetchFileBatchReaderImpl::PrefetchFileBatchReaderImpl(
117117
const std::vector<std::shared_ptr<PrefetchFileBatchReader>>& readers, int32_t batch_size,
118118
uint32_t prefetch_queue_capacity, bool enable_adaptive_prefetch_strategy,
119-
const std::shared_ptr<Executor>& executor, const std::shared_ptr<ReadAheadCache>& cache)
119+
const std::shared_ptr<Executor>& executor, const std::shared_ptr<ReadAheadCache>& cache,
120+
PrefetchCacheMode cache_mode)
120121
: readers_(std::move(readers)),
121122
batch_size_(batch_size),
122123
executor_(executor),
123124
cache_(cache),
125+
cache_mode_(cache_mode),
124126
prefetch_queue_capacity_(prefetch_queue_capacity),
125127
enable_adaptive_prefetch_strategy_(enable_adaptive_prefetch_strategy) {
126128
for (size_t i = 0; i < readers_.size(); i++) {
@@ -146,6 +148,7 @@ Status PrefetchFileBatchReaderImpl::SetReadSchema(
146148
PAIMON_RETURN_NOT_OK(reader->SetReadSchema(c_schema.get(), predicate, selection_bitmap));
147149
}
148150
selection_bitmap_ = selection_bitmap;
151+
predicate_ = predicate;
149152
return RefreshReadRanges();
150153
}
151154

@@ -275,10 +278,28 @@ Status PrefetchFileBatchReaderImpl::CleanUp() {
275278
return Status::OK();
276279
}
277280

281+
bool PrefetchFileBatchReaderImpl::NeedInitCache() const {
282+
switch (cache_mode_) {
283+
case PrefetchCacheMode::NEVER:
284+
return false;
285+
case PrefetchCacheMode::EXCLUDE_PREDICATE:
286+
return predicate_ == nullptr;
287+
case PrefetchCacheMode::EXCLUDE_BITMAP:
288+
return selection_bitmap_ == std::nullopt;
289+
case PrefetchCacheMode::EXCLUDE_BITMAP_OR_PREDICATE:
290+
return predicate_ == nullptr && selection_bitmap_ == std::nullopt;
291+
case PrefetchCacheMode::ALWAYS:
292+
return true;
293+
default:
294+
assert(false);
295+
return true;
296+
}
297+
}
298+
278299
void PrefetchFileBatchReaderImpl::Workloop() {
279300
std::vector<std::future<void>> futures;
280301
futures.resize(readers_.size());
281-
if (cache_) {
302+
if (cache_ && NeedInitCache()) {
282303
auto read_ranges = readers_[0]->PreBufferRange();
283304
if (read_ranges.ok()) {
284305
std::vector<ByteRange> ranges;
@@ -288,11 +309,9 @@ void PrefetchFileBatchReaderImpl::Workloop() {
288309
auto s = cache_->Init(std::move(ranges));
289310
if (!s.ok()) {
290311
SetReadStatus(s);
291-
return;
292312
}
293313
} else {
294314
SetReadStatus(read_ranges.status());
295-
return;
296315
}
297316
}
298317

0 commit comments

Comments
 (0)