mirror of
https://github.com/ruvnet/RuVector.git
synced 2026-06-02 07:29:19 +00:00
This commit fixes multiple compilation issues in the Neo4j-compatible hypergraph database implementation: Build Fixes: - Add Hash, Eq derives to Label type for HashMap compatibility - Fix PropertyValue enum - add List variant as alias for Array - Fix LabelIndex to use label.name instead of Label struct as key - Split cypher lexer alt() into nested calls (nom 21-alternative limit) - Fix RoaringBitmap serialize method (use serialize_into) - Add ordered-float dependency for Hash impl on float values - Fix ReadOnlyTable usage (use iter().count() instead of len()) - Add VectorIndex trait import for HnswIndex methods - Fix PropertyValue variant names in match statements (Boolean/Integer) - Add Clone bound to AdaptiveRadixTree generic parameter - Fix PhysicalPlan to use custom Debug impl (dyn Operator not Clone) - Add HyperedgeScan to PlanNode compile_node match Type System: - Implement Hash and Eq for plan::Value using OrderedFloat - Fix property_value_to_string to handle all PropertyValue variants - Add proper type annotations for nom parser combinators Code Quality: - Remove unused Clone derive from PhysicalPlan - Use std::mem::take for ownership transfer in Pipeline - Fix ArtNode type annotation in adaptive_radix.rs - Clean up test_cypher_parser.rs to use library import The library now compiles successfully. Some test files still need updates for NodeBuilder/EdgeBuilder exports and From implementations.
121 lines
3.9 KiB
Rust
121 lines
3.9 KiB
Rust
//! Standalone example demonstrating the Cypher parser
|
|
//! Run with: cargo run --example test_cypher_parser
|
|
|
|
use ruvector_graph::cypher::{parse_cypher, ast::*};
|
|
|
|
fn main() {
|
|
println!("=== Cypher Parser Test Suite ===\n");
|
|
|
|
// Test 1: Simple MATCH
|
|
println!("Test 1: Simple MATCH query");
|
|
let query1 = "MATCH (n:Person) RETURN n";
|
|
match parse_cypher(query1) {
|
|
Ok(ast) => {
|
|
println!("✓ Parsed successfully");
|
|
println!(" Statements: {}", ast.statements.len());
|
|
println!(" Read-only: {}", ast.is_read_only());
|
|
}
|
|
Err(e) => println!("✗ Parse error: {}", e),
|
|
}
|
|
println!();
|
|
|
|
// Test 2: MATCH with WHERE
|
|
println!("Test 2: MATCH with WHERE clause");
|
|
let query2 = "MATCH (n:Person) WHERE n.age > 30 RETURN n.name";
|
|
match parse_cypher(query2) {
|
|
Ok(_) => println!("✓ Parsed successfully"),
|
|
Err(e) => println!("✗ Parse error: {}", e),
|
|
}
|
|
println!();
|
|
|
|
// Test 3: Relationship pattern
|
|
println!("Test 3: Relationship pattern");
|
|
let query3 = "MATCH (a:Person)-[r:KNOWS]->(b:Person) RETURN a, r, b";
|
|
match parse_cypher(query3) {
|
|
Ok(_) => println!("✓ Parsed successfully"),
|
|
Err(e) => println!("✗ Parse error: {}", e),
|
|
}
|
|
println!();
|
|
|
|
// Test 4: CREATE node
|
|
println!("Test 4: CREATE node");
|
|
let query4 = "CREATE (n:Person {name: 'Alice', age: 30})";
|
|
match parse_cypher(query4) {
|
|
Ok(ast) => {
|
|
println!("✓ Parsed successfully");
|
|
println!(" Read-only: {}", ast.is_read_only());
|
|
}
|
|
Err(e) => println!("✗ Parse error: {}", e),
|
|
}
|
|
println!();
|
|
|
|
// Test 5: Hyperedge (N-ary relationship)
|
|
println!("Test 5: Hyperedge pattern");
|
|
let query5 = "MATCH (a)-[r:TRANSACTION]->(b, c, d) RETURN a, r, b, c, d";
|
|
match parse_cypher(query5) {
|
|
Ok(ast) => {
|
|
println!("✓ Parsed successfully");
|
|
println!(" Has hyperedges: {}", ast.has_hyperedges());
|
|
}
|
|
Err(e) => println!("✗ Parse error: {}", e),
|
|
}
|
|
println!();
|
|
|
|
// Test 6: Aggregation functions
|
|
println!("Test 6: Aggregation functions");
|
|
let query6 = "MATCH (n:Person) RETURN COUNT(n), AVG(n.age), MAX(n.salary)";
|
|
match parse_cypher(query6) {
|
|
Ok(_) => println!("✓ Parsed successfully"),
|
|
Err(e) => println!("✗ Parse error: {}", e),
|
|
}
|
|
println!();
|
|
|
|
// Test 7: Complex query with ORDER BY and LIMIT
|
|
println!("Test 7: Complex query with ORDER BY and LIMIT");
|
|
let query7 = r#"
|
|
MATCH (a:Person)-[r:KNOWS]->(b:Person)
|
|
WHERE a.age > 30 AND b.name = 'Alice'
|
|
RETURN a.name, b.name, r.since
|
|
ORDER BY r.since DESC
|
|
LIMIT 10
|
|
"#;
|
|
match parse_cypher(query7) {
|
|
Ok(_) => println!("✓ Parsed successfully"),
|
|
Err(e) => println!("✗ Parse error: {}", e),
|
|
}
|
|
println!();
|
|
|
|
// Test 8: MERGE with ON CREATE
|
|
println!("Test 8: MERGE with ON CREATE");
|
|
let query8 = "MERGE (n:Person {name: 'Bob'}) ON CREATE SET n.created = 2024";
|
|
match parse_cypher(query8) {
|
|
Ok(_) => println!("✓ Parsed successfully"),
|
|
Err(e) => println!("✗ Parse error: {}", e),
|
|
}
|
|
println!();
|
|
|
|
// Test 9: WITH clause (query chaining)
|
|
println!("Test 9: WITH clause");
|
|
let query9 = r#"
|
|
MATCH (n:Person)
|
|
WITH n, n.age AS age
|
|
WHERE age > 30
|
|
RETURN n.name, age
|
|
"#;
|
|
match parse_cypher(query9) {
|
|
Ok(_) => println!("✓ Parsed successfully"),
|
|
Err(e) => println!("✗ Parse error: {}", e),
|
|
}
|
|
println!();
|
|
|
|
// Test 10: Variable-length path
|
|
println!("Test 10: Variable-length path");
|
|
let query10 = "MATCH p = (a:Person)-[*1..3]->(b:Person) RETURN p";
|
|
match parse_cypher(query10) {
|
|
Ok(_) => println!("✓ Parsed successfully"),
|
|
Err(e) => println!("✗ Parse error: {}", e),
|
|
}
|
|
println!();
|
|
|
|
println!("=== All tests completed ===");
|
|
}
|