fix(hql): Fixing count type checking #854
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
Fixed type checking for
Counttype in boolean expressions and added code generation support for WHERE clauses with multi-step traversals before property access (fixes #847).Key Changes:
Type::Countcase mapping toFieldType::I64intraversal_validation.rs:888traversal_steps.rs:837-937ToN/FromNwithIDaccess and property fetchesImplementation Details:
The new codegen handles patterns like
_::ToN::ID::EQ(id)by:_::ToN)G::from_iterto execute the traversal chainThe code properly handles both reserved properties (
ID,Label) and user-defined properties with appropriate getter methods.Important Files Changed
Type::Countcase to map toFieldType::I64in boolean expression type checkingToN,FromNwithIDand property fetchesSequence Diagram
sequenceDiagram participant User as Query Code participant Parser as HQL Parser participant Analyzer as Type Analyzer participant Generator as Code Generator participant Runtime as Generated Rust Code User->>Parser: Parse WHERE clause with traversal Note over Parser: WHERE(_::ToN::ID::EQ(id)) Parser->>Analyzer: Validate traversal steps alt Type::Count in boolean expression Analyzer->>Analyzer: Check expression type Note over Analyzer: (Type::Count, _) => FieldType::I64 Analyzer->>Generator: Type validated as I64 else Type::Boolean in boolean expression Analyzer->>Analyzer: Map to FieldType::Boolean Analyzer->>Generator: Type validated as Boolean else Type::Scalar in boolean expression Analyzer->>Analyzer: Use existing FieldType Analyzer->>Generator: Type validated end Generator->>Generator: Check pattern: steps > 2? alt Pattern: [...] + PropertyAccess + BoolOp Generator->>Generator: Extract prefix steps Generator->>Generator: Build traversal chain alt Case: ReservedPropertyAccess (ID/Label) Generator->>Runtime: Generate filter_ref with G::from_iter Note over Runtime: Access node.id() or node.label() else Case: PropertyFetch Generator->>Runtime: Generate filter_ref with get_property Note over Runtime: Access node.get_property(name) end else Simple 2-step pattern Generator->>Runtime: Use optimized short path end Runtime->>User: Return filtered results