neo4j-graph-algorithms icon indicating copy to clipboard operation
neo4j-graph-algorithms copied to clipboard

Can't load a graph via graph.load with cypher

Open GittiHab opened this issue 6 years ago • 5 comments

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!

GittiHab avatar Feb 04 '19 14:02 GittiHab

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"})

mneedham avatar Feb 04 '19 14:02 mneedham

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. screenshot 2019-02-05 at 10 50 15

GittiHab avatar Feb 05 '19 09:02 GittiHab

Also, nothing is logged – so it's hard to tell where that comes from.

GittiHab avatar Feb 05 '19 10:02 GittiHab

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"})

tomasonjo avatar Feb 05 '19 10:02 tomasonjo

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?

GittiHab avatar Feb 05 '19 10:02 GittiHab