Repository navigation
refactor: relocate read-view-exclusive helpers under read_view/ - #8977
Conversation
The helpers in query_optimization/condition_converter{,/match_converter}.rs
and the bulk of query_optimization/rescore_formula/value_retriever.rs were
only ever called from struct_payload_index/read_view/. Move them next to
their callers.
The trait split work (#8975, #8976) showed why these helpers can't migrate
to a uniform FieldIndexRead bound: every branch in field_condition_index,
match_converter, get_range_*, get_geo_*, indexed_variable_retriever
destructures FieldIndex variants and reaches into variant-specific
predicates on the underlying typed indexes (MapIndex::check_values_any,
FullTextIndex::parse_*_query, NumericIndex::get_values, …). The variant
match is the whole point of these helpers; co-locating them with the read
view is the right shape.
New layout:
- read_view/condition_converter/{mod.rs, helpers.rs, match_converter.rs}
(was a flat read_view/condition_converter.rs + scattered query_optimization
files)
- read_view/value_retriever/{mod.rs, helpers.rs}
(was a flat read_view/value_retriever.rs + query_optimization/rescore_formula/
value_retriever.rs)
VariableRetrieverFn type alias stays in query_optimization/rescore_formula/
value_retriever.rs (now a 6-line file): formula_scorer.rs in the same module
uses it as a struct field, so the type belongs there. Only the helper
functions and their tests move.
Visibility tightened where natural: cross-file entry points are
pub(super), purely-local helpers are private, public-API surface is
unchanged.
No behavioural change. cargo test -p segment: 666 unit + 120 integration
tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis PR refactors the Qdrant codebase to localize condition_converter and value_retriever implementations from the query_optimization module hierarchy into struct_payload_index/read_view. The condition_converter is removed from public exports in query_optimization/mod.rs. Helper functions in condition_converter/helpers.rs are reduced from public to internal visibility (pub(super) or private). A new value_retriever/helpers.rs is created that implements index-based and payload-based value extraction with array flattening logic and type conversions for multiple FieldIndex variants. Both modules are rewired to source their helpers locally instead of from query_optimization. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/segment/src/index/struct_payload_index/read_view/condition_converter/helpers.rs (1)
221-229: ⚡ Quick winReplace wildcard arm in
get_is_empty_indexeswith explicitFieldIndexvariants.Line 226 uses
_, which can silently absorb future enum variants and hide behavior changes in this selection logic.Suggested patch
for index in indexes { match index { FieldIndex::NullIndex(null_index) => { primary_null_index = Some(null_index); } - _ => { + FieldIndex::BoolIndex(_) + | FieldIndex::DatetimeIndex(_) + | FieldIndex::FloatIndex(_) + | FieldIndex::FullTextIndex(_) + | FieldIndex::GeoIndex(_) + | FieldIndex::IntIndex(_) + | FieldIndex::IntMapIndex(_) + | FieldIndex::KeywordIndex(_) + | FieldIndex::UuidIndex(_) + | FieldIndex::UuidMapIndex(_) => { fallback_index = Some(index); } } }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 current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/segment/src/index/struct_payload_index/read_view/condition_converter/helpers.rs` around lines 221 - 229, The match in get_is_empty_indexes currently uses a wildcard arm (_) which can hide new FieldIndex variants; update the match to enumerate all existing FieldIndex variants explicitly (e.g., FieldIndex::NullIndex and each other current variant) and for each non-NullIndex arm preserve the current behavior of assigning fallback_index = Some(index) (or specific handling if a variant needs different logic), so that adding new variants will force compile-time handling rather than being silently absorbed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@lib/segment/src/index/struct_payload_index/read_view/condition_converter/helpers.rs`:
- Around line 221-229: The match in get_is_empty_indexes currently uses a
wildcard arm (_) which can hide new FieldIndex variants; update the match to
enumerate all existing FieldIndex variants explicitly (e.g.,
FieldIndex::NullIndex and each other current variant) and for each non-NullIndex
arm preserve the current behavior of assigning fallback_index = Some(index) (or
specific handling if a variant needs different logic), so that adding new
variants will force compile-time handling rather than being silently absorbed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3c86e376-3855-4723-acf9-43f4882784b4
📒 Files selected for processing (7)
lib/segment/src/index/query_optimization/mod.rslib/segment/src/index/query_optimization/rescore_formula/value_retriever.rslib/segment/src/index/struct_payload_index/read_view/condition_converter/helpers.rslib/segment/src/index/struct_payload_index/read_view/condition_converter/match_converter.rslib/segment/src/index/struct_payload_index/read_view/condition_converter/mod.rslib/segment/src/index/struct_payload_index/read_view/value_retriever/helpers.rslib/segment/src/index/struct_payload_index/read_view/value_retriever/mod.rs
💤 Files with no reviewable changes (1)
- lib/segment/src/index/query_optimization/mod.rs
The helpers in query_optimization/condition_converter{,/match_converter}.rs
and the bulk of query_optimization/rescore_formula/value_retriever.rs were
only ever called from struct_payload_index/read_view/. Move them next to
their callers.
The trait split work (#8975, #8976) showed why these helpers can't migrate
to a uniform FieldIndexRead bound: every branch in field_condition_index,
match_converter, get_range_*, get_geo_*, indexed_variable_retriever
destructures FieldIndex variants and reaches into variant-specific
predicates on the underlying typed indexes (MapIndex::check_values_any,
FullTextIndex::parse_*_query, NumericIndex::get_values, …). The variant
match is the whole point of these helpers; co-locating them with the read
view is the right shape.
New layout:
- read_view/condition_converter/{mod.rs, helpers.rs, match_converter.rs}
(was a flat read_view/condition_converter.rs + scattered query_optimization
files)
- read_view/value_retriever/{mod.rs, helpers.rs}
(was a flat read_view/value_retriever.rs + query_optimization/rescore_formula/
value_retriever.rs)
VariableRetrieverFn type alias stays in query_optimization/rescore_formula/
value_retriever.rs (now a 6-line file): formula_scorer.rs in the same module
uses it as a struct field, so the type belongs there. Only the helper
functions and their tests move.
Visibility tightened where natural: cross-file entry points are
pub(super), purely-local helpers are private, public-API surface is
unchanged.
No behavioural change. cargo test -p segment: 666 unit + 120 integration
tests pass.
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Step 3 of the
StructPayloadIndexReadView➜FieldIndexReadtrack. After #8975 / #8976 introducedFieldIndexRead, the original step-3 plan was to migrate variant-destructuring helpers inquery_optimization/condition_converter*andrescore_formula/value_retriever.rsto aFieldIndexReadbound. That migration isn't possible — every branch in those helpers reaches into a variant-specific predicate on the underlying typed index (MapIndex::check_values_any,FullTextIndex::parse_text_query,NumericIndex::get_values, …), and the variant match is the entire point.The right shape is to co-locate the helpers with their only callers. Call-graph audit (
grep -rnacross the workspace) showed that:field_condition_index, the entirematch_convertersubmodule,get_range_*,get_geo_*,get_is_empty_indexes,get_null_index_is_empty_checker,get_fallback_is_empty_checker,get_is_null_checker, andvariable_retriever(+ itspayload_variable_retriever/indexed_variable_retrieversiblings) are only called fromstruct_payload_index/read_view/.check_field_conditionandselect_nested_indexes(inpayload_storage/query_checker.rs) stay where they are — they have non-view callers.Layout change
Before:
After:
VariableRetrieverFntype alias stays inquery_optimization/rescore_formula/value_retriever.rs(now a 6-line file).formula_scorer.rsin the same module uses it as a struct field, so the type belongs there — only the helper functions move.Visibility tightening
Cross-file entry points become
pub(super). Purely-local helpers (get_range_checkers,get_float_range_checkers,get_datetime_range_checkers,get_geo_radius_checkers,get_geo_bounding_box_checkers,get_geo_polygon_checkers,get_is_empty_checker) become private. No public-API surface change.Test plan
cargo build --workspace --tests(clean)cargo test -p segment— 666 unit + 120 integration tests passcargo +nightly fmt --all -- --check(pre-push hook)🤖 Generated with Claude Code