Alpha attempt at in and out predicates.
This commit is contained in:
parent
86ae24f59d
commit
f775756ad1
3 changed files with 29 additions and 0 deletions
|
|
@ -139,6 +139,15 @@ func buildInOutIterator(obj *otto.Object, qs graph.QuadStore, base graph.Iterato
|
|||
return iterator.NewHasA(qs, and, out)
|
||||
}
|
||||
|
||||
func buildInOutPredicateIterator(obj *otto.Object, qs graph.QuadStore, base graph.Iterator, isReverse bool) graph.Iterator {
|
||||
dir := quad.Subject
|
||||
if isReverse {
|
||||
dir = quad.Object
|
||||
}
|
||||
lto := iterator.NewLinksTo(qs, base, dir)
|
||||
return iterator.NewHasA(qs, lto, quad.Predicate)
|
||||
}
|
||||
|
||||
func buildIteratorTreeHelper(obj *otto.Object, qs graph.QuadStore, base graph.Iterator) graph.Iterator {
|
||||
// TODO: Better error handling
|
||||
var (
|
||||
|
|
@ -315,6 +324,10 @@ func buildIteratorTreeHelper(obj *otto.Object, qs graph.QuadStore, base graph.It
|
|||
and.AddSubIterator(subIt)
|
||||
and.AddSubIterator(notIt)
|
||||
it = and
|
||||
case "in_predicates":
|
||||
it = buildInOutPredicateIterator(obj, qs, subIt, true)
|
||||
case "out_predicates":
|
||||
it = buildInOutPredicateIterator(obj, qs, subIt, false)
|
||||
}
|
||||
if it == nil {
|
||||
panic("Iterator building does not catch the output iterator in some case.")
|
||||
|
|
|
|||
|
|
@ -250,6 +250,20 @@ var testQueries = []struct {
|
|||
`,
|
||||
expect: []string{"bob", "greg"},
|
||||
},
|
||||
{
|
||||
message: "list all in predicates",
|
||||
query: `
|
||||
g.V().InPredicates().All()
|
||||
`,
|
||||
expect: []string{"follows", "status"},
|
||||
},
|
||||
{
|
||||
message: "list all out predicates",
|
||||
query: `
|
||||
g.V().OutPredicates().All()
|
||||
`,
|
||||
expect: []string{"follows", "status"},
|
||||
},
|
||||
}
|
||||
|
||||
func runQueryGetTag(g []quad.Quad, query string, tag string) []string {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ func (wk *worker) embedTraversals(env *otto.Otto, obj *otto.Object) {
|
|||
obj.Set("SaveR", wk.gremlinFunc("saver", obj, env))
|
||||
obj.Set("Except", wk.gremlinFunc("except", obj, env))
|
||||
obj.Set("Difference", wk.gremlinFunc("except", obj, env))
|
||||
obj.Set("InPredicates", wk.gremlinFunc("in_predicates", obj, env))
|
||||
obj.Set("OutPredicates", wk.gremlinFunc("out_predicates", 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