graphlite 0.0.1

GraphLite - A lightweight ISO GQL Graph Database
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
//! ISO GQL DML (Data Manipulation Language) Compliance Tests
//!
//! Tests for INSERT, SET, REMOVE, DELETE statements according to ISO GQL standard
//! Covers all data modification operations

#[path = "testutils/mod.rs"]
mod testutils;

use graphlite::Value;
use testutils::test_fixture::{FixtureType, TestCase, TestFixture, TestSuite};

#[test]
fn test_insert_operations() {
    let fixture = TestFixture::new().expect("Failed to create test fixture");
    // Setup fresh graph for this test to avoid interference
    fixture
        .setup_graph("test_insert_operations")
        .expect("Failed to setup graph");

    // Test basic node insertion
    fixture.assert_query_succeeds("INSERT (new_node:Person {name: 'John Doe', age: 30})");

    // Verify insertion
    fixture.assert_first_value(
        "MATCH (p:Person) WHERE p.name = 'John Doe' RETURN count(p) as count",
        "count",
        Value::Number(1.0),
    );

    // Test multiple node insertion
    fixture.assert_query_succeeds(
        "INSERT (alice:Person {name: 'Alice', age: 25}), 
                (bob:Person {name: 'Bob', age: 28})",
    );

    // Verify multiple insertions
    fixture.assert_first_value(
        "MATCH (p:Person) WHERE p.name IN ['Alice', 'Bob'] RETURN count(p) as count",
        "count",
        Value::Number(2.0),
    );

    // Test node insertion with multiple labels
    fixture.assert_query_succeeds(
        "INSERT (manager:Person:Employee {name: 'Manager', age: 45, role: 'supervisor'})",
    );

    // Test relationship insertion
    fixture.assert_query_succeeds("INSERT (company:Company {name: 'TechCorp'})");

    fixture.assert_query_succeeds(
        "MATCH (p:Person {name: 'John Doe'}), (c:Company {name: 'TechCorp'})
         INSERT (p)-[:WORKS_FOR {since: '2020-01-01', position: 'Developer'}]->(c)",
    );

    // Verify relationship
    fixture.assert_first_value(
        "MATCH (p:Person)-[r:WORKS_FOR]->(c:Company) 
         RETURN count(r) as count",
        "count",
        Value::Number(1.0),
    );

    // Test complex pattern insertion - split into separate statements for now
    fixture.assert_query_succeeds("INSERT (ai_proj:Project {name: 'AI System'})");

    fixture.assert_query_succeeds(
        "MATCH (proj:Project {name: 'AI System'})
         INSERT (john_lead:Person {name: 'John'})-[:ASSIGNED_TO {role: 'lead'}]->(proj)",
    );
}

#[test]
fn test_set_operations() {
    let fixture = TestFixture::new().expect("Failed to create test fixture");
    // Setup fresh graph for this test to avoid interference
    fixture
        .setup_graph("test_set_operations")
        .expect("Failed to setup graph");

    // Insert test data first
    fixture.assert_query_succeeds(
        "INSERT (emp:Employee {name: 'Jane Smith', age: 30, salary: 50000})",
    );

    // Test property SET
    fixture.assert_query_succeeds(
        "MATCH (emp:Employee {name: 'Jane Smith'}) 
         SET emp.age = 31, emp.salary = 55000",
    );

    // Verify property update
    let result = fixture.assert_query_succeeds(
        "MATCH (emp:Employee {name: 'Jane Smith'}) 
         RETURN emp.age as age, emp.salary as salary",
    );
    assert_eq!(result.rows.len(), 1);

    // Test adding new property
    fixture.assert_query_succeeds(
        "MATCH (emp:Employee {name: 'Jane Smith'}) 
         SET emp.department = 'Engineering', emp.active = true",
    );

    // Verify new property
    fixture.assert_first_value(
        "MATCH (emp:Employee {name: 'Jane Smith'}) 
         RETURN emp.department as dept",
        "dept",
        Value::String("Engineering".to_string()),
    );

    // Test label SET
    fixture.assert_query_succeeds(
        "MATCH (emp:Employee {name: 'Jane Smith'}) 
         SET emp:Manager",
    );

    // Verify label addition
    fixture.assert_first_value(
        "MATCH (emp:Employee:Manager {name: 'Jane Smith'}) 
         RETURN count(emp) as count",
        "count",
        Value::Number(1.0),
    );

    // Test conditional SET
    fixture.assert_query_succeeds(
        "MATCH (emp:Employee) 
         WHERE emp.salary > 50000 
         SET emp.performance_tier = 'high'",
    );

    // Test SET with expression
    fixture.assert_query_succeeds(
        "MATCH (emp:Employee {name: 'Jane Smith'}) 
         SET emp.salary = emp.salary * 1.1",
    );
}

#[test]
fn test_remove_operations() {
    let fixture = TestFixture::new().expect("Failed to create test fixture");
    // Setup fresh graph for this test to avoid interference
    fixture
        .setup_graph("test_remove_operations")
        .expect("Failed to setup graph");

    // Insert test data
    fixture.assert_query_succeeds(
        "INSERT (temp:TempNode:ExtraLabel {prop1: 'value1', prop2: 'value2', prop3: 'value3'})",
    );

    // Test property REMOVE
    fixture.assert_query_succeeds(
        "MATCH (temp:TempNode) 
         REMOVE temp.prop1, temp.prop2",
    );

    // Verify properties removed
    fixture.assert_first_value(
        "MATCH (temp:TempNode) 
         RETURN temp.prop3 as remaining_prop",
        "remaining_prop",
        Value::String("value3".to_string()),
    );

    // Test label REMOVE
    fixture.assert_query_succeeds(
        "MATCH (temp:TempNode:ExtraLabel) 
         REMOVE temp:ExtraLabel",
    );

    // Verify label removed (node should still exist with TempNode label)
    fixture.assert_first_value(
        "MATCH (temp:TempNode) 
         WHERE NOT temp:ExtraLabel 
         RETURN count(temp) as count",
        "count",
        Value::Number(1.0),
    );

    // Test conditional REMOVE
    fixture.assert_query_succeeds(
        "INSERT (conditional:ConditionalNode {status: 'temporary', value: 100})",
    );

    fixture.assert_query_succeeds(
        "MATCH (c:ConditionalNode) 
         WHERE c.status = 'temporary' 
         REMOVE c.status",
    );

    // Verify conditional remove
    let result = fixture
        .query(
            "MATCH (c:ConditionalNode) 
         RETURN c.status as status",
        )
        .unwrap();

    assert!(result.rows[0].values.get("status").unwrap() == &Value::Null);
}

#[test]
fn test_count_aggregation_with_empty_results() {
    let fixture = TestFixture::new().expect("Failed to create test fixture");
    // Setup fresh graph for this test to avoid interference
    fixture
        .setup_graph("test_count_aggregation")
        .expect("Failed to setup graph");
    // Re-insert simple data since we have a fresh graph
    fixture
        .insert_simple_data()
        .expect("Failed to insert simple data");

    // First test a working case - COUNT on existing nodes
    let working_result = fixture
        .query("MATCH (n:TestNode) RETURN count(n) as count")
        .unwrap();
    for (i, row) in working_result.rows.iter().enumerate() {}

    // Now test COUNT on non-existent nodes - should return 1 row with count=0
    let result = match fixture.query("MATCH (x:NonExistentLabel) RETURN count(x) as count") {
        Ok(r) => r,
        Err(e) => {
            panic!("Query failed with error: {}", e);
        }
    };

    for (i, row) in result.rows.iter().enumerate() {}

    // This should return exactly 1 row with count=0, not 0 rows
    assert_eq!(
        result.rows.len(),
        1,
        "COUNT should always return exactly 1 row, even with 0 matching nodes"
    );
    let count_value = result.rows[0].values.get("count").unwrap();
    assert_eq!(
        count_value,
        &Value::Number(0.0),
        "COUNT of non-existent nodes should be 0"
    );
}

#[test]
fn test_delete_operations() {
    let fixture = TestFixture::empty().expect("Failed to create test fixture");

    // Create schema and graph for this test (ISO GQL compliant)
    fixture
        .query(&format!(
            "CREATE SCHEMA IF NOT EXISTS /{}",
            fixture.schema_name()
        ))
        .unwrap();
    fixture
        .query(&format!(
            "CREATE GRAPH /{}/delete_test_graph",
            fixture.schema_name()
        ))
        .unwrap();
    fixture
        .query(&format!(
            "SESSION SET GRAPH /{}/delete_test_graph",
            fixture.schema_name()
        ))
        .unwrap();

    // Insert test data for deletion
    fixture.assert_query_succeeds(
        "INSERT (delete_me:DeleteTest {name: 'ToDelete'}),
                (keep_me:DeleteTest {name: 'ToKeep'}),
                (other:Other {name: 'Other'})",
    );

    fixture.assert_query_succeeds(
        "MATCH (d:DeleteTest {name: 'ToDelete'}), (o:Other)
         INSERT (d)-[:RELATED_TO]->(o)",
    );

    // Test simple node deletion with relationships (requires DETACH)
    fixture.assert_query_succeeds(
        "MATCH (d:DeleteTest {name: 'ToDelete'}) 
         DETACH DELETE d",
    );

    // Verify deletion - use query instead of assert_first_value to handle empty results
    let result = fixture
        .query(
            "MATCH (d:DeleteTest {name: 'ToDelete'}) 
         RETURN count(d) as count",
        )
        .unwrap();

    // COUNT should return 1 row even with 0 count
    assert_eq!(
        result.rows.len(),
        1,
        "COUNT should always return exactly 1 row"
    );
    let count = result.rows[0].values.get("count").unwrap();
    assert_eq!(
        count,
        &Value::Number(0.0),
        "Expected count to be 0 after deletion"
    );

    // Verify other nodes remain
    let result = fixture
        .query(
            "MATCH (d:DeleteTest {name: 'ToKeep'}) 
         RETURN count(d) as count",
        )
        .unwrap();

    if result.rows.is_empty() {
        panic!("Expected to find remaining nodes, but count query returned no rows");
    } else {
        let count = result.rows[0].values.get("count").unwrap();
        assert_eq!(count, &Value::Number(1.0), "Expected 1 remaining node");
    }

    // Test relationship deletion
    fixture.assert_query_succeeds("INSERT (src:Source {id: 1}), (dst:Destination {id: 2})");

    fixture.assert_query_succeeds(
        "MATCH (src:Source), (dst:Destination)
         INSERT (src)-[r:CONNECTS {weight: 1.0}]->(dst)",
    );

    fixture.assert_query_succeeds(
        "MATCH ()-[r:CONNECTS]->() 
         DELETE r",
    );

    // Verify relationship deleted but nodes remain
    fixture.assert_first_value(
        "MATCH ()-[r:CONNECTS]->() 
         RETURN count(r) as count",
        "count",
        Value::Number(0.0),
    );

    fixture.assert_first_value(
        "MATCH (n) WHERE n:Source OR n:Destination 
         RETURN count(n) as count",
        "count",
        Value::Number(2.0),
    );

    // Test DETACH DELETE (delete node and its relationships)
    fixture.assert_query_succeeds("INSERT (hub:Hub {id: 'central'})");

    fixture.assert_query_succeeds(
        "MATCH (hub:Hub), (src:Source), (dst:Destination)
         INSERT (src)-[:CONNECTS_TO]->(hub),
                (hub)-[:CONNECTS_TO]->(dst)",
    );

    fixture.assert_query_succeeds(
        "MATCH (hub:Hub) 
         DETACH DELETE hub",
    );

    // Verify node and its relationships are deleted
    fixture.assert_first_value(
        "MATCH (hub:Hub) 
         RETURN count(hub) as count",
        "count",
        Value::Number(0.0),
    );

    fixture.assert_first_value(
        "MATCH ()-[r:CONNECTS_TO]->() 
         RETURN count(r) as count",
        "count",
        Value::Number(0.0),
    );
}

#[test]
fn test_dml_data_driven_cases() {
    let test_suite = TestSuite {
        name: "DML Operations Test Suite".to_string(),
        fixture_type: FixtureType::Simple,
        test_cases: vec![
            // INSERT tests
            TestCase {
                name: "insert_single_node".to_string(),
                description: "Insert a single node with properties".to_string(),
                query: "INSERT (test:TestNode {name: 'DML Test', value: 42})".to_string(),
                expected_rows: Some(1),
                expected_values: None,
                expected_error: None,
            },
            TestCase {
                name: "insert_multiple_nodes".to_string(),
                description: "Insert multiple nodes in one statement".to_string(),
                query: "INSERT (a:NodeA {id: 1}), (b:NodeB {id: 2})".to_string(),
                expected_rows: Some(1),
                expected_values: None,
                expected_error: None,
            },
            // SET tests  
            TestCase {
                name: "set_property_value".to_string(),
                description: "Set property values on existing nodes".to_string(),
                query: "MATCH (n:TestNode) WHERE n.name = 'Node 1' SET n.updated = true, n.timestamp = '2024-01-01'".to_string(),
                expected_rows: Some(1),
                expected_values: None,
                expected_error: None,
            },
            // REMOVE tests
            TestCase {
                name: "remove_property".to_string(),
                description: "Remove property from node".to_string(),
                query: "MATCH (n:TestNode) WHERE n.value = 1 REMOVE n.name".to_string(),
                expected_rows: Some(1),
                expected_values: None,
                expected_error: None,
            },
            // DELETE tests
            TestCase {
                name: "delete_nodes_conditional".to_string(),
                description: "Delete nodes based on condition".to_string(),
                query: "MATCH (n:TestNode) WHERE n.value > 15 DELETE n".to_string(),
                expected_rows: Some(1),
                expected_values: None,
                expected_error: None,
            },
        ],
    };

    let results = test_suite.run().expect("Failed to run DML test suite");
    results.print_summary();

    assert!(
        results.passed >= 4,
        "Should have at least 4 passing DML tests"
    );
}

#[test]
fn test_simple_match_set() {
    let fixture = TestFixture::new().expect("Failed to create test fixture");
    // Setup fresh graph for this test to avoid interference
    fixture
        .setup_graph("test_simple_match_set")
        .expect("Failed to setup graph");
    // Re-insert fraud data since we have a fresh graph
    fixture
        .insert_fraud_data()
        .expect("Failed to insert fraud data");

    // Test simple MATCH SET without complex patterns
    fixture.assert_query_succeeds(
        "MATCH (a:Account) 
         WHERE a.balance > 100000 
         SET a.tier = 'premium'",
    );
}

#[test]
fn test_complex_dml_scenarios() {
    let fixture = TestFixture::new().expect("Failed to create test fixture");
    // Setup fresh graph for this test to avoid interference
    fixture
        .setup_graph("test_complex_dml_scenarios")
        .expect("Failed to setup graph");
    // Re-insert fraud data since we have a fresh graph
    fixture
        .insert_fraud_data()
        .expect("Failed to insert fraud data");

    // Test batch operations on large dataset

    // 1. Batch update based on conditions
    fixture.assert_query_succeeds(
        "MATCH (a:Account) 
         WHERE a.balance > 100000 
         SET a:HighValue, a.tier = 'premium'",
    );

    // Verify batch update
    let result = fixture.assert_query_succeeds(
        "MATCH (a:Account:HighValue) 
         RETURN count(a) as premium_accounts",
    );
    assert!(!result.rows.is_empty());

    // 2. Insert derived data based on existing patterns
    fixture.assert_query_succeeds(
        "MATCH (a:Account)-[t:Transaction]->(m:Merchant)
         WHERE t.amount > 50000
         INSERT (alert:SecurityAlert {
             account_id: a.account_number,
             merchant: m.name,
             amount: t.amount,
             alert_type: 'high_value_transaction',
             created_at: '2024-01-01T12:00:00Z'
         })",
    );

    // Verify derived data insertion
    let result = fixture.assert_query_succeeds(
        "MATCH (alert:SecurityAlert) 
         WHERE alert.alert_type = 'high_value_transaction' 
         RETURN count(alert) as alerts",
    );
    assert!(!result.rows.is_empty());

    // 3. Conditional property updates with calculations
    fixture.assert_query_succeeds(
        "MATCH (a:Account)-[t:Transaction]->()
         WITH a, count(t) as transaction_count, avg(t.amount) as avg_amount
         WHERE transaction_count > 10
         SET a.activity_score = transaction_count * 0.1 + avg_amount * 0.0001,
             a.active_user = true",
    );

    // 4. Remove outdated or invalid data
    fixture.assert_query_succeeds(
        "MATCH (a:Account) 
         WHERE a.status = 'inactive' AND a.balance = 0 
         DETACH DELETE a",
    );

    // 5. Bulk relationship modifications
    fixture.assert_query_succeeds(
        "MATCH (a:Account)-[t:Transaction]->(m:Merchant)
         WHERE t.amount < 10 AND t.status = 'completed'
         SET t:MicroTransaction, t.processed_date = '2024-01-01'",
    );
}

#[test]
fn test_dml_transaction_behavior() {
    let fixture = TestFixture::new().expect("Failed to create test fixture");
    fixture
        .setup_graph("test_transaction_behavior")
        .expect("Failed to setup graph");

    // Test DML within transactions
    fixture.assert_query_succeeds("BEGIN");

    // Insert data in transaction
    fixture.assert_query_succeeds("INSERT (tx_test:TransactionTest {name: 'TX Data', value: 100})");

    // Verify data is visible within transaction
    fixture.assert_first_value(
        "MATCH (t:TransactionTest) RETURN count(t) as count",
        "count",
        Value::Number(1.0),
    );

    // Update data in transaction
    fixture.assert_query_succeeds(
        "MATCH (t:TransactionTest) 
         SET t.value = 200, t.updated_in_tx = true",
    );

    // Rollback transaction
    fixture.assert_query_succeeds("ROLLBACK");

    // Verify data is rolled back
    fixture.assert_first_value(
        "MATCH (t:TransactionTest) RETURN count(t) as count",
        "count",
        Value::Number(0.0),
    );

    // Test commit behavior
    fixture.assert_query_succeeds("BEGIN");

    fixture.assert_query_succeeds("INSERT (commit_test:CommitTest {name: 'Committed Data'})");

    fixture.assert_query_succeeds("COMMIT");

    // Verify data persists after commit
    fixture.assert_first_value(
        "MATCH (c:CommitTest) RETURN count(c) as count",
        "count",
        Value::Number(1.0),
    );
}

#[test]
fn test_dml_error_cases() {
    let fixture = TestFixture::new().expect("Failed to create test fixture");
    fixture
        .setup_graph("test_error_cases")
        .expect("Failed to setup graph");

    // Test invalid INSERT syntax
    fixture.assert_query_fails("INSERT (invalid syntax here)", "Parse error");

    // Test SET on non-existent nodes (should succeed but affect 0 nodes)
    fixture.assert_query_succeeds("MATCH (n:NonExistentLabel) SET n.prop = 'value'");

    // Test REMOVE on non-existent properties (should succeed)
    fixture.assert_query_succeeds("INSERT (test:RemoveTest {prop1: 'value'})");

    fixture.assert_query_succeeds("MATCH (test:RemoveTest) REMOVE test.non_existent_prop");

    // Test DELETE with missing DETACH when node has relationships
    // TODO: This test is disabled because MATCH INSERT is not working properly
    // The MATCH INSERT operation fails to create relationships, so the DELETE constraint check
    // cannot be properly tested. Once MATCH INSERT is fixed, re-enable this test.
    /*
    fixture.assert_query_succeeds(
        "INSERT (connected:Connected {id: 1}), (other:Other {id: 2})"
    );

    fixture.assert_query_succeeds(
        "MATCH (c:Connected), (o:Other) INSERT (c)-[:LINKS_TO]->(o)"
    );

    fixture.assert_query_fails(
        "MATCH (c:Connected) DELETE c",
        "Cannot delete node"
    );
    */

    // Test type mismatches in SET operations
    fixture.assert_query_succeeds("INSERT (type_test:TypeTest {number_prop: 42})");

    // This may or may not fail depending on type coercion rules
    let result = fixture.query("MATCH (t:TypeTest) SET t.number_prop = 'string_value'");

    match result {
        Ok(_) => {}
        Err(_) => {}
    }
}

#[test]
fn test_dml_performance() {
    let fixture = TestFixture::new().expect("Failed to create test fixture");
    // Setup fresh graph for this test to avoid interference
    fixture
        .setup_graph("test_dml_performance")
        .expect("Failed to setup graph");

    // Test bulk insert performance
    let start = std::time::Instant::now();

    // Insert 100 nodes in smaller batches to avoid lexer infinite loop
    for batch in 0..10 {
        let mut insert_query = String::from("INSERT ");
        let mut clauses = Vec::new();

        for i in 0..10 {
            let node_id = batch * 10 + i;
            clauses.push(format!(
                "(perf_node_{}:PerfNode {{id: {}, batch: {}, value: {}}})",
                node_id,
                node_id,
                batch,
                node_id * 2
            ));
        }

        // Debug: show the first few clauses
        if batch == 0 {}

        insert_query.push_str(&clauses.join(", "));
        fixture.assert_query_succeeds(&insert_query);

        // Debug: check node count after each batch
        let result = fixture
            .query("MATCH (p:PerfNode) RETURN count(p) as count")
            .unwrap();
        if !result.rows.is_empty() {
            let count = result.rows[0]
                .values
                .get("count")
                .unwrap_or(&Value::Number(0.0));
        } else {
        }
    }

    let insert_duration = start.elapsed();

    // Verify all nodes inserted
    let result = fixture
        .query("MATCH (p:PerfNode) RETURN count(p) as count")
        .unwrap();
    if result.rows.is_empty() {
        panic!("Expected to find nodes, but count query returned no rows");
    } else {
        let count = result.rows[0].values.get("count").unwrap();
        assert_eq!(
            count,
            &Value::Number(100.0),
            "Expected 100 nodes to be inserted"
        );
    }

    // Test bulk update performance
    let start = std::time::Instant::now();

    fixture.assert_query_succeeds(
        "MATCH (p:PerfNode) 
         WHERE p.value % 2 = 0 
         SET p:EvenValue, p.processed = true",
    );

    let update_duration = start.elapsed();

    // Test bulk delete performance
    let start = std::time::Instant::now();

    fixture.assert_query_succeeds(
        "MATCH (p:PerfNode) 
         WHERE p.batch >= 5 
         DELETE p",
    );

    let delete_duration = start.elapsed();

    // Verify partial deletion
    let result = fixture
        .query("MATCH (p:PerfNode) RETURN count(p) as count")
        .unwrap();
    if result.rows.is_empty() {
        panic!("Expected to find remaining nodes, but count query returned no rows");
    } else {
        let count = result.rows[0].values.get("count").unwrap();
        assert_eq!(
            count,
            &Value::Number(50.0),
            "Expected 50 nodes to remain after deletion"
        );
    }

    assert!(
        insert_duration.as_secs() < 10,
        "Bulk insert should complete within 10 seconds"
    );
    assert!(
        update_duration.as_secs() < 5,
        "Bulk update should complete within 5 seconds"
    );
    assert!(
        delete_duration.as_secs() < 5,
        "Bulk delete should complete within 5 seconds"
    );
}