Last active
December 18, 2023 03:08
-
-
Save pbnjay/1645574ffbe5abb73b41 to your computer and use it in GitHub Desktop.
Some examples for testing traversal in the Gremlin-Cayley dialect.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var movie1 = g.V().Has("name", "The Net") | |
var movie2 = g.V().Has("name", "Speed") | |
var actor1 = g.V().Has("name", "Sandra Bullock") | |
var actor2 = g.V().Has("name", "Keanu Reeves") | |
//////////////////////////////////// | |
// (film) -> starring -> (actor) | |
var filmToActor = g.Morphism().Out("/film/film/starring").Out("/film/performance/actor") | |
// (actor) -> starring -> [film -> starring -> (actor)] | |
var coStars1 = g.Morphism().In("/film/performance/actor").In("/film/film/starring").Save("name","costar1_movie").Follow(filmToActor) | |
var coStars2 = g.Morphism().In("/film/performance/actor").In("/film/film/starring").Save("name","costar2_movie").Follow(filmToActor) | |
// Stars for the movies "The Net" and "Speed" | |
var m1_actors = movie1.Save("name","movie1").Follow(filmToActor) | |
var m2_actors = movie2.Save("name","movie2").Follow(filmToActor) | |
//////////////////////////////////// | |
//Q1: Who starred in both "The Net" and "Speed" ? | |
//A1: "Sandra Bullock" | |
//m1_actors.Intersect(m2_actors).Out("name").All() | |
// Memstore: 7-10ms | |
// LevelDB: 19-25ms | |
// Mongo: > 2m (timeout) | |
//Q2: Did "Keanu Reeves" star in "The Net" ? | |
//A2: No | |
//actor2.Intersect(m1_actors).Out("name").All() | |
// Memstore: 3-7ms | |
// LevelDB: 7-11ms | |
// Mongo: 19s | |
//Q3: Did "Keanu Reeves" star in "Speed" ? | |
//A3: Yes | |
//actor2.Intersect(m2_actors).Out("name").All() | |
// Memstore: 4-7ms | |
// LevelDB: 8-12ms | |
// Mongo: 37s | |
//Q4: Has "Keanu Reeves" co-starred with anyone who starred in "The Net" ? | |
//A4: "Keanu Reeves" was in "Speed" and "The Lake House" with | |
// "Sandra Bullock", who was in "The Net" | |
actor2.Follow(coStars1).Intersect(m1_actors).Out("name").All() | |
// Memstore: 101-111ms | |
// LevelDB: 470-636ms | |
// Mongo: > 5m (w/ 2m timeout? bug?) | |
//Q5: Do "Keanu Reeves" and "Sandra Bullock" have any commons co-stars? | |
//A5: Yes, many. For example: SB starred with "Steve Martin" in "The Prince | |
// of Egypt", and KR starred with Steven Martin in "Parenthood". | |
//actor1.Save("name","costar1_actor").Follow(coStars1).Intersect( | |
// actor2.Save("name","costar2_actor").Follow(coStars2)).Out("name").All() | |
// Memstore: 14.8s | |
// LevelDB: 1m7s - 1m8s | |
// Example Q5 result output interpretation: | |
// "Sandra Bullock" co-starred with "Steve Martin" in the "Prince of Egypt", | |
// and "Keanu Reeves" and "Steve Martin" were both in "Parenthood" | |
// | |
// "costar1_actor": "Sandra Bullock", | |
// "costar1_movie": "The Prince of Egypt", | |
// "costar2_actor": "Keanu Reeves", | |
// "costar2_movie": "Parenthood", | |
// "id": "Steve Martin" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Highly scientific and precise benchmarking method: hitting "Run Query" multiple times, watching the logs on stderr, and throwing out obvious outliers. 15" MBPr, 2.7Ghz i7, 16GB RAM.