Repository navigation
Propagate OperationResult [3/4]: estimate_cardinality - #8446
Conversation
ab9e869 to
99299a6
Compare
b61f902 to
11444ac
Compare
99299a6 to
f5ddf7c
Compare
11444ac to
337bfdf
Compare
f5ddf7c to
c73b359
Compare
337bfdf to
7f74a36
Compare
c73b359 to
70f5f6b
Compare
7f74a36 to
a047ac3
Compare
70f5f6b to
d6f69f8
Compare
a047ac3 to
e5d91c8
Compare
e5d91c8 to
c9c1cca
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (33)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (14)
📝 WalkthroughWalkthroughThis PR converts many previously infallible payload/index/query APIs to return OperationResult, changing return types across PayloadIndex and PayloadFieldIndex traits and their concrete implementations (field indices, geo/map/numeric/bool/full-text, HNSW, plain/sparse/struct indices). Call sites are updated to propagate errors with Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can enable review details to help with troubleshooting, context usage and more.Enable the |
There was a problem hiding this comment.
🧹 Nitpick comments (5)
lib/segment/src/index/field_index/map_index/mod.rs (1)
809-863: Please enumerate the unsupportedMatchcases explicitly.All three updated estimators still end with
_ => None, which means a newly addedMatchvariant will be ignored by cardinality planning instead of triggering a compile-time review in these index routers.As per coding guidelines, "Prefer explicit exhaustive matches over catch-all
_arm in Rust match expressions, so we don't miss handling new enum variants when they are added later".Also applies to: 981-1056, 1154-1208
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/index/field_index/map_index/mod.rs` around lines 809 - 863, The match on condition.r#match currently ends with a catch-all `_ => None`; replace that catch-all with explicit arms for every remaining Match enum variant not already handled (i.e., add explicit Match::X(...) => None stubs or real handling) instead of `_`, so new variants trigger compile-time review; update the same change in the other two similar match blocks referenced (the blocks around the other ranges) and keep the existing handled arms (Match::Value, Match::Any, Match::Except) unchanged while adding explicit unsupported arms with a short comment like "unsupported by map_index".lib/segment/src/index/field_index/full_text_index/text_index.rs (1)
618-623: Make theMatchdispatch explicit here.This new estimator path uses a catch-all
_arm, so a futureMatchvariant will silently fall intoOk(None)instead of forcing an explicit decision in full-text routing.As per coding guidelines, "Prefer explicit exhaustive matches over catch-all
_arm in Rust match expressions, so we don't miss handling new enum variants when they are added later".🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/index/field_index/full_text_index/text_index.rs` around lines 618 - 623, The match over condition.r#match currently uses a catch-all `_` arm which hides future Match variants; replace the `_` arm with explicit match arms for every current Match variant (e.g., Match::Text => self.parse_text_query(text, hw_counter), Match::Phrase => self.parse_phrase_query(phrase, hw_counter), plus explicit arms for any other existing Match::... variants) and have each arm either call the appropriate parser or return Ok(None) as intended so new variants will force you to handle them at compile time (remove the wildcard to ensure exhaustiveness).lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs (1)
399-420: Prefer an explicit match here instead of_ => None.Since this function is already being updated, expanding the match keeps future
Matchvariants compiler-visible instead of silently treating them as unsupported. As per coding guidelines: Prefer explicit exhaustive matches over catch-all_arm in Rust match expressions, so we don't miss handling new enum variants when they are added later.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs` around lines 399 - 420, The match in estimate_cardinality currently uses a catch-all `_ => None`; replace that with an explicit match over all Match enum variants (e.g., Match::Value(...), Match::Range(...), Match::OneOf(...), etc.) so each variant is spelled out and unsupported variants explicitly return None; update the match arms in the estimate_cardinality function (referencing FieldCondition and Match) to keep the compiler checking future enum additions rather than silently matching `_`, leaving the existing handling for Match::Value(ValueVariants::Bool(...)) intact and returning Some(estimation) there while returning None in the other explicit arms.lib/segment/src/index/field_index/bool_index/simple_bool_index.rs (1)
371-392: Prefer an explicit match here instead of_ => None.Now that this function is being touched, the catch-all arm will silently accept future
Matchvariants without forcing a decision on whether the bool index should support them. As per coding guidelines: Prefer explicit exhaustive matches over catch-all_arm in Rust match expressions, so we don't miss handling new enum variants when they are added later.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/index/field_index/bool_index/simple_bool_index.rs` around lines 371 - 392, The match in estimate_cardinality currently uses a catch-all `_ => None`; replace that with explicit arms for each current Match enum variant so unsupported variants return None individually (e.g., add explicit arms like Match::Range(..) => None, Match::Values(..) => None, etc.), ensuring the match is exhaustive without a wildcard so future Match variants will force a compile-time decision; keep the existing Bool arm (Match::Value with ValueVariants::Bool) and the construction of CardinalityEstimation as-is.lib/segment/src/index/struct_payload_index.rs (1)
120-127: Consider naming thetransposebridge.
find_map(...transpose()).transpose()is correct, but it takes a moment to reconstruct theOption<Result<_>>/Result<Option<_>>flow. A tiny helper or short comment here would make this new error-propagation path easier to maintain.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/index/struct_payload_index.rs` around lines 120 - 127, The expression using chained transposes (indexes.iter().find_map(|index| index.estimate_cardinality(&full_path_condition, hw_counter).transpose()).transpose()) is correct but confusing; introduce a small named helper or intermediate variable (e.g., let transpose_bridge = |opt_res: Option<Result<T, E>>| -> Result<Option<T>, E> { opt_res.transpose() } or name the intermediate result like found_cardinality = indexes.iter().find_map(...).transpose() ) or add a one-line comment explaining the Option<Result<_>> → Result<Option<_>> conversion to make the intent clear and reference estimate_cardinality, full_path_condition, hw_counter and the find_map call when locating the code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs`:
- Around line 399-420: The match in estimate_cardinality currently uses a
catch-all `_ => None`; replace that with an explicit match over all Match enum
variants (e.g., Match::Value(...), Match::Range(...), Match::OneOf(...), etc.)
so each variant is spelled out and unsupported variants explicitly return None;
update the match arms in the estimate_cardinality function (referencing
FieldCondition and Match) to keep the compiler checking future enum additions
rather than silently matching `_`, leaving the existing handling for
Match::Value(ValueVariants::Bool(...)) intact and returning Some(estimation)
there while returning None in the other explicit arms.
In `@lib/segment/src/index/field_index/bool_index/simple_bool_index.rs`:
- Around line 371-392: The match in estimate_cardinality currently uses a
catch-all `_ => None`; replace that with explicit arms for each current Match
enum variant so unsupported variants return None individually (e.g., add
explicit arms like Match::Range(..) => None, Match::Values(..) => None, etc.),
ensuring the match is exhaustive without a wildcard so future Match variants
will force a compile-time decision; keep the existing Bool arm (Match::Value
with ValueVariants::Bool) and the construction of CardinalityEstimation as-is.
In `@lib/segment/src/index/field_index/full_text_index/text_index.rs`:
- Around line 618-623: The match over condition.r#match currently uses a
catch-all `_` arm which hides future Match variants; replace the `_` arm with
explicit match arms for every current Match variant (e.g., Match::Text =>
self.parse_text_query(text, hw_counter), Match::Phrase =>
self.parse_phrase_query(phrase, hw_counter), plus explicit arms for any other
existing Match::... variants) and have each arm either call the appropriate
parser or return Ok(None) as intended so new variants will force you to handle
them at compile time (remove the wildcard to ensure exhaustiveness).
In `@lib/segment/src/index/field_index/map_index/mod.rs`:
- Around line 809-863: The match on condition.r#match currently ends with a
catch-all `_ => None`; replace that catch-all with explicit arms for every
remaining Match enum variant not already handled (i.e., add explicit
Match::X(...) => None stubs or real handling) instead of `_`, so new variants
trigger compile-time review; update the same change in the other two similar
match blocks referenced (the blocks around the other ranges) and keep the
existing handled arms (Match::Value, Match::Any, Match::Except) unchanged while
adding explicit unsupported arms with a short comment like "unsupported by
map_index".
In `@lib/segment/src/index/struct_payload_index.rs`:
- Around line 120-127: The expression using chained transposes
(indexes.iter().find_map(|index|
index.estimate_cardinality(&full_path_condition,
hw_counter).transpose()).transpose()) is correct but confusing; introduce a
small named helper or intermediate variable (e.g., let transpose_bridge =
|opt_res: Option<Result<T, E>>| -> Result<Option<T>, E> { opt_res.transpose() }
or name the intermediate result like found_cardinality =
indexes.iter().find_map(...).transpose() ) or add a one-line comment explaining
the Option<Result<_>> → Result<Option<_>> conversion to make the intent clear
and reference estimate_cardinality, full_path_condition, hw_counter and the
find_map call when locating the code.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 75138cb0-1329-41a2-be2f-42aa509c0eee
📒 Files selected for processing (33)
lib/collection/src/collection_manager/segments_searcher.rslib/segment/benches/boolean_filtering.rslib/segment/benches/conditional_search.rslib/segment/benches/range_filtering.rslib/segment/src/index/field_index/bool_index/mod.rslib/segment/src/index/field_index/bool_index/mutable_bool_index.rslib/segment/src/index/field_index/bool_index/simple_bool_index.rslib/segment/src/index/field_index/field_index_base.rslib/segment/src/index/field_index/full_text_index/text_index.rslib/segment/src/index/field_index/geo_index/mod.rslib/segment/src/index/field_index/map_index/mod.rslib/segment/src/index/field_index/null_index/mutable_null_index.rslib/segment/src/index/field_index/numeric_index/mod.rslib/segment/src/index/hnsw_index/hnsw.rslib/segment/src/index/payload_index_base.rslib/segment/src/index/plain_payload_index.rslib/segment/src/index/plain_vector_index.rslib/segment/src/index/query_estimator.rslib/segment/src/index/query_optimization/optimizer.rslib/segment/src/index/query_optimization/rescore_formula/formula_scorer.rslib/segment/src/index/sparse_index/sparse_vector_index.rslib/segment/src/index/struct_payload_index.rslib/segment/src/segment/entry.rslib/segment/src/segment/facet.rslib/segment/src/segment/formula_rescore.rslib/segment/src/segment/order_by.rslib/segment/src/segment/sampling.rslib/segment/src/segment/scroll.rslib/segment/tests/integration/exact_search_test.rslib/segment/tests/integration/filtering_context_check.rslib/segment/tests/integration/filtrable_hnsw_test.rslib/segment/tests/integration/nested_filtering_test.rslib/segment/tests/integration/payload_index_test.rs
c9c1cca to
c232229
Compare
Fourth commit in the stack #8433.