5

Creating a named graph from the main Neo4j Graph is documented. Beside, one also knows how to list, drop, check if a named graph already exists, e.g. CALL gds.graph.exists('my-store-graph') YIELD exists;

However, I wonder if there is any method for cypher-query against the just created named graph?

One workaround is to push this named graph into an offline/empty Neo4j Graph, i.e. CALL gds.beta.graph.export('my-graph', { dbName: 'mydatabase' }). However, this method is less convenient because we often want to check if the named graph is projected correcly before applying, e.g. PageRank on it. And the projection can be a trial-and-error cycle.

JoyfulPanda
  • 867
  • 6
  • 14

1 Answers1

3

There is currently no other way of querying the named graph other than the workaround you already found.

However, there are additional functions, e.g. gds.util.nodeProperty that allow you to access a node property in the named graph without writing it back to Neo4j. An example for querying a score property could look like this:

CALL gds.graph.create('my-graph', 'User', 'LINK');
CALL gds.pageRank.mutate('my-graph', { mutateProperty: 'score' });
MATCH (user:User)
WHERE user.name = 'Alice'
RETURN
    user.name AS name,
    gds.util.nodeProperty('my-graph', id(user), 'score') AS score

Could you maybe elaborate why your projections are "trial-and-error" cycles. Maybe an option is to run your validation queries on the subgraph you want to project?

s1ck
  • 158
  • 7
  • In my opinion, it's a trial-and-error cycle because projection using Cypher results in a subgraph. And you want to double check if the subgraph structure is expected in certain ways. Currently, we can't cypher-query against this subgraph conveniently. – JoyfulPanda Jun 04 '20 at 07:36
  • @JoyfulPanda So if I understand correctly, you use a Cypher projection to create a graph, and afterwards you would like to inspect the created graph to make sure it is what you expect? Does inspecting the Cypher queries you use in the `graph.create.cypher()` call directly not give the necessary insights? – Mats_SX Jun 04 '20 at 14:05
  • 1
    @s1ck Correct. I want to make sure the projected graph follows my expectation. In `CALL gds.graph.create.cypher(graphName, nodeQuery, relationshipQuery, configuration)`, one needs 2 queries: one for nodes, one for relationships. I assume it first extracts the nodes, then it extracts relationships, and any relationships whose nodes are not included in the first set are dropped. Thus, it's sometime *not convenient* to reasonate on 2 separate queries about the shape of the projected graph. One might miss some thing... – JoyfulPanda Jun 04 '20 at 16:30
  • @JoyfulPanda Understood, and I agree. Expect this to improve with future versions :) One detail: relationships whose nodes are not in the first set will raise an error in GDS 1.2, which you can change to silent dropping behaviour using a configuration parameter. – Mats_SX Jun 04 '20 at 16:42