feat(hql): Intersect function #860
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Greptile Overview
Greptile Summary
This PR adds a new
INTERSECTtraversal step to HelixQL end-to-end: Pest grammar support, parserStepType::Intersect, analyzer validation and codegen, plus a new engine adapter (IntersectAdapter) and multiple test fixtures (engine-level Rust tests and HQL tests).At runtime, the engine implementation collects upstream items, executes a provided sub-traversal closure per item to get candidate results, then returns only values whose IDs appear in every sub-result set (set intersection semantics). The generator emits
.intersect(|val, db, txn, arena| { G::from_iter(..) <substeps> ... })to wire the HQL syntax to the engine adapter.Main issue to address before merge: one existing HQL test (
user_test_12) changes the meaning ofGetIndicatorsWithTimeParamsfrom “has any matching time parameter” to “connected to all matching time parameters provided”, which will change expected results when multipletime_valsare passed and should be clarified/adjusted.Important Files Changed
INTERSECT(_::<traversal>)as a new util step in the Pest grammar.intersect(...)closure code (currently drops sub-traversal errors).intersect_stepinto StepType::Intersect using parse_expression.itemparam and pass it to Embed().Sequence Diagram
sequenceDiagram participant User as HQL User participant Parser as helixc parser (pest) participant Analyzer as helixc analyzer participant Gen as helixc generator participant Engine as traversal engine User->>Parser: Parse traversal with ::INTERSECT(_::<sub-traversal>) Parser->>Analyzer: Emit StepType::Intersect(Expression) Analyzer->>Analyzer: infer_expr_type(expr, Some(cur_ty)) Analyzer->>Gen: GenerateStep::Intersect { traversal } Gen->>Engine: Emit Rust: .intersect(|val, db, txn, arena| G::from_iter(..).<substeps>...) Engine->>Engine: Collect upstream values loop for each upstream value Engine->>Engine: Run sub-traversal closure => Vec<TraversalValue> end Engine->>Engine: Intersect result sets by TraversalValue.id() Engine-->>User: Iterator of intersected TraversalValue results