fix (hql): fixing hql with inner traversals #718
Merged
+501
−41
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
Optimized HQL compiler to handle inner traversals in WHERE clause comparisons. Previously, comparing properties from different variables (e.g.,
_::{login}::EQ(toUser::{login})) would generate inefficient code with unnecessaryG::from_itercalls. The fix introducesPropertyEqandPropertyNeqoperators that detect simple property access patterns and generate directget_property()calls instead.Key Changes:
is_simple_property_traversal()helper that identifies property-only traversals (no graph navigation)PropertyEqandPropertyNeqboolean operators for optimized property comparisonstraversal_validation.rsto use optimized path for simple casesImpact:
CheckFollowsEdgethat filter edges by comparing properties across variablesImportant Files Changed
File Analysis
is_simple_property_traversalhelper function and optimized Equal/NotEqual operators to use PropertyEq/PropertyNeq for simple property access, avoiding unnecessaryG::from_itercallsget_propertyinstead of creating full traversalsCheckFollowsEdgequery that uses inner traversal comparison pattern_::{login}::EQ(toUser::{login})Sequence Diagram
sequenceDiagram participant User as HQL Query participant Analyzer as traversal_validation.rs participant BoolOps as bool_ops.rs participant Generator as traversal_steps.rs participant Output as Generated Rust Code User->>Analyzer: WHERE(_::{login}::EQ(toUser::{login})) Analyzer->>Analyzer: Validate BooleanOpType::Equal Analyzer->>Analyzer: Check if RHS is ExpressionType::Traversal Analyzer->>Analyzer: Call is_simple_property_traversal() alt Simple property traversal Analyzer->>Analyzer: Detected: toUser::{login} Analyzer->>BoolOps: Create PropertyEq(var: "toUser", property: "login") BoolOps->>Generator: Pass PropertyEq to WhereRef Generator->>Output: Generate: toUser.get_property("login").map_or(false, |w| w == v) else Complex traversal Analyzer->>Analyzer: Parse full traversal with validate_traversal() Analyzer->>BoolOps: Create Eq with GeneratedValue::Traversal BoolOps->>Generator: Pass Eq with traversal Generator->>Output: Generate: G::from_iter(...) comparison end