Open Stephaneke opened 4 months ago
Update: the following query below does work (so you can see the result). It is generating all the steps in one create. But the WITH statement should just work as intended? So the bug remains.
SELECT * FROM cypher('my_graph', $$
MATCH (node1:NodeType1)-[rel:RelType]->(node2:NodeType2)
WHERE NOT exists((node1)-[:RelType2]-(:NodeType3)-[:RelType2]-(node2))
AND node1.project = 'PROJECT_ID'
AND node2.project = 'PROJECT_ID'
CREATE (node1)-[:RelType2 {uri: 'https://example.com/ns#RelType2'}]->(newNode:NodeType3 {
name: node1.name + '|' + node2.name,
uri: 'https://example.com/ns#NodeType3',
project: 'PROJECT_ID',
executionType: 'AUTO'
})<-[:RelType2 {uri: 'https://example.com/ns#RelType2'}]-(node2)
RETURN node1, node2, newNode
$$) AS (n1 agtype, n2 agtype, n3 agtype);
A few questions
1
Just reading example queries, thought to ask, are the -[:<rel_type>]-
legitimate.
I am learning cypher, and, at least in the past, it had to have directed expression where at least one of the sides has -> or <- relationships ( looking at Exists ).
I don't think it has any bearing on the question asked, though, just curious regarding cypher expression, hoping on kindness of people to help along the way in more detailed questions on cypher language.
2
It makes sense to check if this graph expression
(node1:NodeType1)-[rel:RelType]->(node2:NodeType2)
is unique, linking one vertice NodeType1 to one vertice NodeType2
If it is, than the WHERE clause below, save for existance check, is not really needed ( that's the beauty of graph ) and if it is not unique and requires further filtering on PROJECT_ID on both sides of node link, than it makes sense to check node design.
3
I noted you were using node1.name + '|' +node2.name in the property design, but for some reason kept on using 'PROJECT_ID' constant, where node1.project seems most natural. Unless in real life this 'PROJECT_ID' really something more complicated. Just trying to make best sense and see how query itself can be worked with, to make it as good and as efficient as it could be ( again, not the question asked, but improving query design seems like of interest, I hope it is positive :) )
4
If I understand intent of using MERGE correctly ( with its general motto "when exists, keep, when missing, add" ) to mimik behavior of statements with MERGE this query needs two MATCH clauses independently checking for relationship
(NodeType1)-[]->(NodeType3) (NodeType2)-[]->(NodeType3)
else it has a risk of creating duplicate link, if one of the links is missing, prior to query execution. Also, looking at "MERGE" in more holistic sense of word, it makes sense, when applied to properties of node instance variable. Since than it has an object instance to really MERGE. However, in the context of ()-[]->() relationship it might or might not be semantical concept ( if it makes sense? ), just first thoughts looking at the code. I will check further and if I am wrong somewhere in my thoughts, I am just trailing the path of "unaware", for the sake of seeing input from your side, if these thoughts make sense. Though, as you mentioned, it works in Neo4j, so, something regarding Merge I don't know/understand at the moment.
This issue is stale because it has been open 60 days with no activity. Remove "Abondoned" label or comment or this will be closed in 14 days.
I am working with Apache AGE and I am trying to create new nodes and relationships based on existing nodes and their relationships. Here is a simplified version of my schema and queries. These can be used to reproduce the problem.
I wanted to look for existing relationships and create new nodes and relationships connected to the found nodes. However, it seems to be able to find the nodes, but when adding the WITH statement, it no longer creates nodes and is unable to find them. This works fine in a neo4j context, so i assume this is a bug with the WITH clause.
Schema Setup
preparation script (if age extension does not exist).
pastable setup script:
Working Query (creates nodes but not relationships)
Failing Query (tries to create relationships, but fails)
This results in the error:
Alternative Query (without WITH clause, also fails)
This also results in the error:
What We Have Tried
WITH
clauses to alias variables.None of these approaches have resolved the issue, and we consistently encounter the vertex deletion error.