neo4j-graph-algorithms
neo4j-graph-algorithms copied to clipboard
Can't load a graph via graph.load with cypher
I am not sure if I am doing something wrong or if there is a bug. I am trying to load a cypher projected graph using the algos.graph.load
procedure. However, if I only give a label as an argument the graph is, as expected, not the whole graph, e.g.
CALL algo.graph.load("my-graph", "Person")
On the other hand, if I try to retrieve the respective nodes using a cypher projection, the graph contains all nodes, e.g.
CALL algo.graph.load("my-other-graph", "MATCH (n:Person) RETURN id(n) as id")
I would expect this to return the same projection – but it doesn't 🤔 . And it doesn't matter what I specify for the relationships either.
So, my request: a) a better documentation is necessary for sure, b) an answer how I can achieve this 😅
Thanks in advance!
For your 2nd example you need to pass in the config graph: 'cypher'
otherwise it treats the value as a label, and (somewhat confusingly I guess) if you provide a non existent label it loads all nodes.
CALL algo.graph.load("my-other-graph", "MATCH (n:Person) RETURN id(n) as id", null,
{graph: "cypher"})
Thanks for your reply @mneedham.
But sadly, that doesn't work as expected either. I get a NullPointerException
when running it like this. I am on Neo4j 3.4.7 with graph-algos 3.4.8 and tried it on a fresh installation.
Also, nothing is logged – so it's hard to tell where that comes from.
Not sure but maybe the cypher loading does not allow null values judging by the error.
Try:
CALL algo.graph.load("my-other-graph", "MATCH (n:Person) RETURN id(n) as id",
MATCH (n)-->(m) RETURN id(n) as source, id(m) as target, {graph: "cypher"})
Ah, that worked! Many thanks!
I would have expected that at least an empty string ""
would have worked – but one has to specify a query for the relationships as well. Is there any way to make neo4j print such errors (NullPointerExceptions
specifically) in the log?