Commit 6a748ae
authored
fix(hql+core): fixing nested ID, math ops (#844)
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR implements comprehensive math operations support in HQL and
fixes nested ID field access.
**Key Changes:**
- Implemented `Value` type arithmetic operators (`Add`, `Sub`, `Mul`,
`Div`, `Rem`) with automatic type coercion between integer and float
types
- Added special math methods to `Value`: `pow()`, `abs()`, `sqrt()`,
`min()`, `max()`
- Created new `computed_expr.rs` module for generating Rust code from
HQL math function calls (ADD, SUB, MUL, DIV, POW, MOD, ABS, SQRT, MIN,
MAX)
- Fixed nested ID access by including implicit fields when `has_spread`
is true in query validation
- Extended object validation to detect and store math function calls as
computed expressions
- Integrated computed expression generation into query code generation
pipeline
- Added comprehensive test suite covering all math operations with
various scenarios
**Previous Issues Addressed:**
All previously reported missing method implementations have been
resolved:
- `pow(&Value)`, `abs()`, `sqrt()`, `min(&Value)`, `max(&Value)` methods
implemented
- `Rem` trait implemented for modulo operations
- `to_f64()` helper method added (as private) for type conversions
**Issues Found:**
- Minor syntax issue in `min()` and `max()` code generation (missing `&`
before reference parameter)
<details><summary><h3>Important Files Changed</h3></summary>
| Filename | Overview |
|----------|----------|
| helix-db/src/protocol/value.rs | Added comprehensive math operator
implementations (Add, Sub, Mul, Div, Rem) with type coercion and special
methods (pow, abs, sqrt, min, max) to support computed expressions |
| helix-db/src/helixc/generator/computed_expr.rs | New module for
generating Rust code from math function calls in HQL queries, handles
ADD, SUB, MUL, DIV, POW, MOD, ABS, SQRT, MIN, MAX |
| helix-db/src/helixc/analyzer/methods/query_validation.rs | Fixed
nested ID access by including implicit fields when has_spread is true,
added support for computed expression fields in return types |
| helix-db/src/helixc/generator/queries.rs | Integrated computed
expression generation into query code generation, handling
ComputedExpression field sources across single/collection/aggregate
returns |
| helix-db/src/helixc/analyzer/methods/object_validation.rs | Extended
property access validation to detect and store MathFunctionCall
expressions as computed expressions |
</details>
</details>
<details><summary><h3>Sequence Diagram</h3></summary>
```mermaid
sequenceDiagram
participant HQL as HQL Query
participant Parser as Parser
participant ObjVal as Object Validator
participant QueryVal as Query Validator
participant CodeGen as Code Generator
participant ComputedExpr as Computed Expr Generator
participant Value as Value Type
HQL->>Parser: Parse query with math expression<br/>(e.g., ADD(_::Out<HasCluster>::COUNT, 10))
Parser->>ObjVal: validate_property_access()
ObjVal->>ObjVal: Detect MathFunctionCall expression
ObjVal->>ObjVal: Store as ComputedExpressionInfo<br/>in traversal.computed_expressions
ObjVal->>QueryVal: Continue validation
QueryVal->>QueryVal: build_return_fields()
QueryVal->>QueryVal: Add computed expression fields<br/>with ReturnFieldSource::ComputedExpression
QueryVal->>QueryVal: Fix nested ID access:<br/>Include implicit fields when has_spread
QueryVal->>CodeGen: Generate query code
CodeGen->>CodeGen: Process ReturnFieldInfo
CodeGen->>ComputedExpr: generate_computed_expression(expression, item_var)
ComputedExpr->>ComputedExpr: Match MathFunction type<br/>(ADD, SUB, MUL, DIV, POW, etc.)
ComputedExpr->>ComputedExpr: Recursively generate args
ComputedExpr-->>CodeGen: Return Rust code<br/>(e.g., "(count1) + (10)")
CodeGen->>CodeGen: Emit struct field initialization<br/>with computed expression
Note over Value: Runtime execution
Value->>Value: Execute operator (Add, Sub, Mul, Div, Rem)
Value->>Value: Perform type coercion<br/>(int->float, cross-type ops)
Value->>Value: Execute special methods<br/>(pow, abs, sqrt, min, max)
Value-->>HQL: Return computed Value result
```
</details>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->File tree
21 files changed
+3390
-233
lines changed- helix-db/src
- helixc
- analyzer/methods
- generator
- parser
- protocol
- hql-tests/tests
- full_project
- math
- migrations
21 files changed
+3390
-233
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
234 | 234 | | |
235 | 235 | | |
236 | 236 | | |
237 | | - | |
| 237 | + | |
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
| |||
Lines changed: 12 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
408 | | - | |
| 408 | + | |
409 | 409 | | |
410 | 410 | | |
411 | | - | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
412 | 422 | | |
413 | 423 | | |
414 | 424 | | |
| |||
Lines changed: 29 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
| 147 | + | |
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
154 | | - | |
| 154 | + | |
155 | 155 | | |
156 | | - | |
| 156 | + | |
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
180 | | - | |
| 179 | + | |
| 180 | + | |
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
201 | | - | |
| 201 | + | |
202 | 202 | | |
203 | 203 | | |
204 | 204 | | |
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
| 225 | + | |
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | | - | |
| 246 | + | |
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
| 268 | + | |
269 | 269 | | |
270 | 270 | | |
271 | 271 | | |
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
289 | | - | |
| 289 | + | |
290 | 290 | | |
291 | 291 | | |
292 | 292 | | |
| |||
321 | 321 | | |
322 | 322 | | |
323 | 323 | | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
324 | 329 | | |
325 | 330 | | |
326 | 331 | | |
| |||
734 | 739 | | |
735 | 740 | | |
736 | 741 | | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
737 | 753 | | |
738 | 754 | | |
739 | 755 | | |
| |||
1004 | 1020 | | |
1005 | 1021 | | |
1006 | 1022 | | |
| 1023 | + | |
1007 | 1024 | | |
1008 | 1025 | | |
1009 | 1026 | | |
| |||
1336 | 1353 | | |
1337 | 1354 | | |
1338 | 1355 | | |
1339 | | - | |
| 1356 | + | |
1340 | 1357 | | |
1341 | 1358 | | |
1342 | 1359 | | |
| |||
1349 | 1366 | | |
1350 | 1367 | | |
1351 | 1368 | | |
| 1369 | + | |
1352 | 1370 | | |
1353 | 1371 | | |
1354 | 1372 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
0 commit comments