fix (hql): fixing hql issues with exists #714
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.
Description
Related Issues
Closes #
Checklist when merging to main
rustfmthelix-cli/Cargo.tomlandhelixdb/Cargo.tomlAdditional Notes
Greptile Overview
Greptile Summary
This PR fixes critical panic issues in HQL's EXISTS operation and field validation logic. The changes replace unsafe
unwrap()calls with proper error handling using match statements.Key Changes
.unwrap()calls with match statements ininfer_expr_type.rsto gracefully handle missing schema fields/types instead of panickingbool_ops.rsto only apply when source step isIdentifierorAnonymous, preventing incorrect code generationImpact
The changes improve robustness by preventing runtime panics when users write queries with invalid field names or types that don't match the schema. Errors are now properly reported during compilation rather than causing panics.
Important Files Changed
File Analysis
Sequence Diagram
sequenceDiagram participant User as HQL Query participant Analyzer as Type Inference Analyzer participant Validator as Field Validator participant Generator as Code Generator participant Schema as Schema Store User->>Analyzer: EXISTS(N<User>({github_id: github_id})) Analyzer->>Analyzer: infer_expr_type() for EXISTS Analyzer->>Validator: Check identifier in scope or param alt Identifier not in scope and not param Validator-->>Analyzer: Generate E301 error end Analyzer->>Schema: Get node_fields for User type alt Type doesn't exist Schema-->>Analyzer: None Note over Analyzer: Skip validation, error already generated else Type exists Schema-->>Analyzer: Some(fields) Analyzer->>Schema: Get field github_id alt Field doesn't exist Schema-->>Analyzer: None Note over Analyzer: Skip validation, error already generated else Field exists Schema-->>Analyzer: Some(field) Analyzer->>Validator: Validate value type matches field type alt Type mismatch Validator-->>Analyzer: Generate E205 error end end end Analyzer->>Generator: Generate traversal code Generator->>Generator: Check if optimization applies Note over Generator: Only optimize if source is<br/>Identifier or Anonymous Generator-->>User: Generated Rust code