Orientdb - Traverse all possible N degree separation paths between vertexes - orientdb2.2

Is it possible to find out all possible paths with N degree of separation between two nodes in Orientdb?

Try this:
SELECT $path FROM ( TRAVERSE out() FROM (select from entities where id ='A') WHILE $depth <= N ) where id ='B'

Related

Neo4j expand path and return distinct nodes and relationships

I have given one or more start nodes (by ID) and I need to expand over one or more hops and return one result with an array of distinct nodes and and array of distinct relationships.
I can do this either via apoc.path.expand() or apoc.path.subgraphAll(), but either way it produces multiple rows for each expanded path, and therefore may contain duplicate nodes. To reduce the multiple rows into one row, I have used collect() with apoc.coll.toSet() and apoc.coll.flatten() to remove duplicates from the nodes and relationships array:
apoc.path.subgraphAll:
MATCH (n) WHERE id(n) IN $ids
CALL apoc.path.subgraphAll(n, { minLevel: 1, maxLevel: 2 }) YIELD nodes, relationships
WITH collect(nodes) as nodes, collect(relationships) as relationships
RETURN apoc.coll.toSet(apoc.coll.flatten(nodes)) as nodes, apoc.coll.toSet(apoc.coll.flatten(relationships)) as relationships
apoc.path.expand:
MATCH (n) WHERE id(n) IN $ids
CALL apoc.path.expand(n, null, null, 1, 2) YIELD path
WITH collect(nodes(path)) as nodes, collect(relationships(path)) as relationships
RETURN apoc.coll.toSet(apoc.coll.flatten(nodes)) as nodes, apoc.coll.toSet(apoc.coll.flatten(relationships)) as relationships
Is there another way to remove the duplicates from the two arrays or to query the nodes and relationships?

How to delete nodes without in-edge and out-edge

NebulaGraph version: v3.1.0
How can I delete those nodes which have no links with other nodes?
delete isolated nodes, which has no in-edge and out-edge.
Try the statement as below:
(
lookup on player yield id(vertex) as vid
minus
(lookup on player yield id(vertex) as vid | go 1 step from $-.vid over * bidirect yield distinct id($^) as vid)
)
| delete vertex $-.vid

How to get a hierarchical tree path in SQLite?

Imagine a simple table that defines a tree structure.
create table nodes (
id integer primary key,
name text not null,
parent integer
)
Some example nodes:
Node 1 is parent of 2 and 3. Node 3 is parent of 4. Is it possible to write a SQL query in SQLite, so that it returns:
id path
1 foo
2 foo/bar
3 foo/baz
4 foo/baz/stuff
You can perform recursion in SQLite using recursive common table expressions.
An example query that would return the node paths:
with recursive paths(id, name, path) as (
select id, name, name from nodes where parent is null
union
select nodes.id, nodes.name, paths.path || '/' || nodes.name
from nodes join paths where nodes.parent = paths.id
)
select id, path from paths

Get relationship node from 2 edges in 1 cypher query

I need a cypher query that retrieves the weight of two edges at the same time. This is my attempt:
MATCH (n:User)-[r:VIEWED|UPDATED]->(f:File) WHERE f.id IN 'some_id','another_id'] RETURN n, r.weight, ORDER BY r.weight DESC
The result contains two lines for each user who updated and viewed the file. However, I want the result in one line. For example: user: x - updated: 12 - viewed:15
How can I do this?
UPDATED:
try:
MATCH (f:File)
OPTIONAL MATCH (n:User)-[r1:VIEWED]->(f:File)
OPTIONAL MATCH (n:User)-[r2:UPDATED]->(f:File)
where f.id IN ['some_id','another_id']
return n,
sum(r1.weight) as totalViewedWeight,
sum(r2.weight) as totalUpdatedWeight
MATCH (n:User)-[r:VIEWED|UPDATED]->(f:File)
WHERE f.id IN ['some_id','another_id']
RETURN n, collect(type(r)), collect(r.weight)

Cypher Order By Number of Paths

Let's say I have a graph of movies and directors, where movies are connected to each other by co-viewership. I want to find similar directors, i.e. directors whose films tend to be watched together.
START n=node:index(Name="Steven Spielberg") MATCH n-->m--l<--o RETURN o;
This gets me all of the related directors, but how do I order them by the number of paths that connect them? Bonus points if I can also take weight of the tie between films into consideration.
count(*) is the number of paths that start with n and end with o
START n=node:index(Name="Steven Spielberg")
MATCH n-->m--l<--o
RETURN o,count(*)
order by count(*) desc;
with weights on the relationships
START n=node:index(Name="Steven Spielberg")
MATCH path=n-->m--l<--o
RETURN o,sum(reduce(sum=0,r in rels(path) : sum+r.weight)) as weight
ORDER BY weight desc;
START n=node:index(Name="Steven Spielberg")
MATCH path=n-->m--l<--o
RETURN o
ORDER BY length(path);

Resources