From 8895381d0fd6b76180f2a7b8a123cf12a0e71fad Mon Sep 17 00:00:00 2001 From: Leonardo Christino <leomilho@gmail.com> Date: Wed, 9 Aug 2023 16:49:35 +0200 Subject: [PATCH] fix query direction conversion --- cypherv2/convertQuery.go | 11 ++++++----- cypherv2/convertQuery_test.go | 33 ++++++++++++++++----------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/cypherv2/convertQuery.go b/cypherv2/convertQuery.go index af3a3e0..4fb6587 100644 --- a/cypherv2/convertQuery.go +++ b/cypherv2/convertQuery.go @@ -56,9 +56,9 @@ func getNodeCypher(JSONQuery *entityv2.NodeStruct) (string, error) { return "", err } if JSONQuery.Relation.Direction != "TO" { - cypher += fmt.Sprintf("-%s", relationCypher) - } else { cypher += fmt.Sprintf("<-%s", relationCypher) + } else { + cypher += fmt.Sprintf("-%s", relationCypher) } } return cypher, nil @@ -89,9 +89,9 @@ func getRelationCypher(JSONQuery *entityv2.RelationStruct) (string, error) { return "", err } if JSONQuery.Direction != "TO" { - cypher += fmt.Sprintf("->%s", nodeCypher) - } else { cypher += fmt.Sprintf("-%s", nodeCypher) + } else { + cypher += fmt.Sprintf("->%s", nodeCypher) } return cypher, nil } @@ -165,11 +165,12 @@ func extractLogicCypher(LogicQuery interface{}) (interface{}, string, error) { switch v := LogicQuery.(type) { case []interface{}: op := strings.ReplaceAll(v[0].(string), "_", "") + op = strings.ToLower(op) left, whereLogic, err := extractLogicCypher(v[1]) if err != nil { return "", "", err } - switch strings.ToLower(op) { + switch op { // Operations case "!=": op = "<>" diff --git a/cypherv2/convertQuery_test.go b/cypherv2/convertQuery_test.go index a76dbed..95ad30e 100644 --- a/cypherv2/convertQuery_test.go +++ b/cypherv2/convertQuery_test.go @@ -81,8 +81,8 @@ func TestV2NoLogic(t *testing.T) { } t.Log(*cypher) - answer := `MATCH path1 = ((p1:Person)<-[:DIRECTED*1..1]-(m1:Movie)) - MATCH path2 = ((p1:Person)<-[:IN_GENRE*1..1]-(g1:Genre)) + answer := `MATCH path1 = ((p1:Person)-[:DIRECTED*1..1]->(m1:Movie)) + MATCH path2 = ((p1:Person)-[:IN_GENRE*1..1]->(g1:Genre)) RETURN * LIMIT 5000` fmt.Printf("Cypher: %s\n", answer) @@ -150,8 +150,8 @@ func TestV2Simple(t *testing.T) { } t.Log(*cypher) - answer := `MATCH path1 = ((p1:Person)<-[:DIRECTED*1..1]-(m1:Movie)) - MATCH path2 = ((p1:Person)<-[:IN_GENRE*1..1]-(g1:Genre)) + answer := `MATCH path1 = ((p1:Person)-[:DIRECTED*1..1]->(m1:Movie)) + MATCH path2 = ((p1:Person)-[:IN_GENRE*1..1]->(g1:Genre)) WHERE (p1.name <> "Raymond Campbell") RETURN * LIMIT 5000` @@ -211,9 +211,9 @@ func TestV2GroupBy(t *testing.T) { } t.Log(*cypher) - answer := `MATCH path1 = ((p1:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) + answer := `MATCH path1 = ((p1:Person)-[acted:ACTED_IN*1..1]->(movie:Movie)) MATCH path2 = ((p2:Person)) - WHERE ((movie.imdbRating < 7.500000) AND (p2.age = p1.age)) + WHERE ((movie.imdbRating < 7.500000) and (p2.age = p1.age)) RETURN path2 LIMIT 5000` fmt.Printf("Cypher: %s\n", answer) @@ -264,7 +264,7 @@ func TestV2NoLabel(t *testing.T) { } t.Log(*cypher) - answer := `MATCH path1 = ((p1)<-[acted*1..1]-(movie:Movie)) + answer := `MATCH path1 = ((p1)-[acted*1..1]->(movie:Movie)) WHERE ((movie.year - p1.year) < 10.000000) RETURN * LIMIT 5000` @@ -322,9 +322,9 @@ func TestV2NoDepth(t *testing.T) { t.Log(*cypher) - answer := `MATCH path1 = ((p1)<-[acted]-(movie:Movie)) + answer := `MATCH path1 = ((p1)-[acted]->(movie:Movie)) MATCH path2 = ((p2)) - WHERE ((movie.imdbRating < 7.500000) AND (p2.age = p1.age)) + WHERE ((movie.imdbRating < 7.500000) and (p2.age = p1.age)) RETURN * LIMIT 5000` fmt.Printf("Cypher: %s\n", answer) @@ -376,9 +376,9 @@ func TestV2WithAverage(t *testing.T) { } t.Log(*cypher) - answer := `MATCH path1 = ((p1:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) + answer := `MATCH path1 = ((p1:Person)-[acted:ACTED_IN*1..1]->(movie:Movie)) WITH avg(p1.age) AS p1_age_avg - MATCH path1 = ((p1:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) + MATCH path1 = ((p1:Person)-[acted:ACTED_IN*1..1]->(movie:Movie)) WHERE (p1.age < p1_age_avg) RETURN * LIMIT 5000` @@ -447,11 +447,11 @@ func TestV2WithAverage2Paths(t *testing.T) { } t.Log(*cypher) - answer := `MATCH path1 = ((p1:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) - MATCH path2 = ((p2:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) + answer := `MATCH path1 = ((p1:Person)-[acted:ACTED_IN*1..1]->(movie:Movie)) + MATCH path2 = ((p2:Person)-[acted:ACTED_IN*1..1]->(movie:Movie)) WITH avg(p1.age) AS p1_age_avg - MATCH path1 = ((p1:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) - MATCH path2 = ((p2:Person)<-[acted:ACTED_IN*1..1]-(movie:Movie)) + MATCH path1 = ((p1:Person)-[acted:ACTED_IN*1..1]->(movie:Movie)) + MATCH path2 = ((p2:Person)-[acted:ACTED_IN*1..1]->(movie:Movie)) WHERE (p1.age < p1_age_avg) RETURN * LIMIT 5000` @@ -495,7 +495,6 @@ func TestV2SingleEntityWithLowerLike(t *testing.T) { t.Log(*cypher) answer := `MATCH path1 = ((p1:Person)) - MATCH path1 = ((p1:Person)) WHERE (toLower(p1.name) =~ (".*" + "john" + ".*")) RETURN * LIMIT 5000` @@ -550,7 +549,7 @@ func TestV2Like(t *testing.T) { } t.Log(*cypher) - answer := `MATCH path_0 = ((id_1691576718400:Employee)<-[id_1691576720177:REPORTS_TO]-()) + answer := `MATCH path_0 = ((id_1691576718400:Employee)-[id_1691576720177:REPORTS_TO]->()) WHERE (id_1691576718400.title =~ (".*" + "ale" + ".*")) RETURN * LIMIT 500` -- GitLab