lora-database 0.5.5

LoraDB — embeddable in-memory graph database with Cypher query support.
Documentation
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
/// WITH clause tests — variable piping, scoping, aggregation pipelines,
/// multi-part queries, top-N patterns, chained filtering.
mod test_helpers;
use test_helpers::TestDb;

// ============================================================
// Basic piping
// ============================================================

#[test]
fn with_passes_variables() {
    let db = TestDb::new();
    db.seed_social_graph();
    let rows = db.run("MATCH (a:User) WITH a RETURN a");
    assert_eq!(rows.len(), 3);
}

#[test]
fn with_renames_variable() {
    let db = TestDb::new();
    db.run("CREATE (n:User {name: 'Alice'})");
    let rows = db.run("MATCH (n:User) WITH n.name AS name RETURN name");
    assert_eq!(rows[0]["name"], "Alice");
}

#[test]
fn with_property_access_returns_value() {
    let db = TestDb::new();
    db.run("CREATE (a:User {name: 'Alice', age: 30})");
    let rows = db.run("MATCH (n:User) WITH n RETURN n.name AS name");
    assert_eq!(rows.len(), 1);
    assert_eq!(rows[0]["name"], "Alice");
}

// ============================================================
// Filtering
// ============================================================

#[test]
fn with_filters_trivial_true() {
    let db = TestDb::new();
    db.seed_social_graph();
    let rows = db.run("MATCH (n:User) WITH n WHERE true RETURN n");
    assert_eq!(rows.len(), 3);
}

#[test]
fn with_filters_by_name() {
    let db = TestDb::new();
    db.seed_social_graph();
    let rows = db.run("MATCH (n:User) WITH n WHERE n.name = 'Alice' RETURN n");
    assert_eq!(rows.len(), 1);
}

#[test]
fn with_filters() {
    let db = TestDb::new();
    db.seed_social_graph();
    let all = db.run("MATCH (n:User) WITH n RETURN n");
    assert_eq!(all.len(), 3);
    let rows = db.run("MATCH (n:User) WITH n WHERE n.age > 28 RETURN n");
    assert_eq!(rows.len(), 2);
}

// ============================================================
// Variable scoping
// ============================================================

#[test]
fn with_hides_unmentioned_variables() {
    let db = TestDb::new();
    db.seed_social_graph();
    let err = db.run_err("MATCH (a:User {name: 'Alice'})-[r:FOLLOWS]->(b) WITH a RETURN b");
    assert!(err.contains("Unknown variable") || err.contains("variable"));
}

#[test]
fn with_hides_unselected_variables() {
    let db = TestDb::new();
    db.seed_org_graph();
    let err = db.run_err("MATCH (p:Person)-[r:WORKS_AT]->(c:Company) WITH p RETURN r");
    assert!(err.contains("Unknown variable") || err.contains("variable"));
}

#[test]
fn with_star_keeps_all_variables() {
    let db = TestDb::new();
    db.run("CREATE (:A {x:1})-[:R]->(:B {y:2})");
    let rows = db.run("MATCH (a:A)-[r:R]->(b:B) WITH * RETURN a.x AS ax, b.y AS by");
    assert_eq!(rows.len(), 1);
    assert_eq!(rows[0]["ax"], 1);
    assert_eq!(rows[0]["by"], 2);
}

// ============================================================
// Multi-part queries
// ============================================================

#[test]
fn multi_part_query_with_match_then_match() {
    let db = TestDb::new();
    db.seed_social_graph();
    let rows = db.run(
        "MATCH (a:User {name: 'Alice'})-[:FOLLOWS]->(b) \
         WITH b \
         MATCH (b)-[:FOLLOWS]->(c) \
         RETURN c",
    );
    assert_eq!(rows.len(), 1);
    assert_eq!(rows[0]["c"]["properties"]["name"], "Carol");
}

#[test]
fn pipeline_match_with_then_match() {
    let db = TestDb::new();
    db.seed_org_graph();
    let rows = db.run(
        "MATCH (p:Person)-[:LIVES_IN]->(c:City {name:'London'}) \
         WITH p \
         MATCH (p)-[:ASSIGNED_TO]->(proj:Project) \
         RETURN p.name AS person, proj.name AS project",
    );
    assert!(rows.len() >= 2);
}

// ============================================================
// WITH + ORDER BY / LIMIT
// ============================================================

#[test]
fn with_order_and_limit() {
    let db = TestDb::new();
    db.seed_social_graph();
    let rows = db.run("MATCH (n:User) WITH n ORDER BY n.name ASC LIMIT 2 RETURN n.name AS name");
    assert_eq!(rows.len(), 2);
}

#[test]
fn top_n_oldest_employees() {
    let db = TestDb::new();
    db.seed_org_graph();
    let names = db.column(
        "MATCH (p:Person) WITH p ORDER BY p.age DESC LIMIT 3 RETURN p.name AS name",
        "name",
    );
    let s: Vec<&str> = names.iter().map(|v| v.as_str().unwrap()).collect();
    assert_eq!(s.len(), 3);
    assert_eq!(s[0], "Frank");
}

// ============================================================
// WITH + aggregation
// ============================================================

#[test]
fn with_aggregation_then_filter() {
    let db = TestDb::new();
    db.run("CREATE (a:User {name: 'Alice', dept: 'eng'})");
    db.run("CREATE (b:User {name: 'Bob', dept: 'eng'})");
    db.run("CREATE (c:User {name: 'Carol', dept: 'sales'})");
    let rows =
        db.run("MATCH (n:User) WITH n.dept AS dept, count(n) AS c WHERE c > 1 RETURN dept, c");
    assert_eq!(rows.len(), 1);
    assert_eq!(rows[0]["dept"], "eng");
}

#[test]
fn pipeline_match_with_aggregate_then_filter() {
    let db = TestDb::new();
    db.seed_org_graph();
    let rows = db.run(
        "MATCH (p:Person)-[:LIVES_IN]->(c:City) \
         WITH c.name AS city, count(p) AS pop \
         WHERE pop > 1 \
         RETURN city, pop ORDER BY city",
    );
    assert_eq!(rows.len(), 2);
    assert_eq!(rows[0]["city"], "Berlin");
    assert_eq!(rows[1]["city"], "London");
}

#[test]
fn with_grouped_aggregation_pipeline() {
    let db = TestDb::new();
    db.seed_org_graph();
    let rows = db.run(
        "MATCH (p:Person) \
         WITH p.dept AS dept, count(p) AS cnt \
         WHERE cnt >= 3 \
         RETURN dept, cnt",
    );
    assert_eq!(rows.len(), 1);
    assert_eq!(rows[0]["dept"], "Engineering");
}

// ============================================================
// WITH + UNWIND
// ============================================================

#[test]
fn with_collect_then_unwind() {
    let db = TestDb::new();
    db.seed_org_graph();
    let rows =
        db.run("MATCH (p:Person) WITH collect(p.name) AS names UNWIND names AS name RETURN name");
    assert_eq!(rows.len(), 6);
}

// ============================================================
// Chained WITH
// ============================================================

#[test]
fn chained_with_narrows_progressively() {
    let db = TestDb::new();
    db.seed_org_graph();
    let rows = db.run(
        "MATCH (p:Person) \
         WITH p WHERE p.dept = 'Engineering' \
         WITH p WHERE p.age > 30 \
         RETURN p.name AS name ORDER BY p.name",
    );
    assert_eq!(rows.len(), 2);
    assert_eq!(rows[0]["name"], "Alice");
    assert_eq!(rows[1]["name"], "Frank");
}

// ============================================================
// WITH + SET
// ============================================================

#[test]
fn with_set_then_return() {
    let db = TestDb::new();
    db.run("CREATE (n:User {name: 'Alice'})");
    let rows = db.run("MATCH (n:User) SET n:Seen WITH n RETURN n");
    assert_eq!(rows.len(), 1);
    db.assert_count("MATCH (n:Seen) RETURN n", 1);
}

// ============================================================
// Mixed read-write pipeline
// ============================================================

#[test]
fn match_aggregate_then_create() {
    let db = TestDb::new();
    db.run("CREATE (:Score {val: 10})");
    db.run("CREATE (:Score {val: 20})");
    db.run("CREATE (:Score {val: 30})");
    db.run("MATCH (s:Score) WITH sum(s.val) AS total CREATE (:Summary {total: total})");
    let rows = db.run("MATCH (s:Summary) RETURN s");
    assert_eq!(rows[0]["s"]["properties"]["total"], 60);
}

// ============================================================
// WITH pipeline patterns
// ============================================================

#[test]
fn with_aggregation_filter_having_like() {
    let db = TestDb::new();
    db.seed_org_graph();
    // Group persons by city, keep only cities with more than 1 resident
    let rows = db.run(
        "MATCH (p:Person)-[:LIVES_IN]->(c:City) \
         WITH c.name AS city, count(p) AS pop \
         WHERE pop >= 3 \
         RETURN city, pop",
    );
    // London has 3 residents (Alice, Carol, Frank)
    assert_eq!(rows.len(), 1);
    assert_eq!(rows[0]["city"], "London");
    assert_eq!(rows[0]["pop"], 3);
}

#[test]
fn multi_step_with_pipeline_match_with_match_return() {
    let db = TestDb::new();
    db.seed_org_graph();
    // Find people in London, then find which projects they work on
    let rows = db.run(
        "MATCH (p:Person)-[:LIVES_IN]->(c:City {name:'London'}) \
         WITH p \
         MATCH (p)-[:ASSIGNED_TO]->(proj:Project) \
         RETURN p.name AS person, proj.name AS project ORDER BY p.name",
    );
    // Alice -> Alpha, Carol -> Beta (Frank has no project assignment)
    assert_eq!(rows.len(), 2);
    assert_eq!(rows[0]["person"], "Alice");
    assert_eq!(rows[0]["project"], "Alpha");
    assert_eq!(rows[1]["person"], "Carol");
    assert_eq!(rows[1]["project"], "Beta");
}

#[test]
fn with_introducing_computed_columns() {
    let db = TestDb::new();
    db.seed_org_graph();
    let rows = db.run(
        "MATCH (p:Person) \
         WITH p.name AS name, p.age * 2 AS double_age \
         WHERE double_age > 80 \
         RETURN name, double_age ORDER BY name",
    );
    // Alice 35*2=70 (no), Bob 28*2=56 (no), Carol 42*2=84 (yes), Dave 31*2=62 (no),
    // Eve 26*2=52 (no), Frank 50*2=100 (yes)
    assert_eq!(rows.len(), 2);
    assert_eq!(rows[0]["name"], "Carol");
    assert_eq!(rows[0]["double_age"], 84);
    assert_eq!(rows[1]["name"], "Frank");
    assert_eq!(rows[1]["double_age"], 100);
}

#[test]
fn with_pagination_order_by_skip_limit() {
    let db = TestDb::new();
    db.seed_org_graph();
    // Get 2nd and 3rd oldest persons (skip 1, limit 2)
    let names = db.column(
        "MATCH (p:Person) \
         WITH p ORDER BY p.age DESC SKIP 1 LIMIT 2 \
         RETURN p.name AS name",
        "name",
    );
    // Sorted by age DESC: Frank(50), Carol(42), Alice(35), Dave(31), Bob(28), Eve(26)
    // Skip 1 = skip Frank, Limit 2 = Carol, Alice
    assert_eq!(names.len(), 2);
    assert_eq!(names[0].as_str().unwrap(), "Carol");
    assert_eq!(names[1].as_str().unwrap(), "Alice");
}

#[test]
fn with_collect_then_unwind_round_trip() {
    let db = TestDb::new();
    db.run("CREATE (:Tag {name:'a'})");
    db.run("CREATE (:Tag {name:'b'})");
    db.run("CREATE (:Tag {name:'c'})");
    let names = db.sorted_strings(
        "MATCH (t:Tag) \
         WITH collect(t.name) AS tags \
         UNWIND tags AS tag \
         RETURN tag",
        "tag",
    );
    assert_eq!(names, vec!["a", "b", "c"]);
}

// ============================================================
// WITH scope isolation
// ============================================================

#[test]
fn with_variables_before_not_visible_after() {
    let db = TestDb::new();
    db.seed_social_graph();
    // After WITH a, the variable r should not be accessible
    let err = db.run_err(
        "MATCH (a:User)-[r:FOLLOWS]->(b:User) \
         WITH a \
         RETURN r",
    );
    assert!(err.contains("Unknown variable") || err.contains("variable"));
}

#[test]
fn with_passes_only_listed_variables() {
    let db = TestDb::new();
    db.seed_org_graph();
    // Pass only c through WITH — p should not be visible after
    let err = db.run_err(
        "MATCH (p:Person)-[:LIVES_IN]->(c:City) \
         WITH c \
         RETURN p.name AS name",
    );
    assert!(err.contains("Unknown variable") || err.contains("variable"));
}

#[test]
fn with_alias_rename() {
    let db = TestDb::new();
    db.run("CREATE (:Item {val: 42})");
    let rows = db.run(
        "MATCH (n:Item) \
         WITH n.val AS renamed_value \
         RETURN renamed_value",
    );
    assert_eq!(rows.len(), 1);
    assert_eq!(rows[0]["renamed_value"], 42);
}

#[test]
fn with_alias_rename_hides_original() {
    let db = TestDb::new();
    db.run("CREATE (:Item {val: 42})");
    // After renaming n to x, the original variable n should be gone
    let err = db.run_err(
        "MATCH (n:Item) \
         WITH n AS x \
         RETURN n.val",
    );
    assert!(err.contains("Unknown variable") || err.contains("variable"));
}

// ============================================================
// Ignored WITH tests (pending implementation)
// ============================================================

#[test]
fn with_order_by_within_pipeline() {
    // Lora: WITH ... ORDER BY within pipeline
    let db = TestDb::new();
    db.seed_org_graph();
    // ORDER BY inside WITH without LIMIT should preserve ordering for later stages
    let names = db.column(
        "MATCH (p:Person) \
         WITH p ORDER BY p.name ASC \
         RETURN p.name AS name",
        "name",
    );
    assert_eq!(names[0].as_str().unwrap(), "Alice");
    assert_eq!(names[5].as_str().unwrap(), "Frank");
}

#[test]
fn with_star_passes_all_variables_complex() {
    // Lora: WITH * passes all variables
    let db = TestDb::new();
    db.seed_org_graph();
    let rows = db.run(
        "MATCH (p:Person)-[r:WORKS_AT]->(c:Company) \
         WITH * \
         WHERE p.dept = 'Engineering' \
         RETURN p.name AS name, c.name AS company",
    );
    assert_eq!(rows.len(), 4); // Alice, Bob, Eve, Frank
}

#[test]
fn with_distinct_deduplication() {
    // Lora: WITH DISTINCT deduplication
    let db = TestDb::new();
    db.seed_org_graph();
    let rows = db.run(
        "MATCH (p:Person)-[:LIVES_IN]->(c:City) \
         WITH DISTINCT c.name AS city \
         RETURN city ORDER BY city",
    );
    // Berlin, London, Tokyo — deduplicated
    assert_eq!(rows.len(), 3);
    assert_eq!(rows[0]["city"], "Berlin");
    assert_eq!(rows[1]["city"], "London");
    assert_eq!(rows[2]["city"], "Tokyo");
}

// ============================================================
// Extended WITH: query pipelining and scoping
// ============================================================

#[test]
fn with_filters_then_aggregates() {
    let db = TestDb::new();
    db.seed_org_graph();
    let rows = db.run(
        "MATCH (p:Person)-[:WORKS_AT]->(c:Company) \
         WITH p WHERE p.age > 30 \
         RETURN count(p) AS senior_count",
    );
    assert_eq!(rows.len(), 1);
    assert!(rows[0]["senior_count"].as_i64().unwrap() >= 2);
}

#[test]
fn with_computed_value_in_next_match() {
    let db = TestDb::new();
    db.seed_org_graph();
    let rows = db.run(
        "MATCH (p:Person) \
         WITH avg(p.age) AS avg_age \
         MATCH (p2:Person) WHERE p2.age > avg_age \
         RETURN p2.name AS name ORDER BY name",
    );
    assert!(!rows.is_empty());
}

#[test]
fn with_limit_then_collect() {
    let db = TestDb::new();
    db.seed_org_graph();
    let rows = db.run(
        "MATCH (p:Person) \
         WITH p ORDER BY p.age DESC LIMIT 3 \
         RETURN collect(p.name) AS top3",
    );
    let names = rows[0]["top3"].as_array().unwrap();
    assert_eq!(names.len(), 3);
}

#[test]
fn with_unwind_then_aggregate() {
    let db = TestDb::new();
    let rows = db.run(
        "WITH [1, 2, 3, 4, 5] AS nums \
         UNWIND nums AS n \
         RETURN sum(n) AS total, count(n) AS cnt",
    );
    assert_eq!(rows[0]["total"], 15);
    assert_eq!(rows[0]["cnt"], 5);
}

#[test]
fn with_multiple_stages() {
    let db = TestDb::new();
    db.seed_org_graph();
    let rows = db.run(
        "MATCH (p:Person)-[:WORKS_AT]->(c:Company) \
         WITH p.dept AS dept, count(p) AS cnt \
         WITH dept, cnt WHERE cnt > 1 \
         RETURN dept, cnt ORDER BY dept",
    );
    assert!(!rows.is_empty());
    for row in &rows {
        assert!(row["cnt"].as_i64().unwrap() > 1);
    }
}

#[test]
fn with_distinct_pass_through() {
    let db = TestDb::new();
    db.seed_org_graph();
    let rows = db.run(
        "MATCH (p:Person)-[:LIVES_IN]->(c:City) \
         WITH DISTINCT c.name AS city \
         RETURN city ORDER BY city",
    );
    // Should be deduplicated cities
    let cities: Vec<&str> = rows.iter().map(|r| r["city"].as_str().unwrap()).collect();
    let mut deduped = cities.clone();
    deduped.dedup();
    assert_eq!(cities, deduped);
}

#[test]
fn with_preserves_variables_explicitly() {
    let db = TestDb::new();
    db.run("CREATE (:P {name: 'Alice', age: 30})");
    // After WITH, only passed-through variables are visible
    let rows = db.run(
        "MATCH (p:P) \
         WITH p.name AS name \
         RETURN name",
    );
    assert_eq!(rows[0]["name"], "Alice");
}

// ============================================================
// Complex three-stage pipeline
// ============================================================

#[test]
fn with_three_stage_pipeline() {
    let db = TestDb::new();
    db.seed_org_graph();
    // Stage 1: match + filter. Stage 2: aggregate. Stage 3: filter aggregation result
    let rows = db.run(
        "MATCH (p:Person)-[:LIVES_IN]->(c:City) \
         WITH c.name AS city, collect(p.name) AS people, count(p) AS pop \
         WITH city, people, pop WHERE pop >= 2 \
         RETURN city, pop ORDER BY pop DESC",
    );
    // London(3), Berlin(2) — Tokyo(1) filtered out
    assert_eq!(rows.len(), 2);
    assert_eq!(rows[0]["city"], "London");
    assert_eq!(rows[0]["pop"], 3);
    assert_eq!(rows[1]["city"], "Berlin");
    assert_eq!(rows[1]["pop"], 2);
}

// ============================================================
// WITH + OPTIONAL MATCH
// ============================================================

#[test]
fn with_followed_by_optional_match() {
    let db = TestDb::new();
    db.seed_org_graph();
    // Get engineering people, then optionally find their projects
    let rows = db.run(
        "MATCH (p:Person) WHERE p.dept = 'Engineering' \
         WITH p \
         OPTIONAL MATCH (p)-[:ASSIGNED_TO]->(proj:Project) \
         RETURN p.name AS name, proj.name AS project ORDER BY p.name",
    );
    // Alice->Alpha, Bob->Alpha, Eve->Beta, Frank->null
    assert_eq!(rows.len(), 4);
    let frank = rows.iter().find(|r| r["name"] == "Frank").unwrap();
    assert!(frank["project"].is_null());
}

// ============================================================
// WITH + CASE expression
// ============================================================

#[test]
fn with_case_in_pipeline() {
    let db = TestDb::new();
    db.seed_org_graph();
    let rows = db.run(
        "MATCH (p:Person) \
         WITH p.name AS name, \
              CASE WHEN p.age >= 40 THEN 'senior' \
                   WHEN p.age >= 30 THEN 'mid' \
                   ELSE 'junior' END AS tier \
         RETURN tier, collect(name) AS people ORDER BY tier",
    );
    assert_eq!(rows.len(), 3);
}

// ============================================================
// WITH for top-N per group pattern
// ============================================================

#[test]
fn with_top_n_per_group() {
    let db = TestDb::new();
    db.seed_recommendation_graph();
    // Highest rated movie per viewer using max(score)
    let rows = db.run(
        "MATCH (v:Viewer)-[r:RATED]->(m:Movie) \
         RETURN v.name AS viewer, max(r.score) AS top_score \
         ORDER BY viewer",
    );
    assert_eq!(rows.len(), 3);
    assert_eq!(rows[0]["viewer"], "Alice");
    assert_eq!(rows[0]["top_score"], 5); // Matrix
    assert_eq!(rows[1]["viewer"], "Bob");
    assert_eq!(rows[1]["top_score"], 5); // Matrix
    assert_eq!(rows[2]["viewer"], "Carol");
    assert_eq!(rows[2]["top_score"], 5); // Inception
}

// ============================================================
// WITH + UNWIND + aggregation round-trip
// ============================================================

#[test]
fn with_unwind_filter_reaggregate() {
    let db = TestDb::new();
    db.seed_org_graph();
    // Collect all ages, unwind, filter > 30, count
    let rows = db.run(
        "MATCH (p:Person) \
         WITH collect(p.age) AS ages \
         UNWIND ages AS age \
         WITH age WHERE age > 30 \
         RETURN count(age) AS senior_count, min(age) AS youngest_senior",
    );
    // > 30: Alice(35), Carol(42), Dave(31), Frank(50) = 4
    assert_eq!(rows[0]["senior_count"], 4);
    assert_eq!(rows[0]["youngest_senior"], 31);
}

// ============================================================
// Ignored WITH tests
// ============================================================

#[test]
#[ignore = "pending implementation"]
fn with_call_subquery() {
    let db = TestDb::new();
    db.seed_org_graph();
    let _rows = db.run(
        "MATCH (p:Person) \
         CALL { WITH p MATCH (p)-[:MANAGES]->(s) RETURN count(s) AS subs } \
         RETURN p.name, subs",
    );
}