-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPath_Finding_6_Longest_paths_examples.cypher
25 lines (24 loc) · 1.35 KB
/
Path_Finding_6_Longest_paths_examples.cypher
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Path Finding - Longest path - Stream - Max. paths as examples
CALL gds.dag.longestPath.stream($dependencies_projection + '-cleaned')
YIELD index, sourceNode, targetNode, totalCost, path
WITH index
,path
,toInteger(totalCost) AS distance
,sourceNode AS sourceNodeId
,targetNode AS targetNodeId
WHERE sourceNodeId <> targetNodeId // Filter out cyclic dependencies
WITH *
,gds.util.asNode(sourceNodeId) AS source
,gds.util.asNode(targetNodeId) AS target
// Optionally get the project (e.g. Java Artifact, Typescript Project) the source and target belong to
OPTIONAL MATCH (sourceProject:Artifact|Project)-[:CONTAINS]->(source)
OPTIONAL MATCH (targetProject:Artifact|Project)-[:CONTAINS]->(target)
// Optionally get the name of the scan that contained that project
OPTIONAL MATCH (sourceScan:TS:Scan)-[:CONTAINS_PROJECT]->(sourceProject)
OPTIONAL MATCH (targetScan:TS:Scan)-[:CONTAINS_PROJECT]->(targetProject)
WITH *, coalesce(source.rootProjectName, sourceScan.name, sourceProject.name) AS sourceContainerName
ORDER BY distance DESC, sourceContainerName ASC
// Only output the top 10 entries
LIMIT 10
// Group by project name, if the target project is the same and the distance. Return those as result.
RETURN distance, index, sourceContainerName, sourceProject, sourceScan, path