lszskye commented on code in PR #573:
URL: https://github.com/apache/paimon-cpp/pull/573#discussion_r4623821075


##########
src/paimon/core/io/file_index_evaluator.cpp:
##########
@@ -199,22 +203,48 @@ Result<std::shared_ptr<FileIndexResult>> 
FileIndexEvaluator::EvaluateLeaf(
         if (!full_text) {
             return Status::Invalid("FullTextMatch requires a full-text match 
predicate");
         }
-        return reader->VisitFullTextMatch(full_text->GetFullTextMatch(), 
needs_scores);
+        auto match = full_text->GetFullTextMatch();
+        if (candidates) {
+            match = std::make_shared<FullTextMatch>(*match);
+            RoaringBitmap64 eligible(*candidates);
+            if (match->include_row_ids) {
+                eligible &= *match->include_row_ids;
+            }
+            match->include_row_ids = std::move(eligible);
+        }
+        return reader->VisitFullTextMatch(match, needs_scores);
+    }
+    if (candidates && candidates->IsEmpty()) {
+        return FileIndexResult::Skip();
     }
     PAIMON_ASSIGN_OR_RAISE(std::vector<std::shared_ptr<FileIndexReader>> 
readers,
                            GetReaders(predicate->FieldName()));
-    std::shared_ptr<FileIndexResult> result = FileIndexResult::Remain();
     for (const auto& reader : readers) {
-        PAIMON_ASSIGN_OR_RAISE(
-            std::shared_ptr<FileIndexResult> child,
-            
PredicateUtils::VisitPredicate<std::shared_ptr<FileIndexResult>>(predicate, 
reader));
-        PAIMON_ASSIGN_OR_RAISE(result, result->And(child));
-        PAIMON_ASSIGN_OR_RAISE(bool remain, result->IsRemain());
-        if (!remain) {
-            break;
+        PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<FileIndexResult> child,
+                               reader->Evaluate(predicate, candidates));
+        // Inexact indexes may miss matches. Try another index over the 
original scope.
+        // Remain is also inexact and contributes no row selection for this 
predicate.
+        if (!child->IsExact()) {
+            continue;
+        }
+        if (std::dynamic_pointer_cast<Skip>(child)) {
+            return child;
+        }
+        auto bitmap = std::dynamic_pointer_cast<BitmapIndexResult>(child);
+        assert(bitmap);
+        if (!candidates) {
+            return child;
         }
+        return std::make_shared<BitmapIndexResult>(
+            [bitmap, rows = *candidates]() -> Result<RoaringBitmap32> {
+                PAIMON_ASSIGN_OR_RAISE(const RoaringBitmap32* matches, 
bitmap->GetBitmap());
+                RoaringBitmap32 result(rows);
+                result &= *matches;
+                return result;
+            },
+            /*is_exact=*/true);
     }
-    return result;
+    return FileIndexResult::Remain();

Review Comment:
   Will return `candidates` instead



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to