Commit 4be937f
Dylan Bobby Storey
fix(varlen): T-0309 — RETURN of varlen rel emits JSON array of edges
Variable-length pattern bindings `[r*N..M]` reference a recursive CTE
whose alias has columns start_id/end_id/depth/path_ids/visited — not
edge fields. The previous RETURN projector emitted a single-edge JSON
template (`json_object('id', alias.id, 'type', alias.type, ...)`),
producing 'no such column: _gql_default_alias_N.id' for every
varlen-rel projection.
Three coordinated changes:
1. transform_match.c (line ~1145): when registering a varlen rel
variable, stamp `transform_var->cte_name` with the CTE name. This
marks the var as varlen-bound so downstream code branches
appropriately.
2. transform_return.c (line ~956): in the AST_NODE_IDENTIFIER edge-
variable projector, branch on `evar->cte_name`. When set, emit:
(SELECT json_group_array(json_object('id', e.id, 'type', e.type, ...))
FROM edges e WHERE e.id IN (SELECT CAST(value AS INTEGER)
FROM json_each('[' || alias.path_ids || ']'))
ORDER BY instr(',' || alias.path_ids || ',', ',' || e.id || ','))
instead of the single-edge template. Path-order preservation via
`instr` on the comma-separated path_ids string.
3. executor_match.c + extension.c: build_query_results identifies
varlen edge vars (`evar->cte_name`) and skips the single-edge re-
fetch (atoll(value) → fetch by id), leaving `result->data[row][col]`
as the verbatim JSON array text. The result renderer in
extension.c then falls back to text data when agtype_data is NULL
(gated on the pointer being NULL, not on agtype_value_to_string
returning NULL — that function returns 'null' for NULL input).
Result rendering (verified manually):
MATCH (a)-[r*1..1]->(b) RETURN r
=> [{"r": [{"id":1,"type":"T",...}]}] (was: error)
MATCH (a)-[r*1..2]->(b) RETURN r over a->b->c
=> 4 rows: [[T1]], [[T1,T2]], [[T2]], [[]] (was: error)
MATCH ()-[r:T]->() RETURN r
=> [{"r": {"id":1,"type":"T",...}}] (unchanged — non-varlen)
TCK delta: pass=3458 -> 3461 (+3), errors=84 -> 79 (-5), fails=284
-> 286 (+2). The 5 `_gql_default_alias` errors that flipped:
- Match4 [1] Handling fixed-length variable length pattern
- Match9 [1] Variable length relationship variables are lists of relationships
- (+ 3 others that moved error → pass or error → fail)
944/944 unit, functional clean.1 parent 00b5ff4 commit 4be937f
4 files changed
Lines changed: 102 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
421 | 431 | | |
422 | 432 | | |
423 | 433 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1149 | 1149 | | |
1150 | 1150 | | |
1151 | 1151 | | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
1152 | 1159 | | |
1153 | 1160 | | |
1154 | 1161 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
954 | 954 | | |
955 | 955 | | |
956 | 956 | | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
957 | 990 | | |
958 | 991 | | |
959 | 992 | | |
| |||
980 | 1013 | | |
981 | 1014 | | |
982 | 1015 | | |
| 1016 | + | |
983 | 1017 | | |
984 | 1018 | | |
985 | 1019 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | | - | |
152 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
153 | 160 | | |
154 | 161 | | |
155 | | - | |
| 162 | + | |
156 | 163 | | |
157 | 164 | | |
158 | | - | |
| 165 | + | |
159 | 166 | | |
160 | 167 | | |
161 | 168 | | |
162 | | - | |
| 169 | + | |
163 | 170 | | |
164 | 171 | | |
165 | 172 | | |
| |||
176 | 183 | | |
177 | 184 | | |
178 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
179 | 189 | | |
180 | 190 | | |
181 | 191 | | |
| |||
203 | 213 | | |
204 | 214 | | |
205 | 215 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
211 | 226 | | |
212 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
213 | 235 | | |
214 | 236 | | |
215 | 237 | | |
| |||
230 | 252 | | |
231 | 253 | | |
232 | 254 | | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
238 | 264 | | |
239 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
240 | 273 | | |
241 | 274 | | |
242 | 275 | | |
| |||
0 commit comments