cancel
Showing results for 
Search instead for 
Did you mean: 

Pregel node degree is 0 even if it has relationships

cuneyttyler
Ninja
Ninja

I'm projecting a graph with the below code:

CALL gds.graph.project(
'entityGraph',
'Entity',
'TO_ENTITY'
)

When I use this projected graph in the call to GDS algorithm dijkstra it returns the desired result. However, when I use this graph in my custom pregel function, when I debug info of the given start node's degree, it says 0. I'm absolutely sure that my start node has TO_ENTITY relationships as I see them when I query that node.

My GDS version is 2.0.4

What might be the cause of the pregel displaying degree as zero?

Thanks.

1 ACCEPTED SOLUTION

🙂 As I wrote in my previous reply, I figured that you took that snippet from the examples. And it's also "wrong" there, so I'll add methods that allow the mapping and will also update the example.


 

View solution in original post

11 REPLIES 11

Note, that the node ids that you see in Pregel (or in GDS in general) are not necessarily the same node ids as in the database. When we project the graph (via native or Cypher projection), we map the original node id space to an internal, consecutive node id space: [0, nodeCount).

For example, let's say you project the Neo4j nodes [42, 1337, 1984, 2001] into the in-memory graph. In GDS, those could be mapped to {0 => 42, 1 => 1337, 2 => 1984, 3 => 2001}.

I assume that you want to figure out if the context.nodeId() is the same as some source node id that you passed in via the config?

cuneyttyler
Ninja
Ninja

Thanks for the explanation. My problem is actually with the degree(the number of relationships a node have). I'm sure that given node has relationships and I can see in the output of graph.create method that relationships have been created. Also, when I run core gds functions such as shortestpaths.dijkstra with the same graph, it returns the desired results. The problem is with the pregel. It somehow can't see the relationships of nodes.

Do you have the code available on GitHub so that I can take a look?

All procedures that take node ids as part of their configuration, including gds.shortestPath.dijkstra translate the given node id to the internal node id. Pregel does not do this out of the box, that's why I thought that you end up looking at the wrong node (i.e. node 0 in Pregel is not node 0 in Neo4j). But best to share some code to verify. Pregel is also used for gds.pageRank and works fine, so I assume it's an input problem.

cuneyttyler
Ninja
Ninja

You can see my code here : https://gitlab.com/cuneyttyler/dijkstra-multiple-inputs

Actually, I'm printing the degree for the start node and that's 0.

It seems I don't have access to the repo, getting a 404.

Seems I don't have access to the repo, getting a 404.

Sorry, I made it available now.

Thanks. I had a look and I think the problem is exactly what I described in my first reply. In https://gitlab.com/cuneyttyler/dijkstra-multiple-inputs/-/blob/master/src/main/java/com/semanticspac... you're checking the internal node id against the original node id (the user input). Those are not necessarily the same node entity, so the degree might differ. I suspect that if you run an algo test (using a GDLGraph) with that computation you'll see the correct degrees since the GDL Graph has (by default) the same internal and original id space.

However, I assume you took the Pregel examples as a template and there, we also show it in the same way. I'll will add methods to the ComputeContext which will allow you to map node ids between the id spaces.

Thanks! I didn't realise that. So I was very new when I asked the question but now I also have a look at the GDS Api and saw tests there. Now I'll run a test and see what happens.

EDIT: But  now I realize that in that line where I check for the nodeId == config.startNode() - I didn't write that code. I took it from the Pregel BFS example. So the example also checks if the processed node is the start node this way. Is there something wrong with the Pregel example as well?

🙂 As I wrote in my previous reply, I figured that you took that snippet from the examples. And it's also "wrong" there, so I'll add methods that allow the mapping and will also update the example.


 

PR is open on the interal repo. With a bit of luck it will be in the 2.1 release next week.