Search code examples
performancecyphertraversal

Traversing Graph using Cypher and presenting resultset as a table


Greeting to All!

I am a beginner with Neo4j and Cypher and have a problem with the following functionality:

  1. I have a acyclic directed graph of Nodes that are connected with :DATA_FLOWS edges

  2. There could be more than one edge between two Nodes as these edges could have different Edge property - scenario_id

  3. When I select one or more nodes (by group) and try to filter by one or more scenario_id (property of the edge) I would like to see all the dependent Nodes of a certain depth (*..n) that depend on my selection and edge filter

  4. I am using the following query: match p= (src:Node)-[:DATA_FLOWS*..5]->(dst:Node) where src.group_id IN {Group} and all(x in RELATIONSHIPS(p) WHERE x.scenario_id IN {Scenario} ) RETURN p;

  5. This looks OK in Neo4j browser that presents the results in a nice visual way, but I need to run this query in Tom Sawyer Perspective, which expects flat table-like result set, rather than Json...

  6. So my query, after too many unsuccessful attempts, looks like: match p= (src:Node)-[:DATA_FLOWS*..5]->(dst:Node) where src.group_id IN {Group} and all(x in RELATIONSHIPS(p) WHERE x.scenario_id IN {Scenario} ) WITH p MATCH (a)-[r:DATA_FLOWS]->(b) where all(x in RELATIONSHIPS(p) WHERE ID(x) = ID(r)) RETURN a.id, r.scenario_id, b.id

  7. I don't think it brings correct results and it is extremely slow...

I would greatly appreciate if anyone provides me any suggestions on how to improve, rewrite, etc this query and get a better performance.

Thank you in advance, Vlad


Solution

  • To formulate neo4j data in a tabular way, you should consider using the neo4j-jdbc driver which allows you to access a neo4j database as if it were any other relational database.

    I'm not familiar with Tom Sawyer Perspective, but it's really common for visualization tools to support pulling data from a JDBC connection, so this might make your life a lot easier, and mean that you don't even have to export data to a tabular file format (CSV) before you bring it into your tool.