neo4j-contrib / neo4j-graph-algorithms

Efficient Graph Algorithms for Neo4j
https://github.com/neo4j/graph-data-science/
GNU General Public License v3.0
770 stars 195 forks source link

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

Open GittiHab opened 5 years ago

GittiHab commented 5 years ago

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!

mneedham commented 5 years ago

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"})
GittiHab commented 5 years ago

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 commented 5 years ago

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

tomasonjo commented 5 years ago

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"})
GittiHab commented 5 years ago

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?