Skip to content

Commit

Permalink
[opt](inverted index) Add null document interface to optimize empty s…
Browse files Browse the repository at this point in the history
…tring indexing (apache#28661)
  • Loading branch information
qidaye authored Dec 20, 2023
1 parent afd5512 commit 3296487
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions be/src/olap/rowset/segment_v2/inverted_index_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ class InvertedIndexColumnWriterImpl : public InvertedIndexColumnWriter {
return Status::OK();
}

Status add_null_document() {
try {
_index_writer->addNullDocument(_doc.get());
} catch (const CLuceneError& e) {
_dir->deleteDirectory();
return Status::Error<ErrorCode::INVERTED_INDEX_CLUCENE_ERROR>(
"CLuceneError add_null_document: {}", e.what());
}
return Status::OK();
}

Status add_nulls(uint32_t count) override {
_null_bitmap.addRange(_rid, _rid + count);
_rid += count;
Expand All @@ -242,7 +253,7 @@ class InvertedIndexColumnWriterImpl : public InvertedIndexColumnWriter {

for (int i = 0; i < count; ++i) {
new_fulltext_field(empty_value.c_str(), 0);
RETURN_IF_ERROR(add_document());
RETURN_IF_ERROR(add_null_document());
}
}
return Status::OK();
Expand Down Expand Up @@ -292,10 +303,11 @@ class InvertedIndexColumnWriterImpl : public InvertedIndexColumnWriter {
VLOG_DEBUG << "fulltext index value length can be at most 256, but got "
<< "value length:" << v->get_size() << ", ignore this value";
new_fulltext_field(empty_value.c_str(), 0);
RETURN_IF_ERROR(add_null_document());
} else {
new_fulltext_field(v->get_data(), v->get_size());
RETURN_IF_ERROR(add_document());
}
RETURN_IF_ERROR(add_document());
++v;
_rid++;
}
Expand Down Expand Up @@ -341,11 +353,12 @@ class InvertedIndexColumnWriterImpl : public InvertedIndexColumnWriter {
VLOG_DEBUG << "fulltext index value length can be at most 256, but got "
<< "value length:" << value.length() << ", ignore this value";
new_fulltext_field(empty_value.c_str(), 0);
RETURN_IF_ERROR(add_null_document());
} else {
new_fulltext_field(value.c_str(), value.length());
RETURN_IF_ERROR(add_document());
}
_rid++;
RETURN_IF_ERROR(add_document());
}
} else if constexpr (field_is_numeric_type(field_type)) {
for (int i = 0; i < count; ++i) {
Expand Down

0 comments on commit 3296487

Please sign in to comment.