In NebulaGraph get subgraph statement, the vertex format must be tagName.propName - nebula-graph

Why in the get subgraph statement, I can't use the vertex in the format of tagName.propName like in the go statement.
(root#nebula) [subgraph]> GET SUBGRAPH 6 STEPS FROM "player101" WHERE $$.player.age>50 YIELD VERTICES AS nodes, EDGES AS relationships;
+---------------------------+---------------+
| nodes | relationships |
+---------------------------+---------------+
| [("player101" :player{})] | [] |
+---------------------------+---------------+
Got 1 rows (time spent 5803/7091 us)
Thu, 20 Oct 2022 03:45:11 UTC
(root#nebula) [subgraph]> GET SUBGRAPH 6 STEPS FROM "player101" WHERE player.age>50 YIELD VERTICES AS nodes, EDGES AS relationships;
[ERROR (-1005)]: EdgeName `player' is nonexistent
(root#nebula) [subgraph]> GO FROM "player100" OVER follow WHERE follow.degree > 90 YIELD dst(edge);
+-----------+
| dst(EDGE) |
+-----------+
+-----------+

In the GET SUBGRAPH statement, you cannot use the vertex in the format of tagName.propName because the WHERE clause of the GET SUBGRAPH statement operates on the vertices and edges within the subgraph, rather than on the starting vertex or edge that you specify in the FROM clause.
Therefore, you should specify the vertex or edge properties directly in the WHERE clause using a reference symbol such as &&, rather than using the tagName.propName syntax.
To put it in a simple way, NebulaGraph does not support such a way of use.

Related

Cypher query - Combine 2 queries by pipe result of one to other

I am a beginner on cypher and want to create a query that find all nodes that connect to specific nodes that other node connect to them,
see the example
I need to get all the brown nodes that connect to the red nodes that the blue node connect to it.
for this example I want to get the brown nodes Ids: 2, 3 and 1 (because no red nodes needs to get it)
For now I did it on 2 different queries and use python to find it, but now I need to do this in 1 query.
Match (r:R)-[]-(a:A) return collect(a.Id)
and the second query:
Match (b:B) Optional Match (b)-[]-(a:A) return b.Id, collect(a.Id)
and in my script check if every record from the second query is a subset of the first list of all a.Id that connect to R
can I do it in 1 query?
Thank!
Improved answer:
Start with :B nodes and check if all their :A neighbours are have a link to :R
the ALL() function also returns true if :B does not have any neighbours
MATCH (b:B)
WHERE ALL(n IN [(b)--(a:A) | a] WHERE EXISTS ((n)--(:R)) )
RETURN b

Gremlin Match Traversal that contains a repetitive structure

Hi I am trying to match a subgraph that may have a path of Extends edges.
The known parts are the Vertices with ids 1,2,3 and 6 and their edges.. What is not known is the number of vertices and their ids between 1 and 6. Match starts from vertex with id=1. The match traversal needs to match the whole subgraph with a limit of let's say 10 steps between 4 and 6. In the trivial case vertex with id 6 is directly connected with vertex having id = 1 through edge ContainsB.
Any help is appreciated!
I think this seems to work the way I wanted:
g.V().match(
__.as("s").hasId("1").outE("ContainsB").inV().until(hasId("6")).repeat(out("Extends")).limit(10),
__.as("s").hasId("1").outE("ContainsA").inV().hasId("2"),
__.as("s").hasId("1").outE("ContainsC").inV().hasId("3")
)

How to find the shortest path cost with under special conditions?

Given a weighted directed graph G = (V, E) , a source vertex s , a destination vertex t and a subset v’, how to finds the shortest non-loop path from s to vertex t in the graph? The vertexs in the subset must be included in the path.
This is a variant of Traveling Salesman Problem (TSP).
You can transform your problem to an exact instance of TSP, by running all-to-all shortest path in the graph (Floyd Warshall Algorithm), and then create a new graph:
G'={V' U {s,t}, E'}
V' - the "must go through" subset
E' = { (s,v), (v,t), (u,v) | u,v in V'} (In words: all edges between two nodes in the new graphs)
Now, finding the miminal path that goes through all nodes (TSP) in G', is also the minimal path that meets the criteria (after expending each path between two pairs back).
Unfortunately, TSP is NP-Complete problem (there is no known polynomial time algorithm to solve it, and most believe one doesn't even exist), and unless your set of "must go through nodes" V' is relatively small (and you can afford exponential time running time of the algorithm), you will need to settle on a "good enough" algorithm, which might not be optimal.
Sidenote regarding "no loops" - note it might be infeasible, for example:
---------
| |
v |
s -> a -> b -> c
|
|
t
In this example, the only path to meet the criteria is s->a->b->c->t

create complex gremlin-java query

I have model implemented in titan graph database with relations presented below:
[A] ---(e1)---> [B] <---(e2)--- [C] ---(e3)---> [D]
| | | | | | |
prop:id | prop:number | | label:e3 |
| | prop:id |
label:e1 label:e2 prop:number
prop:prop1
A and B are "main vertices" (for example users), vertices B and C are "less important vertices" describing some data connected with users.
The input for the query algorithm is property id of vertex A.
I want to find all such vertices D, that are connected with A in the manner shown above. What's more I want to remember the property prop1 of the edge e1 between A and B.
More precisely, I want to efficiently retrieve pairs (prop1, numberD) where prop1 is the property of edge between A -> B (if the edge has this property), and numberD is the property number from D.
I don't know how to efficiently implement this query.
It is easy to retrieve only vertices D (using GremlinPipes):
pipe
.start(startVertex)
.outE("e1")
.inV().hasProperty("number")
.inE("e2")
.outV().hasProperty("id")
.outE("e3")
.inV().hasProperty("number");
But problems occur when I need to get also edges e1 and match them with vertices D.
I tried to compute all these steps separately, but is seems to be very inefficient.
Do you have any suggestions how to implement this (maybe using several queries) using gremlin-java or gremlin-groovy?
Thanks!
Take a look at the Pattern Match Pattern described here:
https://github.com/tinkerpop/gremlin/wiki/Pattern-Match-Pattern
startVertex.outE('e1').as('e')
.inV().hasProperty('number').inE("e2")
.outV().hasProperty("id")
.outE("e3")
.inV().hasProperty("number").as('d')
.table(t)
This should give an iterator of maps
[e:e1, d:D]
From each of these maps, you can easily extract the properties you are interested in.

How to count leaf node from graph database Neo4j?

http://imageshack.us/photo/my-images/707/graphpw.png/
I would like to know how I can get the number of leaf node from certain node using method or something in neo4j ?
Example.
At Node A --> contains 12 leaf nodes
At Node B --> contains 6 leaf nodes
Thanks in advance.
I would model the intermediate relationships as contains and the leaf relationships as leaf, see http://console.neo4j.org/r/ulo3yc
Then, you can do
With a setup of
create (f1{name:'folder1'}), ({name:'root'})-[:contains]->(f1)-[:leaf]-> (f2{name:'folder2'}), f1-[:leaf]->({name:'folder3'})
you can do something like
start root=node(1)
match root-[:contains*0..]->()-[:leaf]->leaf
return leaf
returning
+-------------------------+
| leaf |
+-------------------------+
| Node[2]{name:"folder2"} |
| Node[3]{name:"folder3"} |
+-------------------------+

Resources