11/*
2- * Copyright 2024 -present Alibaba Inc.
2+ * Copyright 2026 -present Alibaba Inc.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1414 * limitations under the License.
1515 */
1616
17- #include " paimon/global_index/bitmap_vector_search_global_index_result .h"
17+ #include " paimon/global_index/bitmap_scored_global_index_result .h"
1818
1919#include " fmt/format.h"
2020#include " fmt/ranges.h"
@@ -41,78 +41,76 @@ std::vector<float> GetScoresFromMap(const RoaringBitmap64& bitmap,
4141 return scores;
4242}
4343} // namespace
44- Result<std::unique_ptr<GlobalIndexResult::Iterator>>
45- BitmapVectorSearchGlobalIndexResult::CreateIterator () const {
44+ Result<std::unique_ptr<GlobalIndexResult::Iterator>> BitmapScoredGlobalIndexResult::CreateIterator ()
45+ const {
4646 return std::make_unique<BitmapGlobalIndexResult::Iterator>(&bitmap_, bitmap_.Begin ());
4747}
4848
49- Result<std::unique_ptr<VectorSearchGlobalIndexResult::VectorSearchIterator >>
50- BitmapVectorSearchGlobalIndexResult::CreateVectorSearchIterator () const {
51- return std::make_unique<BitmapVectorSearchGlobalIndexResult::VectorSearchIterator >(
49+ Result<std::unique_ptr<ScoredGlobalIndexResult::ScoredIterator >>
50+ BitmapScoredGlobalIndexResult::CreateScoredIterator () const {
51+ return std::make_unique<BitmapScoredGlobalIndexResult::ScoredIterator >(
5252 &bitmap_, bitmap_.Begin (), scores_.data ());
5353}
5454
55- Result<std::shared_ptr<GlobalIndexResult>> BitmapVectorSearchGlobalIndexResult ::And (
55+ Result<std::shared_ptr<GlobalIndexResult>> BitmapScoredGlobalIndexResult ::And (
5656 const std::shared_ptr<GlobalIndexResult>& other) {
57- auto vector_search_other =
58- std::dynamic_pointer_cast<BitmapVectorSearchGlobalIndexResult>(other);
59- if (vector_search_other) {
60- // If current and other result are both BitmapVectorSearchGlobalIndexResult, return
57+ auto scored_other = std::dynamic_pointer_cast<BitmapScoredGlobalIndexResult>(other);
58+ if (scored_other) {
59+ // If current and other result are both BitmapScoredGlobalIndexResult, return
6160 // BitmapGlobalIndexResult. Erase scores to prevent the same row id with different
6261 // scores in current and other results.
63- auto supplier = [vector_search_other ,
64- result = std::dynamic_pointer_cast<BitmapVectorSearchGlobalIndexResult >(
62+ auto supplier = [scored_other ,
63+ result = std::dynamic_pointer_cast<BitmapScoredGlobalIndexResult >(
6564 shared_from_this ())]() -> Result<RoaringBitmap64> {
66- PAIMON_ASSIGN_OR_RAISE (const RoaringBitmap64* r1, vector_search_other ->GetBitmap ());
65+ PAIMON_ASSIGN_OR_RAISE (const RoaringBitmap64* r1, scored_other ->GetBitmap ());
6766 PAIMON_ASSIGN_OR_RAISE (const RoaringBitmap64* r2, result->GetBitmap ());
6867 return RoaringBitmap64::And (*r1, *r2);
6968 };
7069 return std::make_shared<BitmapGlobalIndexResult>(supplier);
7170 }
7271 auto bitmap_other = std::dynamic_pointer_cast<BitmapGlobalIndexResult>(other);
7372 if (bitmap_other) {
74- // If other bitmap is BitmapGlobalIndexResult, return BitmapVectorSearchGlobalIndexResult as
75- // score must exist in current vector search result.
73+ // If other bitmap is BitmapGlobalIndexResult, return BitmapScoredGlobalIndexResult as
74+ // score must exist in current scored result.
7675 std::map<int64_t , float > id_to_score = CreateIdToScoreMap (bitmap_, scores_);
7776 PAIMON_ASSIGN_OR_RAISE (const RoaringBitmap64* other_bitmap, bitmap_other->GetBitmap ());
7877 auto and_bitmap = RoaringBitmap64::And (bitmap_, *other_bitmap);
7978 std::vector<float > and_scores = GetScoresFromMap (and_bitmap, id_to_score);
80- return std::make_shared<BitmapVectorSearchGlobalIndexResult >(std::move (and_bitmap),
81- std::move (and_scores));
79+ return std::make_shared<BitmapScoredGlobalIndexResult >(std::move (and_bitmap),
80+ std::move (and_scores));
8281 }
8382 return GlobalIndexResult::And (other);
8483}
8584
86- Result<std::shared_ptr<GlobalIndexResult>> BitmapVectorSearchGlobalIndexResult ::Or (
85+ Result<std::shared_ptr<GlobalIndexResult>> BitmapScoredGlobalIndexResult ::Or (
8786 const std::shared_ptr<GlobalIndexResult>& other) {
88- auto vector_search_other =
89- std::dynamic_pointer_cast<BitmapVectorSearchGlobalIndexResult>(other);
90- if (vector_search_other) {
91- // If current and other result are both BitmapVectorSearchGlobalIndexResult, return
92- // BitmapVectorSearchGlobalIndexResult when current and other have has no intersection row
87+ auto scored_other = std::dynamic_pointer_cast<BitmapScoredGlobalIndexResult>(other);
88+ if (scored_other) {
89+ // If current and other result are both BitmapScoredGlobalIndexResult, return
90+ // BitmapScoredGlobalIndexResult when current and other have has no intersection row
9391 // id.
9492 std::map<int64_t , float > id_to_score = CreateIdToScoreMap (bitmap_, scores_);
9593 size_t idx = 0 ;
96- for (auto iter = vector_search_other ->bitmap_ .Begin ();
97- iter != vector_search_other-> bitmap_ . End (); ++iter, ++idx) {
94+ for (auto iter = scored_other ->bitmap_ .Begin (); iter != scored_other-> bitmap_ . End ();
95+ ++iter, ++idx) {
9896 if (id_to_score.find (*iter) != id_to_score.end ()) {
9997 return Status::Invalid (
100- " not support two BitmapVectorSearchGlobalIndexResult or with same row id" );
98+ " not support two BitmapScoredGlobalIndexResult or with same row id" );
10199 }
102- id_to_score[*iter] = vector_search_other ->scores_ [idx];
100+ id_to_score[*iter] = scored_other ->scores_ [idx];
103101 }
104- auto or_bitmap = RoaringBitmap64::Or (bitmap_, vector_search_other ->bitmap_ );
102+ auto or_bitmap = RoaringBitmap64::Or (bitmap_, scored_other ->bitmap_ );
105103 std::vector<float > or_scores = GetScoresFromMap (or_bitmap, id_to_score);
106- return std::make_shared<BitmapVectorSearchGlobalIndexResult >(std::move (or_bitmap),
107- std::move (or_scores));
104+ return std::make_shared<BitmapScoredGlobalIndexResult >(std::move (or_bitmap),
105+ std::move (or_scores));
108106 }
109107
110108 auto bitmap_other = std::dynamic_pointer_cast<BitmapGlobalIndexResult>(other);
111109 if (bitmap_other) {
112110 // If other bitmap is BitmapGlobalIndexResult, return BitmapGlobalIndexResult as
113111 // score for union row id is unknown.
114112 auto supplier = [bitmap_other,
115- result = std::dynamic_pointer_cast<BitmapVectorSearchGlobalIndexResult >(
113+ result = std::dynamic_pointer_cast<BitmapScoredGlobalIndexResult >(
116114 shared_from_this ())]() -> Result<RoaringBitmap64> {
117115 PAIMON_ASSIGN_OR_RAISE (const RoaringBitmap64* r1, bitmap_other->GetBitmap ());
118116 PAIMON_ASSIGN_OR_RAISE (const RoaringBitmap64* r2, result->GetBitmap ());
@@ -123,31 +121,30 @@ Result<std::shared_ptr<GlobalIndexResult>> BitmapVectorSearchGlobalIndexResult::
123121 return GlobalIndexResult::Or (other);
124122}
125123
126- Result<std::shared_ptr<GlobalIndexResult>> BitmapVectorSearchGlobalIndexResult ::AddOffset (
124+ Result<std::shared_ptr<GlobalIndexResult>> BitmapScoredGlobalIndexResult ::AddOffset (
127125 int64_t offset) {
128126 PAIMON_ASSIGN_OR_RAISE (const RoaringBitmap64* bitmap, GetBitmap ());
129127 RoaringBitmap64 bitmap64;
130128 for (auto iter = bitmap->Begin (); iter != bitmap->End (); ++iter) {
131129 bitmap64.Add (offset + (*iter));
132130 }
133131 auto scores = GetScores ();
134- return std::make_shared<BitmapVectorSearchGlobalIndexResult>(std::move (bitmap64),
135- std::move (scores));
132+ return std::make_shared<BitmapScoredGlobalIndexResult>(std::move (bitmap64), std::move (scores));
136133}
137134
138- Result<bool > BitmapVectorSearchGlobalIndexResult ::IsEmpty () const {
135+ Result<bool > BitmapScoredGlobalIndexResult ::IsEmpty () const {
139136 return bitmap_.IsEmpty ();
140137}
141138
142- Result<const RoaringBitmap64*> BitmapVectorSearchGlobalIndexResult ::GetBitmap () const {
139+ Result<const RoaringBitmap64*> BitmapScoredGlobalIndexResult ::GetBitmap () const {
143140 return &bitmap_;
144141}
145142
146- const std::vector<float >& BitmapVectorSearchGlobalIndexResult ::GetScores () const {
143+ const std::vector<float >& BitmapScoredGlobalIndexResult ::GetScores () const {
147144 return scores_;
148145}
149146
150- std::string BitmapVectorSearchGlobalIndexResult ::ToString () const {
147+ std::string BitmapScoredGlobalIndexResult ::ToString () const {
151148 std::vector<std::string> formatted_scores;
152149 formatted_scores.reserve (scores_.size ());
153150 for (const auto & score : scores_) {
0 commit comments