Merge pull request #153 from mataevs/exceptop
Except/Not Operator for Gremlin.
This commit is contained in:
commit
c2fab568c7
5 changed files with 238 additions and 0 deletions
|
|
@ -298,6 +298,21 @@ func buildIteratorTreeHelper(obj *otto.Object, qs graph.QuadStore, base graph.It
|
|||
it = buildIteratorTreeHelper(arg.Object(), qs, subIt)
|
||||
case "in":
|
||||
it = buildInOutIterator(obj, qs, subIt, true)
|
||||
case "except":
|
||||
arg, _ := obj.Get("_gremlin_values")
|
||||
firstArg, _ := arg.Object().Get("0")
|
||||
if !isVertexChain(firstArg.Object()) {
|
||||
return iterator.NewNull()
|
||||
}
|
||||
|
||||
allIt := qs.NodesAllIterator()
|
||||
toComplementIt := buildIteratorTree(firstArg.Object(), qs)
|
||||
notIt := iterator.NewNot(toComplementIt, allIt)
|
||||
|
||||
and := iterator.NewAnd()
|
||||
and.AddSubIterator(subIt)
|
||||
and.AddSubIterator(notIt)
|
||||
it = and
|
||||
}
|
||||
return it
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,6 +120,20 @@ var testQueries = []struct {
|
|||
tag: "acd",
|
||||
expect: []string{"D"},
|
||||
},
|
||||
{
|
||||
message: "use Except to filter out a single vertex",
|
||||
query: `
|
||||
g.V("A", "B").Except(g.V("A")).All()
|
||||
`,
|
||||
expect: []string{"B"},
|
||||
},
|
||||
{
|
||||
message: "use chained Except",
|
||||
query: `
|
||||
g.V("A", "B", "C").Except(g.V("B")).Except(g.V("C")).All()
|
||||
`,
|
||||
expect: []string{"A"},
|
||||
},
|
||||
|
||||
// Morphism tests.
|
||||
{
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ func (wk *worker) embedTraversals(env *otto.Otto, obj *otto.Object) {
|
|||
obj.Set("Has", wk.gremlinFunc("has", obj, env))
|
||||
obj.Set("Save", wk.gremlinFunc("save", obj, env))
|
||||
obj.Set("SaveR", wk.gremlinFunc("saver", obj, env))
|
||||
obj.Set("Except", wk.gremlinFunc("except", obj, env))
|
||||
obj.Set("Difference", wk.gremlinFunc("except", obj, env))
|
||||
}
|
||||
|
||||
func (wk *worker) gremlinFunc(kind string, prev *otto.Object, env *otto.Otto) func(otto.FunctionCall) otto.Value {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue