Merge pull request #206 from barakmich/negation_benchmark

bench: Add some grunty Not queries to the integration test (derived from...
This commit is contained in:
Barak Michener 2015-02-08 21:07:55 -05:00
commit ad7649806b
2 changed files with 69 additions and 5 deletions

View file

@ -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

View file

@ -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