Skip to content

Commit

Permalink
[Refact](inverted index) refact inverted index compound predicates ev…
Browse files Browse the repository at this point in the history
…aluate logic
  • Loading branch information
airborne12 committed Aug 13, 2024
1 parent 666899c commit be3cd04
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 12 deletions.
2 changes: 1 addition & 1 deletion be/src/vec/exprs/vmulti_match_predicate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Status VMultiMatchPredicate::evaluate_inverted_index(VExprContext* context,
auto result = DORIS_TRY(
_evaluate_inverted_index_by_field(context, arguments, segment_num_rows, col_name));
if (ret.is_empty()) {
ret = std::move(result);
ret = result;
} else {
ret |= result;
}
Expand Down
14 changes: 10 additions & 4 deletions be/src/vec/functions/array/function_array_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ class FunctionArrayIndex : public IFunction {
Field param_value;
arguments[0].column->get(0, param_value);
auto param_type = arguments[0].type->get_type_as_type_descriptor().type;
if (param_value.is_null()) {
return Status::OK();
//return Status::Error<ErrorCode::INVERTED_INDEX_EVALUATE_SKIPPED>(
// "Inverted index evaluate skipped, param_value is nullptr or value is null");
}
if (iter->get_inverted_index_reader_type() ==
segment_v2::InvertedIndexReaderType::FULLTEXT) {
// parser is not none we can not make sure the result is correct in expr combination
Expand All @@ -136,8 +141,9 @@ class FunctionArrayIndex : public IFunction {
// but query is also tokenized, and FULLTEXT reader will catch this row as matched,
// so array_index(array, 'tall:120cm, weight: 35kg') return this rowid,
// but we expect it to be filtered, because we want row is equal to 'tall:120cm, weight: 35kg'
return Status::Error<ErrorCode::INVERTED_INDEX_EVALUATE_SKIPPED>(
"Inverted index evaluate skipped, FULLTEXT reader can not support array_index");
return Status::OK();
//return Status::Error<ErrorCode::INVERTED_INDEX_EVALUATE_SKIPPED>(
// "Inverted index evaluate skipped, FULLTEXT reader can not support array_index");
}
std::unique_ptr<InvertedIndexQueryParamFactory> query_param = nullptr;
RETURN_IF_ERROR(InvertedIndexQueryParamFactory::create_query_value(param_type, &param_value,
Expand All @@ -164,11 +170,11 @@ class FunctionArrayIndex : public IFunction {
RETURN_IF_ERROR(iter->read_null_bitmap(&null_bitmap_cache_handle));
std::shared_ptr<roaring::Roaring> null_bitmap = null_bitmap_cache_handle.get_bitmap();
segment_v2::InvertedIndexResultBitmap result(roaring, null_bitmap);
bitmap_result = std::move(result);
bitmap_result = result;
} else {
std::shared_ptr<roaring::Roaring> null_bitmap = std::make_shared<roaring::Roaring>();
segment_v2::InvertedIndexResultBitmap result(roaring, null_bitmap);
bitmap_result = std::move(result);
bitmap_result = result;
}

return Status::OK();
Expand Down
9 changes: 7 additions & 2 deletions be/src/vec/functions/functions_comparison.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,11 @@ class FunctionComparison : public IFunction {
if (iter == nullptr) {
return Status::OK();
}
if (iter->get_inverted_index_reader_type() ==
segment_v2::InvertedIndexReaderType::FULLTEXT) {
//NOT support comparison predicate when parser is FULLTEXT for expr inverted index evaluate.
return Status::OK();
}
std::string column_name = data_type_with_name.first;
Field param_value;
arguments[0].column->get(0, param_value);
Expand Down Expand Up @@ -574,11 +579,11 @@ class FunctionComparison : public IFunction {
RETURN_IF_ERROR(iter->read_null_bitmap(&null_bitmap_cache_handle));
std::shared_ptr<roaring::Roaring> null_bitmap = null_bitmap_cache_handle.get_bitmap();
segment_v2::InvertedIndexResultBitmap result(roaring, null_bitmap);
bitmap_result = std::move(result);
bitmap_result = result;
} else {
std::shared_ptr<roaring::Roaring> null_bitmap = std::make_shared<roaring::Roaring>();
segment_v2::InvertedIndexResultBitmap result(roaring, null_bitmap);
bitmap_result = std::move(result);
bitmap_result = result;
}

if (name == "ne") {
Expand Down
9 changes: 7 additions & 2 deletions be/src/vec/functions/in.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ class FunctionIn : public IFunction {
if (iter == nullptr) {
return Status::OK();
}
if (iter->get_inverted_index_reader_type() ==
segment_v2::InvertedIndexReaderType::FULLTEXT) {
//NOT support in list when parser is FULLTEXT for expr inverted index evaluate.
return Status::OK();
}
std::string column_name = data_type_with_name.first;
//NOTE: maybe we got NULL process problem here, need to figure it out.
for (const auto& arg : arguments) {
Expand All @@ -166,11 +171,11 @@ class FunctionIn : public IFunction {
RETURN_IF_ERROR(iter->read_null_bitmap(&null_bitmap_cache_handle));
std::shared_ptr<roaring::Roaring> null_bitmap = null_bitmap_cache_handle.get_bitmap();
segment_v2::InvertedIndexResultBitmap result(roaring, null_bitmap);
bitmap_result = std::move(result);
bitmap_result = result;
} else {
std::shared_ptr<roaring::Roaring> null_bitmap = std::make_shared<roaring::Roaring>();
segment_v2::InvertedIndexResultBitmap result(roaring, null_bitmap);
bitmap_result = std::move(result);
bitmap_result = result;
}

if constexpr (negative) {
Expand Down
4 changes: 2 additions & 2 deletions be/src/vec/functions/match.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ Status FunctionMatchBase::evaluate_inverted_index(
RETURN_IF_ERROR(iter->read_null_bitmap(&null_bitmap_cache_handle));
std::shared_ptr<roaring::Roaring> null_bitmap = null_bitmap_cache_handle.get_bitmap();
segment_v2::InvertedIndexResultBitmap result(roaring, null_bitmap);
bitmap_result = std::move(result);
bitmap_result = result;
} else {
std::shared_ptr<roaring::Roaring> null_bitmap = std::make_shared<roaring::Roaring>();
segment_v2::InvertedIndexResultBitmap result(roaring, null_bitmap);
bitmap_result = std::move(result);
bitmap_result = result;
}

return Status::OK();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ suite("test_index_multi_match", "p0"){
} finally {
//try_sql("DROP TABLE IF EXISTS ${testTable}")
}
}
}

0 comments on commit be3cd04

Please sign in to comment.