Repository navigation
feat(file-index): support file-local search with PK+DV filtering #372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a23b7e9
405e989
18cb3b0
0bcceba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "paimon/file_index/file_index_result.h" | ||
| #include "paimon/result.h" | ||
| #include "paimon/utils/roaring_bitmap32.h" | ||
| #include "paimon/visibility.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| /// File-local vector search result. Scores correspond to row positions in ascending order. | ||
| class PAIMON_EXPORT ScoredFileIndexResult : public FileIndexResult { | ||
| public: | ||
| static Result<std::shared_ptr<ScoredFileIndexResult>> Create(RoaringBitmap32&& row_positions, | ||
| std::vector<float>&& scores); | ||
|
|
||
| bool IsEmpty() const { | ||
| return row_positions_.IsEmpty(); | ||
| } | ||
|
|
||
| Result<bool> IsRemain() const override; | ||
|
|
||
| const RoaringBitmap32& GetRowPositions() const { | ||
| return row_positions_; | ||
| } | ||
|
|
||
| const std::vector<float>& GetScores() const { | ||
| return scores_; | ||
| } | ||
|
|
||
| std::string ToString() const override; | ||
|
|
||
| private: | ||
| ScoredFileIndexResult(RoaringBitmap32&& row_positions, std::vector<float>&& scores); | ||
|
|
||
| RoaringBitmap32 row_positions_; | ||
| std::vector<float> scores_; | ||
| }; | ||
|
|
||
| } // namespace paimon |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,11 +37,13 @@ | |
| namespace paimon { | ||
| class Catalog; | ||
| class Executor; | ||
| struct FullTextSearch; | ||
| class FormatTable; | ||
| class MemoryPool; | ||
| class Predicate; | ||
| class FileSystem; | ||
| class RealtimeContext; | ||
| struct VectorSearch; | ||
|
|
||
| /// `ReadContext` is some configuration for read operations. | ||
| /// | ||
|
|
@@ -53,10 +55,13 @@ class PAIMON_EXPORT ReadContext { | |
| ReadContext(const std::string& path, const std::string& branch, | ||
| const std::vector<std::string>& read_field_names, | ||
| const std::vector<int32_t>& read_field_ids, | ||
| const std::shared_ptr<Predicate>& predicate, bool enable_predicate_filter, | ||
| bool enable_prefetch, bool enable_late_materializing, uint32_t prefetch_batch_count, | ||
| uint32_t prefetch_max_parallel_num, bool enable_multi_thread_row_to_batch, | ||
| uint32_t row_to_batch_thread_number, const std::optional<std::string>& table_schema, | ||
| const std::shared_ptr<Predicate>& predicate, | ||
| const std::shared_ptr<VectorSearch>& vector_search, | ||
| const std::shared_ptr<FullTextSearch>& full_text_search, | ||
| bool enable_predicate_filter, bool enable_prefetch, bool enable_late_materializing, | ||
| uint32_t prefetch_batch_count, uint32_t prefetch_max_parallel_num, | ||
| bool enable_multi_thread_row_to_batch, uint32_t row_to_batch_thread_number, | ||
| const std::optional<std::string>& table_schema, | ||
| const std::shared_ptr<MemoryPool>& memory_pool, | ||
| const std::shared_ptr<Executor>& executor, | ||
| const std::shared_ptr<FileSystem>& specific_file_system, | ||
|
|
@@ -96,6 +101,18 @@ class PAIMON_EXPORT ReadContext { | |
| return predicate_; | ||
| } | ||
|
|
||
| const std::shared_ptr<VectorSearch>& GetVectorSearch() const { | ||
| return vector_search_; | ||
| } | ||
|
|
||
| const std::shared_ptr<FullTextSearch>& GetFullTextSearch() const { | ||
| return full_text_search_; | ||
| } | ||
|
|
||
| bool HasFileIndexSearch() const { | ||
| return vector_search_ != nullptr || full_text_search_ != nullptr; | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename it. |
||
| bool EnablePredicateFilter() const { | ||
| return enable_predicate_filter_; | ||
| } | ||
|
|
@@ -179,6 +196,8 @@ class PAIMON_EXPORT ReadContext { | |
| std::vector<std::string> read_field_names_; | ||
| std::vector<int32_t> read_field_ids_; | ||
| std::shared_ptr<Predicate> predicate_; | ||
| std::shared_ptr<VectorSearch> vector_search_; | ||
| std::shared_ptr<FullTextSearch> full_text_search_; | ||
| bool enable_predicate_filter_; | ||
| bool enable_prefetch_; | ||
| bool enable_late_materializing_; | ||
|
|
@@ -320,6 +339,18 @@ class PAIMON_EXPORT ReadContextBuilder { | |
| /// @return Reference to this builder for method chaining. | ||
| ReadContextBuilder& SetPredicate(const std::shared_ptr<Predicate>& predicate); | ||
|
|
||
| /// Configure file-local vector search. The limit is applied independently to every data file. | ||
| /// Vector search and full-text search are mutually exclusive. | ||
| /// @param vector_search Vector search request, or nullptr to clear it. | ||
| /// @return Reference to this builder for method chaining. | ||
| ReadContextBuilder& SetVectorSearch(const std::shared_ptr<VectorSearch>& vector_search); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although this is currently file-local, please add a TODO to track promoting it to read-level granularity in the future.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add TODO for predicate and search support. |
||
| /// Configure file-local full-text search. The limit is applied independently to every data | ||
| /// file. Full-text search and vector search are mutually exclusive. | ||
| /// @param full_text_search Full-text search request, or nullptr to clear it. | ||
| /// @return Reference to this builder for method chaining. | ||
| ReadContextBuilder& SetFullTextSearch(const std::shared_ptr<FullTextSearch>& full_text_search); | ||
|
|
||
| /// Whether to perform precise filtering according to predicates for data read from format | ||
| /// reader. | ||
| /// @param enabled Whether to enable precise filtering (default: false) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -73,6 +73,7 @@ set(PAIMON_COMMON_SRCS | |
| common/file_index/file_index_format.cpp | ||
| common/file_index/file_index_reader.cpp | ||
| common/file_index/file_index_result.cpp | ||
| common/file_index/scored_file_index_result.cpp | ||
| common/format/column_stats.cpp | ||
| common/format/file_format_factory.cpp | ||
| common/fs/file_system.cpp | ||
|
|
@@ -81,7 +82,6 @@ set(PAIMON_COMMON_SRCS | |
| common/fs/file_system_factory.cpp | ||
| common/global_index/union_global_index_reader.cpp | ||
| common/global_index/offset_global_index_reader.cpp | ||
| common/global_index/complete_index_score_batch_reader.cpp | ||
| common/global_index/bitmap_scored_global_index_result.cpp | ||
| common/global_index/bitmap_global_index_result.cpp | ||
| common/global_index/global_index_result.cpp | ||
|
|
@@ -138,6 +138,8 @@ set(PAIMON_COMMON_SRCS | |
| common/predicate/predicate_utils.cpp | ||
| common/predicate/starts_with.cpp | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add an inte write and read case. |
||
| common/reader/batch_reader.cpp | ||
| common/reader/complete_index_score_batch_reader.cpp | ||
| common/reader/complete_index_score_file_batch_reader.cpp | ||
| common/reader/concat_batch_reader.cpp | ||
| common/reader/late_materializing_file_batch_reader.cpp | ||
| common/reader/data_file_reader_factory.cpp | ||
|
|
@@ -593,6 +595,7 @@ if(PAIMON_BUILD_TESTS) | |
| common/file_index/file_indexer_factory_test.cpp | ||
| common/file_index/file_index_result_test.cpp | ||
| common/file_index/file_index_reader_test.cpp | ||
| common/file_index/scored_file_index_result_test.cpp | ||
| common/file_index/file_index_format_test.cpp | ||
| common/file_index/empty/empty_file_index_reader_test.cpp | ||
| common/file_index/bitmap/bitmap_index_result_test.cpp | ||
|
|
@@ -608,7 +611,6 @@ if(PAIMON_BUILD_TESTS) | |
| common/file_index/rangebitmap/range_bitmap_type_adapter_test.cpp | ||
| common/file_index/bloomfilter/bloom_filter_file_index_test.cpp | ||
| common/file_index/bloomfilter/fast_hash_test.cpp | ||
| common/global_index/complete_index_score_batch_reader_test.cpp | ||
| common/global_index/global_index_result_test.cpp | ||
| common/global_index/global_index_utils_test.cpp | ||
| common/global_index/offset_global_index_reader_test.cpp | ||
|
|
@@ -649,6 +651,7 @@ if(PAIMON_BUILD_TESTS) | |
| common/predicate/predicate_test.cpp | ||
| common/predicate/predicate_utils_test.cpp | ||
| common/predicate/predicate_validator_test.cpp | ||
| common/reader/complete_index_score_batch_reader_test.cpp | ||
| common/reader/concat_batch_reader_test.cpp | ||
| common/reader/data_file_reader_factory_test.cpp | ||
| common/reader/late_materializing_file_batch_reader_test.cpp | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mv
VisitVectorSearchandVisitFullTextSearchtoFunctionVisitor?