Esempio n. 1
0
func (s *Session) Execute(input string, out chan interface{}, limit int) {
	defer close(out)
	it := BuildIteratorTreeForQuery(s.qs, input)
	err := graph.Iterate(context.TODO(), it).Paths(true).Limit(limit).TagEach(func(tags map[string]graph.Value) {
		out <- &tags
	})
	if err != nil {
		clog.Errorf("sexp: %v", err)
	}
}
Esempio n. 2
0
func (wk *worker) runIteratorWithCallback(it graph.Iterator, callback otto.Value, this otto.FunctionCall, limit int) {
	ctx, cancel := wk.newContext()
	defer cancel()

	err := graph.Iterate(ctx, it).Paths(true).Limit(limit).TagEach(func(tags map[string]graph.Value) {
		val, _ := this.Otto.ToValue(wk.tagsToValueMap(tags))
		val, _ = callback.Call(this.This, val)
	})
	if err != nil {
		clog.Errorf("gremlin: %v", err)
	}
}
Esempio n. 3
0
func (wk *worker) runIteratorToArrayNoTags(it graph.Iterator, limit int) []interface{} {
	ctx, cancel := wk.newContext()
	defer cancel()

	output := make([]interface{}, 0)
	err := graph.Iterate(ctx, it).Paths(false).Limit(limit).EachValue(wk.qs, func(v quad.Value) {
		output = append(output, quadValueToNative(v))
	})
	if err != nil {
		clog.Errorf("gremlin: %v", err)
	}
	return output
}
Esempio n. 4
0
func (wk *worker) runIteratorToArray(it graph.Iterator, limit int) []map[string]interface{} {
	ctx, cancel := wk.newContext()
	defer cancel()

	output := make([]map[string]interface{}, 0)
	err := graph.Iterate(ctx, it).Limit(limit).TagEach(func(tags map[string]graph.Value) {
		output = append(output, wk.tagsToValueMap(tags))
	})
	if err != nil {
		clog.Errorf("gremlin: %v", err)
	}
	return output
}
Esempio n. 5
0
func (wk *worker) runIterator(it graph.Iterator) {
	if wk.wantShape() {
		iterator.OutputQueryShapeForIterator(it, wk.qs, wk.shape)
		return
	}

	ctx, cancel := wk.newContext()
	defer cancel()

	err := graph.Iterate(ctx, it).Paths(true).TagEach(func(tags map[string]graph.Value) {
		if !wk.send(ctx, &Result{actualResults: tags}) {
			cancel()
		}
	})
	if err != nil {
		clog.Errorf("gremlin: %v", err)
	}
}
Esempio n. 6
0
func (s *Session) Execute(input string, c chan interface{}, limit int) {
	defer close(c)
	var mqlQuery interface{}
	err := json.Unmarshal([]byte(input), &mqlQuery)
	if err != nil {
		return
	}
	s.currentQuery = NewQuery(s)
	s.currentQuery.BuildIteratorTree(mqlQuery)
	if s.currentQuery.isError() {
		return
	}

	it := s.currentQuery.it
	err = graph.Iterate(context.TODO(), it).Limit(limit).TagEach(func(tags map[string]graph.Value) {
		c <- tags
	})
	if err != nil {
		clog.Errorf("mql: %v", err)
	}
}
Esempio n. 7
0
// Iterate is an shortcut for graph.Iterate.
func (p *Path) Iterate(ctx context.Context) *graph.IterateChain {
	return graph.Iterate(ctx, p.BuildIterator()).On(p.qs)
}