I have a question about the graph editor. How can I keep the vertices fixed when I select some vertices? Now if I select some new vertices, the old vertices will move automatically.
If you want see the vertices from Car and Company and both classes extends V you can run this command:
select from V
this is the output:
Instead if you have some edges between this two classes you can still use the command above or, if you want to see which Company made a Car, you can use this command:
select name,out('made_by').name as Company from Car unwind Company
this is the output:
Hope it helps
Regards
For all I know, you can't keep fixed the old vertices.
Related
I'm not sure the title is the best way to phrase it, here's the structure:
Structure
Here's the db json backup if you want to import it to test it: http://pastebin.com/iw2d3uuy
I'd like to get the Dishes eaten by the Humans living in Continent 1 until a _Parent Human moved to Continent 2.
Which means the target is Dish 1 & 2.
If a parent moved to another Continent, I don't want their dish nor the dishes of their children, even if they move back to Continent 1.
I don't know if it matters, but a Human can have multiple children.
If there wasn't the condition about the children of a Human who has moved from the Continent, this query would have worked:
SELECT expand(in('_Is_in').in('_Lives').in('_Eaten_by'))
FROM Continent WHERE continent_id = 1
But I guess here we're forced to use (among other things)
TRAVERSE out('_Parent') FROM Human WHILE
I've tried to use the while of traverse with a subquery to get all the Humans I'm interested in, before to try to get the Dishes, but I'm not even sure we can use while with a subquery.
I hope the structure will help other users to quickly find out if this query is useful to them. If anyone is wondering, I used the Graph tab of OrientDB Studio to make it, along with GIMP.
As a bonus, if anyone knows the Gremlin syntax, it would also be useful to learn it.
Please feel free to edit this post as you see fit and contribute your thoughts :)
SELECT expand(in('_Eaten_by'))
FROM (TRAVERSE out('_Parent')
FROM (SELECT from Human WHERE in('_Parent').size() = 0)
WHILE out('_Lives').out('_Is_in').continent_id = 1)
Explanation:
TRAVERSE out('_Parent')
FROM (SELECT FROM Human WHERE in('_Parent').size() = 0)
WHILE out('_Lives').out('_Is_in').continent_id = 1
returns Human 1 and 2.
That query traverses Human, starting from Human 1 while the Human is connected to Continent 1.
It starts from in('_Parent').size() = 0 which are the Humans without any _Parent (there's only Human 1 in this case) (size() is the size of the collection of vertices coming in from _Parent).
And SELECT expand(in('_Eaten_by')) FROM
gets the Dishes, starting from the Humans we got from the traversal and going through the edge _Eaten_by.
Note: be sure to always use ' around the vertices and edges names, otherwise the names don't seem to be taken in account.
I'm working with OrientDB (2.2.10) and occasionaly I would like to visually inspect my dataset to make sure I'm doing things correctly. On this page of OrientDB http://orientdb.com/orientdb/ you see a nice visualization of a large graph with the following query:
select * from V limit -1;
So I tried the same query on my dataset but the result is so extremely sluggish that I can't work with it. My dataset is not extremely large (few hundred vertices, couple thousand edges) but still the result is unworkable. I tried all major browsers but with all I have the same result. Also my computer is not underpowered, I have a quad-core i7 with 16GB RAM.
As a very simple example I have the following graph:
BAR --WITHIN---> CITY --LOCATED_IN--> COUNTRY
Here: Find "friends of friends" with OrientDB SQL I was able to get at least an example of how to do this type of query on a graph. I managed to get a subset of my graph for example as follows:
select expand(
bothE('WITHIN').bothV()
) from Bar where barName='Foo' limit -1
This get's me the graph of 1 Bar vertex, the edge WITHIN and the City vertex. But if I now want to go one step further by also fetching the country which the city is located in I cannot get this style of query to work for me. I tried this:
select expand(
bothE('WITHIN').bothV()
.bothE('LOCATED_IN').bothV()
) from Bar where barName='Foo' limit -1
This results in the same subset being shown. However, if I first run the first query and then without clearing the canvas run the second query I do get the 3 vertices. So it seems I'm close but I would like to get all 3 vertices and it's edges in one query, not having to run first the one and then the other. Could someone point me in the right direction?
If you want to get all three vertices, it would be much easier start from the middle (city) and than get in and out to get bar and contry. I've tried with a similar little structure:
To get city, bar name and country you can try a query like this:
select name, in("WITHIN").name as barName,out("LOCATED_IN").name as barCountry from (select from City where name='Milan') unwind barName, barCountry
And the output will be:
Hope it helps.
If it is not suitable for your case, let me know.
You could use
traverse * from (select from bar where barName='Foo') while $depth <= 4
Example: I tried with this little graph
and I got
Hope it helps.
I have an orientdb database with a few million vertices and a few hundred million edges. Some vertices have hundreds of thousands of edges associated with them.
I want to execute random walks on this graph. We'd be content, for now, to get simple random walks working.
To achieve this, my goal is to be able to pick a random edge attached to a specific vertex. What is the best way to do this?
Say I have a highly connected vertex of class "metadata" at #17:0.
I have a bunch of lightly connected vertex class "documents".
I have an edge class "metadata_of"
The metadata #17:0 has 200,000 "metadata_of" edges connecting it to 200,000 different document vertices.
I want to go from a metadata object, through a randomly selected metadata_of object, to the corresponding document object.
I had hoped to be able to run a random order sort to be able to get back a single random edge, but random functionality appears to be a pending enhancement filed back in January of 2014 - https://github.com/orientechnologies/orientdb/issues/1946 and there has been no apparent activity on it since June of 2015.
It seems like a potential way to go about this would be to retrieve the size of the inE value (in my case), then generate a random integer i between the size 0 and len(inE). From there, I want to retrieve edge[i] from the set of inE for a given vertex. I thought I had something like this working conveniently in Gremlin but on re-evaluation it doesn't appear to be working at speed - rather, it appears to be traversing the inE list until it reaches index X. Usually better than retrieving all 200k edges, but not ideal for performance.
gremlin> g = new OrientGraph("remote:localhost/mydb");
Oct 06, 2015 11:03:54 PM com.orientechnologies.common.log.OLogManager log
==>orientgraph[remote:localhost/activeint]
gremlin> v1 = g.v("#17:0")
==>v(concept)[#17:0]
gremlin> v1.inE[554] (this took about 4 seconds)
==>e[#18:8628863][#13:305536-metadata_of->#17:0]
What is the most sensible way to, given a specific vertex, select random edge attached to it?
I've created this following function in javascript with #rid like parameter:
var g=orient.getGraph();
var c=g.command("sql","select out('metadata_of').size() as num from "+rid);
var rand=Math.floor((Math.random() * c[0].getProperty('num')-1) + 0);
var pick=g.command("sql","select expand(out('metadata_of')['"+rand+"']) from "+rid);
return pick;
You can call the function in studio in this way:
select expand(getRandomEdge(12:0)) from (select getRandomEdge(12:0))
P.S Pay attention to insert a valid #rid
OrientDB Server v2.0.10 ,
I am trying to come up with a query for the following scenario.
I have 2 hierarchies: A->B->C and D->E->F
The number of nodes in the hierarchy can change.
The node in 1st hierarchy can be connected to the other hierarchy using some relation say 'Assigned'.
What I want is the parent node of the 2nd hierarchy if there is any incoming edge to any of the node in that 2nd hierarchy from the 1st.
For example, say we have Car-Child->Engine-Child->Piston and Country-Child->State-Child->City
And a relationship Made_In which relates Car or Engine or Piston to either Country or State or City
So if there is a relation with either of Country or State or City, the Country should be returned. Example, Engine1-Made_In->Berlin, this would return Germany.
Sorry for such a toyish example. I hope it is clear.
Thanks.
You should consider reading the chapter about "traversing" - that should be the missing link to answer your question. You can find it here: http://orientdb.com/docs/last/SQL-Traverse.html
Basically, if you think of your graph as a family tree, you want to achieve 3 things:
Find all children, grand-children, grand-grand-children (and so on) from tree 1 for a given family member (=Hierarchy1)
Find those who have relations to members of another family tree (=ASSIGNED)
Show me who's on top of this tree (=Hierarchy2)
One of the possible solutions should look a little something like this:
Since you want to end up on top of hierarchy2, you have to start on the other side, i.e. hierarchy1.
Get hierarchy1 (top-to-bottom)
TRAVERSE out("CHILD") FROM Car
Choose all relations
SELECT out("MADE_IN) FROM ([1])
and from those, go bottom-to-top
TRAVERSE in("CHILD") FROM ([2])
Who's on top?
SELECT FROM ([3]) WHERE #class="Country"
Combined into one sql, it looks as ugly as this:
SELECT FROM (
TRAVERSE in("CHILD") FROM (
SELECT out("MADE_IN") FROM (
TRAVERSE out("CHILD") FROM Car
)
)
) WHERE #class="Country"
You could replace Car with any #rid in hierarchy1 to get a list of countries it or any part of it was made in.
There might be better solutions for sure. But at least this one should work, so I hope it will help.
Exploring OrientDB, I am stuck with the following query:
I've a set of classes Package, Library, Application, each with a name as attribute.
I've also a class Person with name and email as attributes.
Relations are defined as classes 'require' or 'writtenBy' from E.
Applications vertices may have 'require' edges to one or more Librarys.
Librarys vertices may have 'require' edges to one or more Packages.
Packages vertices also may have 'require' edges to one or more Packages !
Applications , Librarys, Packages have 'writtenBy' edges to 1 Person; one Person may write several Packages/Library/Application
Given a specific Application/Library or Package rid, I would like to select, as an array, all Persons (name and email) writing its constituents (identified by the 'require' edges) .
I've tried different strategies in OrientDB Studio but can't find a solution. Thanks for any help !
Found it.
Traverse is the way to go:
the solution is something like:
select expand(writtenBy) from (traverse out('require') from #rid )