interstellar 0.2.0

A high-performance graph database with Gremlin-style traversals and GQL query language
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
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
//! Predicate integration tests with has_where
//!
//! Tests for comparison, range, string, and composed predicates.

#![allow(unused_variables)]
use std::collections::HashMap;

use interstellar::p;
use interstellar::storage::Graph;
use interstellar::traversal::__;
use interstellar::value::{Value, VertexId};

use crate::common::graphs::create_small_graph;

// -------------------------------------------------------------------------
// Comparison Predicates with has_where
// -------------------------------------------------------------------------

#[test]
fn has_where_eq_filters_by_property_value() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age exactly 30
    let results = g.v().has_where("age", p::eq(30)).to_list();

    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.alice));
}

#[test]
fn has_where_neq_filters_out_property_value() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age not equal to 30
    // Bob (25), Charlie (35) should match; Alice (30) should not
    let results = g
        .v()
        .has_label("person")
        .has_where("age", p::neq(30))
        .to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.bob));
    assert!(ids.contains(&tg.charlie));
    assert!(!ids.contains(&tg.alice));
}

#[test]
fn has_where_gte_filters_correctly() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age >= 30
    // Alice (30), Charlie (35) should match; Bob (25) should not
    let results = g.v().has_where("age", p::gte(30)).to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.alice));
    assert!(ids.contains(&tg.charlie));
}

#[test]
fn has_where_gt_filters_correctly() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age > 30
    // Only Charlie (35) should match
    let results = g.v().has_where("age", p::gt(30)).to_list();

    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.charlie));
}

#[test]
fn has_where_lt_filters_correctly() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age < 30
    // Only Bob (25) should match
    let results = g.v().has_where("age", p::lt(30)).to_list();

    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.bob));
}

#[test]
fn has_where_lte_filters_correctly() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age <= 30
    // Alice (30), Bob (25) should match; Charlie (35) should not
    let results = g.v().has_where("age", p::lte(30)).to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.alice));
    assert!(ids.contains(&tg.bob));
}

#[test]
fn has_where_cross_type_comparison() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Float predicate value compared against Int property
    // age >= 29.5 should match Alice (30), Charlie (35)
    let results = g.v().has_where("age", p::gte(29.5f64)).to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.alice));
    assert!(ids.contains(&tg.charlie));
}

#[test]
fn has_where_missing_property_filters_out() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // GraphDB has no "age" property, should be filtered out
    // All person vertices have age
    let results = g.v().has_where("age", p::gte(0)).to_list();

    assert_eq!(results.len(), 3); // Only persons, not GraphDB

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(!ids.contains(&tg.graphdb));
}

// -------------------------------------------------------------------------
// Range Predicates with has_where
// -------------------------------------------------------------------------

#[test]
fn has_where_between_filters_range() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age in [25, 35)
    // Alice (30), Bob (25) should match; Charlie (35) should not (exclusive end)
    let results = g.v().has_where("age", p::between(25, 35)).to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.alice));
    assert!(ids.contains(&tg.bob));
    assert!(!ids.contains(&tg.charlie));
}

#[test]
fn has_where_between_inclusive_start() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age in [30, 40)
    // Start value is inclusive: Alice (30), Charlie (35) should match
    let results = g.v().has_where("age", p::between(30, 40)).to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.alice));
    assert!(ids.contains(&tg.charlie));
}

#[test]
fn has_where_between_exclusive_end() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age in [20, 30)
    // End value is exclusive: only Bob (25) should match
    let results = g.v().has_where("age", p::between(20, 30)).to_list();

    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.bob));
}

#[test]
fn has_where_inside_filters_exclusive() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age in (25, 35) - exclusive both ends
    // Only Alice (30) should match; Bob (25), Charlie (35) at boundaries excluded
    let results = g.v().has_where("age", p::inside(25, 35)).to_list();

    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.alice));
}

#[test]
fn has_where_inside_excludes_boundaries() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for age in (29, 31) - should only match Alice (30)
    let results = g.v().has_where("age", p::inside(29, 31)).to_list();

    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.alice));
}

#[test]
fn has_where_outside_filters_outside_range() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age outside [26, 34]
    // Bob (25) < 26: matches; Alice (30) in range: doesn't match; Charlie (35) > 34: matches
    let results = g.v().has_where("age", p::outside(26, 34)).to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.bob));
    assert!(ids.contains(&tg.charlie));
    assert!(!ids.contains(&tg.alice));
}

#[test]
fn has_where_outside_boundaries_not_outside() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age outside [25, 35]
    // Boundaries are NOT outside, so Bob (25) and Charlie (35) don't match
    // Alice (30) is inside the range so doesn't match either
    let results = g.v().has_where("age", p::outside(25, 35)).to_list();

    assert!(results.is_empty());
}

// -------------------------------------------------------------------------
// String Predicates with has_where
// -------------------------------------------------------------------------

#[test]
fn has_where_starting_with_filters_strings() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with name starting with "A"
    // Alice should match
    let results = g.v().has_where("name", p::starting_with("A")).to_list();

    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.alice));
}

#[test]
fn has_where_starting_with_multiple_matches() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with name starting with "C" or "G"
    // Charlie and GraphDB start with different letters, neither matches
    // Let's check for names starting with "B"
    let results = g.v().has_where("name", p::starting_with("B")).to_list();

    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.bob));
}

#[test]
fn has_where_ending_with_filters_strings() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with name ending with "e"
    // Alice and Charlie both end with "e"
    let results = g.v().has_where("name", p::ending_with("e")).to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.alice));
    assert!(ids.contains(&tg.charlie));
}

#[test]
fn has_where_ending_with_no_matches() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with name ending with "z"
    // No names end with "z"
    let results = g.v().has_where("name", p::ending_with("z")).to_list();

    assert!(results.is_empty());
}

#[test]
fn has_where_containing_filters_strings() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with name containing "li"
    // Alice, Charlie both contain "li"
    let results = g.v().has_where("name", p::containing("li")).to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.alice));
    assert!(ids.contains(&tg.charlie));
}

#[test]
fn has_where_containing_single_match() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with name containing "ob"
    // Only Bob contains "ob"
    let results = g.v().has_where("name", p::containing("ob")).to_list();

    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.bob));
}

#[test]
fn has_where_string_predicate_on_non_string_property_fails() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Apply string predicate to numeric property - should match nothing
    // age is Int, not String
    let results = g.v().has_where("age", p::containing("3")).to_list();

    assert!(results.is_empty());
}

#[test]
fn has_where_regex_filters_strings() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with name matching regex "^[AB].*"
    // Alice and Bob start with A or B
    let results = g.v().has_where("name", p::regex("^[AB].*")).to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.alice));
    assert!(ids.contains(&tg.bob));
}

#[test]
fn has_where_regex_exact_match() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for name exactly "Bob"
    let results = g.v().has_where("name", p::regex("^Bob$")).to_list();

    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.bob));
}

// -------------------------------------------------------------------------
// Composed Predicates with has_where
// -------------------------------------------------------------------------

#[test]
fn has_where_and_composed_predicate() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age >= 25 AND age <= 30
    // Alice (30), Bob (25) should match; Charlie (35) should not
    let results = g
        .v()
        .has_where("age", p::and(p::gte(25), p::lte(30)))
        .to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.alice));
    assert!(ids.contains(&tg.bob));
}

#[test]
fn has_where_or_composed_predicate() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age == 25 OR age == 35
    // Bob (25), Charlie (35) should match; Alice (30) should not
    let results = g
        .v()
        .has_where("age", p::or(p::eq(25), p::eq(35)))
        .to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.bob));
    assert!(ids.contains(&tg.charlie));
}

#[test]
fn has_where_not_composed_predicate() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age NOT equal to 30
    // Bob (25), Charlie (35) should match; Alice (30) should not
    let results = g
        .v()
        .has_label("person")
        .has_where("age", p::not(p::eq(30)))
        .to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.bob));
    assert!(ids.contains(&tg.charlie));
}

#[test]
fn has_where_complex_nested_predicate() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for: (age >= 30 AND age < 35) OR age == 25
    // Matches: Alice (30 >= 30 AND 30 < 35), Bob (25 == 25)
    // Does not match: Charlie (35 is NOT < 35 AND 35 != 25)
    let results = g
        .v()
        .has_where("age", p::or(p::and(p::gte(30), p::lt(35)), p::eq(25)))
        .to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.alice));
    assert!(ids.contains(&tg.bob));
}

#[test]
fn has_where_and_with_string_predicates() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for names that start with a letter and contain specific substring
    // Names starting with "A" AND containing "lic" -> Alice
    let results = g
        .v()
        .has_where("name", p::and(p::starting_with("A"), p::containing("lic")))
        .to_list();

    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.alice));
}

#[test]
fn has_where_or_with_string_predicates() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for names ending with "b" OR containing "arl"
    // Bob ends with "b", Charlie contains "arl"
    let results = g
        .v()
        .has_where("name", p::or(p::ending_with("b"), p::containing("arl")))
        .to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.bob));
    assert!(ids.contains(&tg.charlie));
}

#[test]
fn has_where_not_with_between() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for ages NOT in [26, 34]
    // Bob (25) and Charlie (35) should match
    let results = g
        .v()
        .has_label("person")
        .has_where("age", p::not(p::between(26, 35)))
        .to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.bob));
    assert!(ids.contains(&tg.charlie));
}

// -------------------------------------------------------------------------
// Collection Predicates with has_where
// -------------------------------------------------------------------------

#[test]
fn has_where_within_filters_by_set_membership() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age in {25, 35}
    // Bob (25), Charlie (35) should match
    let results = g.v().has_where("age", p::within([25i64, 35i64])).to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.bob));
    assert!(ids.contains(&tg.charlie));
}

#[test]
fn has_where_without_filters_by_exclusion() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for vertices with age NOT in {25, 35}
    // Only Alice (30) should match
    let results = g
        .v()
        .has_label("person")
        .has_where("age", p::without([25i64, 35i64]))
        .to_list();

    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.alice));
}

#[test]
fn has_where_within_with_strings() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter for names in {"Alice", "Charlie"}
    let results = g
        .v()
        .has_where("name", p::within(["Alice", "Charlie"]))
        .to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.alice));
    assert!(ids.contains(&tg.charlie));
}

// -------------------------------------------------------------------------
// Edge Property Tests with has_where
// -------------------------------------------------------------------------

#[test]
fn has_where_on_edges() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter edges by "since" property
    // knows edges have since: 2020, 2021, 2019
    let results = g
        .e()
        .has_label("knows")
        .has_where("since", p::gte(2020))
        .to_list();

    assert_eq!(results.len(), 2); // 2020 and 2021
}

#[test]
fn has_where_on_edge_with_range() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Filter edges with since between 2019 and 2021 (exclusive end)
    let results = g
        .e()
        .has_label("knows")
        .has_where("since", p::between(2019, 2021))
        .to_list();

    assert_eq!(results.len(), 2); // 2019 and 2020
}

// -------------------------------------------------------------------------
// Integration with Traversal Steps
// -------------------------------------------------------------------------

#[test]
fn has_where_chained_with_navigation() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Start from Alice, get neighbors older than 30
    // Alice -> Bob (25, no), GraphDB (no age)
    // So result should be empty
    let results = g
        .v_ids([tg.alice])
        .out()
        .has_where("age", p::gt(30))
        .to_list();

    assert!(results.is_empty());
}

#[test]
fn has_where_in_where_step() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Find vertices that have an outgoing neighbor with age < 30
    // Alice -> Bob (25 < 30): Alice passes
    // Bob -> Charlie (35 >= 30): Bob fails
    // Charlie -> Alice (30 >= 30): Charlie fails
    // GraphDB -> (no out): fails
    let results = g.v().where_(__.out().has_where("age", p::lt(30))).to_list();

    assert_eq!(results.len(), 1);
    assert_eq!(results[0].as_vertex_id(), Some(tg.alice));
}

#[test]
fn has_where_in_union_branches() {
    let tg = create_small_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Union with different predicates per branch
    let results = g
        .v_ids([tg.alice])
        .union(vec![
            __.out().has_where("age", p::lt(30)),              // Bob (25)
            __.out().has_where("name", p::starting_with("G")), // GraphDB
        ])
        .to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.bob));
    assert!(ids.contains(&tg.graphdb));
}

// -------------------------------------------------------------------------
// Spec-compliant Test Graph
// -------------------------------------------------------------------------

/// Test graph structure for spec-alignment tests.
struct SpecTestGraph {
    graph: Graph,
    alice: VertexId,
    bob: VertexId,
    #[allow(dead_code)]
    carol: VertexId,
    #[allow(dead_code)]
    acme: VertexId,
}

fn create_spec_test_graph() -> SpecTestGraph {
    let graph = Graph::new();

    // Add person vertices
    let alice = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Alice".to_string()));
        props.insert("age".to_string(), Value::Int(30));
        props
    });

    let bob = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Bob".to_string()));
        props.insert("age".to_string(), Value::Int(35));
        props
    });

    let carol = graph.add_vertex("person", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Carol".to_string()));
        props.insert("age".to_string(), Value::Int(25));
        props
    });

    // Add company vertex
    let acme = graph.add_vertex("company", {
        let mut props = HashMap::new();
        props.insert("name".to_string(), Value::String("Acme Corp".to_string()));
        props
    });

    // Add edges
    graph.add_edge(alice, bob, "knows", HashMap::new()).unwrap();

    graph
        .add_edge(alice, carol, "knows", HashMap::new())
        .unwrap();

    graph.add_edge(bob, carol, "knows", HashMap::new()).unwrap();

    // works_at edges
    graph
        .add_edge(alice, acme, "works_at", HashMap::new())
        .unwrap();

    graph
        .add_edge(bob, acme, "works_at", HashMap::new())
        .unwrap();

    SpecTestGraph {
        graph,
        alice,
        bob,
        carol,
        acme,
    }
}

#[test]
fn has_where_spec_graph_integration() {
    // Use the spec-compliant test graph for spec alignment
    let tg = create_spec_test_graph();
    let snapshot = tg.graph.snapshot();
    let g = snapshot.gremlin();

    // Find adults (age >= 18) who work at a company
    // All persons are adults, Alice and Bob work at Acme
    let results = g
        .v()
        .has_where("age", p::gte(18))
        .where_(__.out_labels(&["works_at"]))
        .to_list();

    assert_eq!(results.len(), 2);

    let ids: Vec<VertexId> = results.iter().filter_map(|v| v.as_vertex_id()).collect();
    assert!(ids.contains(&tg.alice));
    assert!(ids.contains(&tg.bob));
}