I'm new to Cypher, self taught so far. I've managed to get creative with basic queries but am now hitting something I have no idea how to achieve....
Given a list of job ID dependencies:
│"A"│"Rel" │"B"│
│29 │"DependantOn" │8 │
│21 │"DependantOn" │8 │
│20 │"DependantOn" │8 │
│22 │"DependantOn" │8 │
│24 │"DependantOn" │9 │
│25 │"DependantOn"│9 │
│23 │"DependantOn"│9 │
│26 │"DependantOn"│11│
│20 │"DependantOn"│11│
│22 │"DependantOn"│11│
│31 │"DependantOn"│23│
│8 │"DependantOn"│1│
│11 │"DependantOn"│1│
│29 │"DependantOn"│1│
│20 │"DependantOn"│1│
│20 │"DependantOn"│10│
│30 │"DependantOn"│10│
│30 │"DependantOn"│20│
│16 │"DependantOn"│5│
│16 │"DependantOn"│5│
│17 │"DependantOn"│5│
│12 │"DependantOn"│5│
│9 │"DependantOn"│2│
│28 │"DependantOn"│2│
│13 │"DependantOn"│2│
│27 │"DependantOn"│13│
│28 │"DependantOn"│13│
│29 │"DependantOn"│15│
│30 │"DependantOn"│15│
│25 │"DependantOn"│14│
│31 │"DependantOn"│14│
│9 │"DependantOn"│3│
│25 │"DependantOn"│3│
│23 │"DependantOn"│3│
│27 │"DependantOn"│3│
│23 │"DependantOn"│12│
│31 │"DependantOn"│12│
│25 │"DependantOn"│6│
│14 │"DependantOn"│6│
│31 │"DependantOn"│6│
│29 │"DependantOn"│7│
│30 │"DependantOn"│7│
│15│"DependantOn"│7│
│10│"DependantOn"│4│
│18│"DependantOn"│4│
│19│"DependantOn"│4│
I'd like to create a table to show the job's run Level based on the longest path and to show that longest path, like a Gnatt chart:
> L1 >>> L2 >>> L3 >>> L4
> 1 >>> 8 >>> 20
> 8 >>> >>> >>> 29
> 8 >>> 21
> 8 >>> 22
> 2 >>> 9 >>> 23
> 3 >>> 9
> 9 >>> 24
> 9 >>> 25
> 4 >>> 10 >>> 20
> 11 >>> 20
> 1 >>> 11 >>> 26
> 1 >>> >>> >>> 20 >>> 30
> 5 >>> 12 >>> >>> >>> 31
> 2 >>> 13 >>> 27
> 3 >>> >>> >>> 23 >>> 31
> 12 >>> 23
> 6 >>> 14 >>> 25
> 7 >>> 15 >>> >>> >>> 29
> 11 >>> 22
> 1 >>> >>> >>> >>> >>> 29
> 10 >>> >>> >>> 30
> 5 >>> 16
> 5 >>> 17
> 2 >>> >>> >>> 28
> 13 >>> 28
> 15 >>> >>> >>> 30
> 14 >>> >>> >>> 31
> 3 >>> >>> >>> 25
> 3 >>> >>> >>> 27
> 6 >>> >>> >>> 25
> 6 >>> >>> >>> >>> >>> 31
> 7 >>> >>> >>> >>> >>> 29
> 7 >>> >>> >>> >>> >>> 30
> 4 >>> 18
> 4 >>> 19
I tried using (:File)-[:DependantOn*3]->(:File)
and collect with
the same for *2, *1, *0
and then sort, but this didn't work. I need some way to identify what's a L1, L2, L3, L4 AND what the longest path is, allocate them to the correct level with the "nulls" becoming ">>>" where applicable.
I can't use [] or () as there are many other nodes and relationships off these nodes (such as file content, data types etc.)
Any pointer would be helpful.
Did you try this?
MATCH p= (start:File)-[:TRIGGER*0..3]->(end:File)
WHERE NOT EXISTS (()-[:DependantOn]->(start))
RETURN end, MAX(length(p))+1 AS level
It would return 29 at L3, where it should be I guess, because it only depends on items at L2