0

This is the data setup:

select * from cypher('test', $$ CREATE (david:Person {name: 'David'})
CREATE (alice:Person {name: 'Alice'})
CREATE (bob:Person {name: 'Bob'})
CREATE (charlie:Person {name: 'Charlie'})
CREATE (eve:Person {name: 'Eve'})

CREATE (david)-[:FRIEND]->(alice)
CREATE (david)-[:FRIEND]->(bob)
CREATE (david)-[:FRIEND]->(charlie)
CREATE (david)-[:FRIEND]->(eve)
CREATE (alice)-[:FRIEND]->(bob)                                    
CREATE (charlie)-[:FRIEND]->(bob)
CREATE (eve)-[:FRIEND]->(frank:Person {name: 'Frank'})
CREATE (frank)-[:FRIEND]->(eve) 
CREATE (alice)-[:FRIEND]->(charlie) $$ ) as (a agtype);

Im searching for the query that returns the person that is a friend of David and has 2 or more outgoing relationships. According to the documantation this query should do it:

SELECT *
FROM cypher('graph_name', $$
    MATCH (david {name: 'David'})-[]-(otherPerson)-[]->()
    WITH otherPerson, count(*) AS foaf
    WHERE foaf > 1
    RETURN otherPerson.name
$$) as (name agtype);

However this returns Alice, Eve, and Charlie. It is like the WHERE clause is completely ignored. What is the correct query?

cybersam
  • 63,203
  • 6
  • 53
  • 76
  • Your DB may have had existing nodes/relationships before you created the new data. Try deleting and recreating. Or, perhaps you need to use `(david:Person ...)` to be specific about the label. – cybersam Mar 20 '23 at 18:59
  • there is no existing data and adding the label didnt change anything – Panagiotis Foliadis Mar 20 '23 at 19:11
  • Your sample Cypher code returns only `Alice` on neo4j 4.4.9. So this might be a bug in `apache-age`. – cybersam Mar 20 '23 at 19:15

2 Answers2

2

This was a bug that is fixed recently (i.e WITH ignoring WHERE clause). So until now, the newest release that is v1.2.0 doesn't incorporate this fix.

If you want to make it work, pull the recent changes from github repo https://github.com/apache/age and rebuild age.

Here is what I get as output on my machine

with/where

0

It does appear that Apache AGE is ignoring the WHERE clause inside the cypher function. One way you could do it is by using the WHERE clause outside the cypher function and adding foaf at the RETURN clause, just like this:

SELECT * FROM cypher('test', $$
    MATCH (david {name: 'David'})-[]-(otherPerson)-[]->() 
    WITH otherPerson, count(*) AS foaf 
    RETURN otherPerson.name, foaf 
    $$) as (name agtype, foaf agtype)
    WHERE foaf > 1;

This query returns every person's name that is a friend of David and has 2 or more outgoing relationships. According to the data provided it would be Alice. the return of the query, returning only the node of Alice

Wendel
  • 763
  • 1
  • 12