From 9450d86881a92c402d6e947ee09a70b6ec619ecd Mon Sep 17 00:00:00 2001 From: Barak Michener Date: Thu, 5 Feb 2015 21:13:30 -0500 Subject: [PATCH 1/2] bench: Add some grunty Not queries to the integration test (derived from existing queries) --- cayley_test.go | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/cayley_test.go b/cayley_test.go index 75ebd00..53e555b 100644 --- a/cayley_test.go +++ b/cayley_test.go @@ -127,6 +127,41 @@ var benchmarkQueries = []struct { }, }, + // Exercises Not().Contains(), as above. + { + message: "the helpless checker, negated (films without Ingrid Bergman)", + long: true, + query: ` + g.V().As("person").In("name").In().In().Out("name").Except(g.V("Ingrid Bergman").In("name").In().In().Out("name")).Is("Casablanca").All() + `, + tag: "person", + expect: [][]interface{}{}, + }, + { + message: "the helpless checker, negated (without actors Ingrid Bergman)", + long: true, + query: ` + g.V().As("person").In("name").Except(g.V("Ingrid Bergman").In("name")).In().In().Out("name").Is("Casablanca").All() + `, + tag: "person", + expect: [][]interface{}{ + {map[string]string{"id": "Casablanca", "person": "Madeleine LeBeau"}}, + {map[string]string{"id": "Casablanca", "person": "Joy Page"}}, + {map[string]string{"id": "Casablanca", "person": "Claude Rains"}}, + {map[string]string{"id": "Casablanca", "person": "S.Z. Sakall"}}, + {map[string]string{"id": "Casablanca", "person": "Helmut Dantine"}}, + {map[string]string{"id": "Casablanca", "person": "Conrad Veidt"}}, + {map[string]string{"id": "Casablanca", "person": "Paul Henreid"}}, + {map[string]string{"id": "Casablanca", "person": "Peter Lorre"}}, + {map[string]string{"id": "Casablanca", "person": "Sydney Greenstreet"}}, + {map[string]string{"id": "Casablanca", "person": "Leonid Kinskey"}}, + {map[string]string{"id": "Casablanca", "person": "Lou Marcelle"}}, + {map[string]string{"id": "Casablanca", "person": "Dooley Wilson"}}, + {map[string]string{"id": "Casablanca", "person": "John Qualen"}}, + {map[string]string{"id": "Casablanca", "person": "Humphrey Bogart"}}, + }, + }, + //Q: Who starred in both "The Net" and "Speed" ? //A: "Sandra Bullock" { @@ -585,26 +620,34 @@ func BenchmarkHelplessContainsChecker(b *testing.B) { runBench(3, b) } -func BenchmarkNetAndSpeed(b *testing.B) { +func BenchmarkHelplessNotContainsFilms(b *testing.B) { runBench(4, b) } -func BenchmarkKeanuAndNet(b *testing.B) { +func BenchmarkHelplessNotContainsActors(b *testing.B) { runBench(5, b) } -func BenchmarkKeanuAndSpeed(b *testing.B) { +func BenchmarkNetAndSpeed(b *testing.B) { runBench(6, b) } -func BenchmarkKeanuOther(b *testing.B) { +func BenchmarkKeanuAndNet(b *testing.B) { runBench(7, b) } -func BenchmarkKeanuBullockOther(b *testing.B) { +func BenchmarkKeanuAndSpeed(b *testing.B) { runBench(8, b) } +func BenchmarkKeanuOther(b *testing.B) { + runBench(9, b) +} + +func BenchmarkKeanuBullockOther(b *testing.B) { + runBench(10, b) +} + // reader is a test helper to filter non-io.Reader methods from the contained io.Reader. type reader struct { r io.Reader From cd35572b6c1703e9c6ffb25501fc51fd1a910a86 Mon Sep 17 00:00:00 2001 From: Barak Michener Date: Thu, 5 Feb 2015 21:30:43 -0500 Subject: [PATCH 2/2] Update the docs, fixes #205 --- docs/GremlinAPI.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/GremlinAPI.md b/docs/GremlinAPI.md index 5048f6e..144b425 100644 --- a/docs/GremlinAPI.md +++ b/docs/GremlinAPI.md @@ -289,6 +289,27 @@ var dFollows = g.V("D").Out("follows") // People followed by both C (B and D) and D (B and G) -- returns B (from C), B (from D), D and G. cFollows.Union(dFollows) ``` +####**`path.Except(query)`** + +Alias: `path.Difference` + +Arguments: + + * `query`: Another query path, the result sets of which will be intersected and negated + +Removes all paths which match `query` from `path`. + +In a set-theoretic sense, this is (A - B). While `g.V().Except(path)` to achieve `U - B = !B` is supported, it's often very slow. + +Example: +```javascript +var cFollows = g.V("C").Out("follows") +var dFollows = g.V("D").Out("follows") +// People followed by both C (B and D) and D (B and G) -- returns B. +cFollows.Except(dFollows) // The set (D) -- what C follows that D does not also follow. +// Equivalently, g.V("C").Out("follows").Except(g.V("D").Out("follows")) +``` + ### Using Morphisms