Examples:
create class Person extends V
create class Restaurant extends V
Create Vertex (Populate)
Examples:
create vertex Person set name = 'Luca'
create vertex Person set name = 'Bill'
create vertex Person set name = 'Jay'
create vertex Restaurant set name = 'Dante', type = 'Pizza'
create vertex Restaurant set name = 'Charlie', type = 'French'
Create Edge (Relatio)
Examples:
create class Eat extends E
create class Friend extends E
Create Connections
Examples:
create edge Eat from (select from Person where name = 'Luca')
to (select from Restaurant where name = 'Dante')
If you know the RID of vertices you can connect them with a shorter and faster command:
create edge Eat from #11:1 to #12:0
create edge Eat from #11:2 to #12:1
create edge Friend from #11:0 to #11:2
Cross Edges (Join)
To cross edges we can use special graph functions like:
- out(), to retrieve the adjacent outgoing vertices
- in(), to retrieve the adjacent incoming vertices
- both(), to retrieve the adjacent incoming and outgoing vertices
Note: expands() is a special function very useful to transforms a resultset of vertices in a expanded resultset (showing all data).
To know all the people that eat in Dante restaurant we can get Dante's record and then cross back traversing the incoming edges to discover the Person records connected
select expand( in() ) from Restaurant where name = 'Dante'
In the following example we've passed the Edge's class "Friend" as argument of the both() function to cross only the relationships of kind "Friend" (so skip the "Eat" this time).
select expand( both('Friend') ) from Person where name = 'Luca'
Get all the restaurants where go Luca's friends.
select expand( both('Friend').out('Eat') ) from Person where name = 'Luca'
No comments:
Post a Comment