Skip to content

Commit 5eaa3d9

Browse files
authored
feat: modify api in LuceneGlobalIndexReader (alibaba#95)
1 parent 20265b7 commit 5eaa3d9

5 files changed

Lines changed: 45 additions & 3 deletions

File tree

include/paimon/global_index/global_index_reader.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@ namespace paimon {
3838
class PAIMON_EXPORT GlobalIndexReader : public FunctionVisitor<std::shared_ptr<GlobalIndexResult>> {
3939
public:
4040
/// VisitVectorSearch performs approximate vector similarity search.
41-
/// @note `VisitVectorSearch` is thread-safe (not coroutine-safe) while other `VisitXXX` is not
42-
/// thread-safe.
4341
/// @warning `VisitVectorSearch` may return error status when it is incorrectly invoked (e.g.,
4442
/// BitmapGlobalIndexReader call `VisitVectorSearch`).
4543
virtual Result<std::shared_ptr<VectorSearchGlobalIndexResult>> VisitVectorSearch(
4644
const std::shared_ptr<VectorSearch>& vector_search) = 0;
45+
46+
/// @return true if the reader is thread-safe; false otherwise.
47+
virtual bool IsThreadSafe() const = 0;
48+
49+
/// @return An identifier representing the index type. (e.g., "bitmap", "lumina").
50+
virtual std::string GetIndexType() const = 0;
4751
};
4852

4953
} // namespace paimon

src/paimon/common/global_index/bitmap/bitmap_global_index.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Result<std::shared_ptr<GlobalIndexReader>> BitmapGlobalIndex::CreateReader(
4949
-> Result<std::shared_ptr<GlobalIndexResult>> {
5050
return ToGlobalIndexResult(range_end, result);
5151
};
52-
return std::make_shared<FileIndexReaderWrapper>(reader, transform);
52+
return std::make_shared<BitmapGlobalIndexReader>(reader, transform);
5353
}
5454

5555
Result<std::shared_ptr<GlobalIndexResult>> BitmapGlobalIndex::ToGlobalIndexResult(

src/paimon/common/global_index/bitmap/bitmap_global_index.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <vector>
2222

2323
#include "paimon/common/file_index/bitmap/bitmap_file_index.h"
24+
#include "paimon/common/global_index/wrap/file_index_reader_wrapper.h"
2425
#include "paimon/global_index/global_indexer.h"
2526

2627
namespace paimon {
@@ -46,4 +47,22 @@ class BitmapGlobalIndex : public GlobalIndexer {
4647
std::shared_ptr<BitmapFileIndex> index_;
4748
};
4849

50+
class BitmapGlobalIndexReader : public FileIndexReaderWrapper {
51+
public:
52+
BitmapGlobalIndexReader(const std::shared_ptr<FileIndexReader>& reader,
53+
const std::function<Result<std::shared_ptr<GlobalIndexResult>>(
54+
const std::shared_ptr<FileIndexResult>&)>& transform)
55+
: FileIndexReaderWrapper(reader, transform) {}
56+
57+
static inline const char kIdentifier[] = "bitmap";
58+
59+
bool IsThreadSafe() const override {
60+
return false;
61+
}
62+
63+
std::string GetIndexType() const override {
64+
return kIdentifier;
65+
}
66+
};
67+
4968
} // namespace paimon

src/paimon/global_index/lucene/lucene_global_index.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ class LuceneGlobalIndexReader : public GlobalIndexReader {
167167
Result<std::shared_ptr<VectorSearchGlobalIndexResult>> VisitFullTextSearch(
168168
const std::shared_ptr<FullTextSearch>& full_text_search);
169169

170+
bool IsThreadSafe() const override {
171+
return false;
172+
}
173+
174+
std::string GetIndexType() const override {
175+
return kIdentifier;
176+
}
177+
170178
private:
171179
LuceneGlobalIndexReader(const std::wstring& wfield_name, int64_t range_end,
172180
const Lucene::IndexSearcherPtr& searcher)

src/paimon/global_index/lumina/lumina_global_index.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "paimon/global_index/bitmap_global_index_result.h"
2929
#include "paimon/global_index/global_indexer.h"
3030
#include "paimon/global_index/lumina/lumina_memory_pool.h"
31+
#include "paimon/global_index/lumina/lumina_utils.h"
3132

3233
namespace paimon::lumina {
3334
/// @note When enabling the lumina global index in `paimon-cpp`, all configuration parameters
@@ -122,6 +123,8 @@ class LuminaIndexReader : public GlobalIndexReader {
122123
[[maybe_unused]] auto status = searcher_->Close();
123124
}
124125

126+
/// @note `VisitVectorSearch` is thread-safe (not coroutine-safe) while other `VisitXXX` is not
127+
/// thread-safe.
125128
Result<std::shared_ptr<VectorSearchGlobalIndexResult>> VisitVectorSearch(
126129
const std::shared_ptr<VectorSearch>& vector_search) override;
127130

@@ -180,6 +183,14 @@ class LuminaIndexReader : public GlobalIndexReader {
180183
return BitmapGlobalIndexResult::FromRanges({Range(0, range_end_)});
181184
}
182185

186+
bool IsThreadSafe() const override {
187+
return true;
188+
}
189+
190+
std::string GetIndexType() const override {
191+
return LuminaDefines::kIdentifier;
192+
}
193+
183194
static Result<LuminaIndexReader::IndexInfo> GetIndexInfo(const GlobalIndexIOMeta& io_meta);
184195

185196
private:

0 commit comments

Comments
 (0)