Skip to content
Snippets Groups Projects
Commit 8f71433d authored by Sven-Ove Hänsel's avatar Sven-Ove Hänsel
Browse files

update queries

parent e30a7234
Branches
Tags
No related merge requests found
count|MATCH (n) return count(n);
count|MATCH (n) return n;
anc|MATCH path=(node:Host)-[*]->(ancestor) RETURN ancestor, size(path) AS distance_upstream ORDER BY distance_upstream;
desc|MATCH path=(node:Host)<-[*]-(descendant) RETURN descendant, size(path) AS distance_downstream ORDER BY distance_downstream;
path|MATCH path = ((a {_uuid: 'A6A7C956-0132-5506-96D1-2A7DE97CB400'})-[*ALLSHORTEST(r,n|1)]->(b {_uuid:'8DA367BF-36C2-11E8-BF66-D9AA8AFF4A69'})) RETURN path;
......
count|MATCH (n) return count(n);
count|MATCH (n) return n;
anc|MATCH path=(node:Host)-[*]->(ancestor) RETURN ancestor, length(path) AS distance_upstream ORDER BY distance_upstream;
desc|MATCH path=(node:Host)<-[*]-(descendant) RETURN descendant, length(path) AS distance_downstream ORDER BY distance_downstream;
path|MATCH path = shortestPath((a:Subject WHERE a._uuid='0CF2BB3E-36B8-11E8-BF66-D9AA8AFF4A69') -[*]- (b:FileObject WHERE b._uuid = '586C56DA-CB56-745E-96CB-52069E742598')) RETURN path;
path|MATCH path = shortestPath((a WHERE a._uuid='A6A7C956-0132-5506-96D1-2A7DE97CB400') -[*]-> (b:FileObject WHERE b._uuid = '8DA367BF-36C2-11E8-BF66-D9AA8AFF4A69')) RETURN path;
2-hop|MATCH (startNode WHERE startNode._uuid = '9FF334BB-9072-D756-B290-556656D73728')-[*1..2]-(neighborhood) RETURN neighborhood;
count|MATCH (n) return count(n);
count|MATCH (n) return n;
anc|MATCH path=(node:Host)-[*]->(ancestor) RETURN ancestor, length(path) AS distance_upstream ORDER BY distance_upstream;
desc|MATCH path=(node:Host)<-[*]-(descendant) RETURN descendant, length(path) AS distance_downstream ORDER BY distance_downstream;
path|MATCH (a:Subject) WHERE a._uuid = '0CF2BB3E-36B8-11E8-BF66-D9AA8AFF4A69' MATCH (b:FileObject) where b._uuid='586C56DA-CB56-745E-96CB-52069E742598' WITH a, b MATCH path = shortestPath((a)-[*]-(b)) RETURN path
path|MATCH (a) WHERE a._uuid = 'A6A7C956-0132-5506-96D1-2A7DE97CB400' MATCH (b:FileObject) where b._uuid='8DA367BF-36C2-11E8-BF66-D9AA8AFF4A69' WITH a, b MATCH path = shortestPath((a)-[*]->(b)) RETURN path
2-hop|MATCH (startNode) -[*1..2]-(neighborhood) WHERE startNode._uuid = '9FF334BB-9072-D756-B290-556656D73728' RETURN neighborhood
\ No newline at end of file
ancestors|WITH RECURSIVE AncestorCTE AS (
count|select * from node_list;
---
anc|WITH RECURSIVE AncestorCTE AS (
SELECT n.node_no, e.dest, n.type, 1 AS Level
FROM node_list n
JOIN edge_list e ON n.uuid = e.source
......@@ -14,21 +16,36 @@ ancestors|WITH RECURSIVE AncestorCTE AS (
)
SELECT DISTINCT node_no, dest, type, Level FROM AncestorCTE;
---
descendant|WITH RECURSIVE DescendantCTE AS (
SELECT n.node_no, e.source, 1 AS Level
FROM node_list n
JOIN edge_list e ON n.uuid = e.dest
WHERE n.node_no = 1 -- Replace with the desired starting node_no
desc|WITH RECURSIVE NodeCTE AS (
-- Initial selection
SELECT
n.node_no,
e.source,
e.dest,
1 AS Level
FROM
node_list n
JOIN
edge_list e ON n.uuid = e.dest
WHERE
n.node_no = 1 -- Replace with the desired starting node_no
UNION ALL
SELECT n.node_no, e.source, a.Level + 1
FROM node_list n
JOIN edge_list e ON n.uuid = e.dest
JOIN DescendantCTE a ON e.source = n.uuid
WHERE a.Level < 3 -- Replace with the desired level
-- Recursive selection
SELECT
n.node_no,
e.source,
e.dest,
c.Level + 1 AS Level
FROM
edge_list e
JOIN
NodeCTE c ON e.dest = c.source
JOIN
node_list n ON e.dest = n.uuid
)
SELECT DISTINCT node_no, source, Level FROM DescendantCTE;
SELECT * FROM NodeCTE;
---
path|WITH RECURSIVE search_path(edge_no, path, dest, visited, depth) AS (
SELECT
......@@ -73,7 +90,7 @@ SELECT
FROM
shortest_paths;
---
k-hop|WITH hop1 AS (
2-hop|WITH hop1 AS (
SELECT DISTINCT e.source, e.dest
FROM edge_list e
WHERE e.source = '9FF334BB-9072-D756-B290-556656D73728'
......@@ -95,4 +112,4 @@ FROM (
UNION ALL
SELECT dest FROM hop2
) AS all_nodes
--WHERE node <> '9FF334BB-9072-D756-B290-556656D73728'
WHERE node <> '9FF334BB-9072-D756-B290-556656D73728'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment