Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.9k
[improve](array-funcs) accelerate arrays_overlap by inverted index (#41161)#41286
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
Merged
dataroaring
merged 2 commits into
apache:branch-3.0
from
amorynan:improve-array-overlapsSep 29, 2024
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -45,6 +45,7 @@ | ||
| #include "vec/data_types/data_type_number.h" | ||
| #include "vec/functions/array/function_array_utils.h" | ||
| #include "vec/functions/function.h" | ||
| #include "vec/functions/function_helpers.h" | ||
| namespace doris { | ||
| class FunctionContext; | ||
| @@ -128,6 +129,79 @@ class FunctionArraysOverlap : public IFunction { | ||
| return make_nullable(std::make_shared<DataTypeUInt8>()); | ||
| } | ||
| /** | ||
| * eval inverted index. we can filter array rows with inverted index iter | ||
| * array_overlap(array, []) -> array_overlap(array, const value) | ||
| */ | ||
| Status evaluate_inverted_index( | ||
| const ColumnsWithTypeAndName& arguments, | ||
| const std::vector<vectorized::IndexFieldNameAndTypePair>& data_type_with_names, | ||
| std::vector<segment_v2::InvertedIndexIterator*> iterators, uint32_t num_rows, | ||
| segment_v2::InvertedIndexResultBitmap& bitmap_result) const override { | ||
| DCHECK(arguments.size() == 1); | ||
| DCHECK(data_type_with_names.size() == 1); | ||
| DCHECK(iterators.size() == 1); | ||
| auto* iter = iterators[0]; | ||
| if (iter == nullptr) { | ||
| return Status::OK(); | ||
| } | ||
| auto data_type_with_name = data_type_with_names[0]; | ||
| if (iter->get_inverted_index_reader_type() == | ||
| segment_v2::InvertedIndexReaderType::FULLTEXT) { | ||
| return Status::Error<ErrorCode::INVERTED_INDEX_EVALUATE_SKIPPED>( | ||
| "Inverted index evaluate skipped, FULLTEXT reader can not support " | ||
| "array_overlap"); | ||
| } | ||
| // in arrays_overlap param is array Field and const Field | ||
| ColumnPtr arg_column = arguments[0].column; | ||
| DataTypePtr arg_type = arguments[0].type; | ||
| if ((is_column_nullable(*arg_column) && !is_column_const(*remove_nullable(arg_column))) || | ||
| (!is_column_nullable(*arg_column) && !is_column_const(*arg_column))) { | ||
| // if not we should skip inverted index and evaluate in expression | ||
| return Status::Error<ErrorCode::INVERTED_INDEX_EVALUATE_SKIPPED>( | ||
| "Inverted index evaluate skipped, array_overlap only support const value"); | ||
| } | ||
| Field param_value; | ||
| arguments[0].column->get(0, param_value); | ||
| DCHECK(is_array(remove_nullable(arguments[0].type))); | ||
| auto nested_param_type = | ||
| check_and_get_data_type<DataTypeArray>(remove_nullable(arguments[0].type).get()) | ||
| ->get_nested_type() | ||
| ->get_type_as_type_descriptor() | ||
| .type; | ||
| // The current implementation for the inverted index of arrays cannot handle cases where the array contains null values, | ||
| // meaning an item in the array is null. | ||
| if (param_value.is_null()) { | ||
| return Status::OK(); | ||
| } | ||
| std::shared_ptr<roaring::Roaring> roaring = std::make_shared<roaring::Roaring>(); | ||
| std::shared_ptr<roaring::Roaring> null_bitmap = std::make_shared<roaring::Roaring>(); | ||
| if (iter->has_null()) { | ||
| segment_v2::InvertedIndexQueryCacheHandle null_bitmap_cache_handle; | ||
| RETURN_IF_ERROR(iter->read_null_bitmap(&null_bitmap_cache_handle)); | ||
| null_bitmap = null_bitmap_cache_handle.get_bitmap(); | ||
| } | ||
| std::unique_ptr<InvertedIndexQueryParamFactory> query_param = nullptr; | ||
| const Array& query_val = param_value.get<Array>(); | ||
| for (size_t i = 0; i < query_val.size(); ++i) { | ||
| Field nested_query_val = query_val[i]; | ||
| std::shared_ptr<roaring::Roaring> single_res = std::make_shared<roaring::Roaring>(); | ||
| RETURN_IF_ERROR(InvertedIndexQueryParamFactory::create_query_value( | ||
| nested_param_type, &nested_query_val, query_param)); | ||
| RETURN_IF_ERROR(iter->read_from_inverted_index( | ||
| data_type_with_name.first, query_param->get_value(), | ||
| segment_v2::InvertedIndexQueryType::EQUAL_QUERY, num_rows, single_res)); | ||
| *roaring |= *single_res; | ||
| } | ||
| segment_v2::InvertedIndexResultBitmap result(roaring, null_bitmap); | ||
| bitmap_result = result; | ||
xiaokang marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| bitmap_result.mask_out_null(); | ||
| return Status::OK(); | ||
| } | ||
| Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, | ||
| size_t result, size_t input_rows_count) const override { | ||
| auto left_column = | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.