Exemplo n.º 1
0
func (wk *worker) runIterator(it graph.Iterator) {
	if wk.wantShape() {
		iterator.OutputQueryShapeForIterator(it, wk.qs, wk.shape)
		return
	}
	it, _ = it.Optimize()
	if glog.V(2) {
		b, err := json.MarshalIndent(it.Describe(), "", "  ")
		if err != nil {
			glog.Infof("failed to format description: %v", err)
		} else {
			glog.Infof("%s", b)
		}
	}
	for {
		select {
		case <-wk.kill:
			return
		default:
		}
		if !graph.Next(it) {
			break
		}
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		if !wk.send(&Result{actualResults: tags}) {
			break
		}
		for it.NextPath() {
			select {
			case <-wk.kill:
				return
			default:
			}
			tags := make(map[string]graph.Value)
			it.TagResults(tags)
			if !wk.send(&Result{actualResults: tags}) {
				break
			}
		}
	}
	if glog.V(2) {
		bytes, _ := json.MarshalIndent(graph.DumpStats(it), "", "  ")
		glog.V(2).Infoln(string(bytes))
	}
	it.Close()
}
Exemplo n.º 2
0
func (s *Session) ShapeOf(query string) (interface{}, error) {
	var mqlQuery interface{}
	err := json.Unmarshal([]byte(query), &mqlQuery)
	if err != nil {
		return nil, err
	}
	s.currentQuery = NewQuery(s)
	s.currentQuery.BuildIteratorTree(mqlQuery)
	output := make(map[string]interface{})
	iterator.OutputQueryShapeForIterator(s.currentQuery.it, s.qs, output)
	nodes := make([]iterator.Node, 0)
	for _, n := range output["nodes"].([]iterator.Node) {
		n.Tags = nil
		nodes = append(nodes, n)
	}
	output["nodes"] = nodes
	return output, nil
}
Exemplo n.º 3
0
func (s *Session) GetQuery(input string, out chan map[string]interface{}) {
	defer close(out)
	var mqlQuery interface{}
	err := json.Unmarshal([]byte(input), &mqlQuery)
	if err != nil {
		return
	}
	s.currentQuery = NewQuery(s)
	s.currentQuery.BuildIteratorTree(mqlQuery)
	output := make(map[string]interface{})
	iterator.OutputQueryShapeForIterator(s.currentQuery.it, s.qs, output)
	nodes := make([]iterator.Node, 0)
	for _, n := range output["nodes"].([]iterator.Node) {
		n.Tags = nil
		nodes = append(nodes, n)
	}
	output["nodes"] = nodes
	out <- output
}
Exemplo n.º 4
0
func (m *Session) GetQuery(input string, output_struct chan map[string]interface{}) {
	defer close(output_struct)
	var mqlQuery interface{}
	err := json.Unmarshal([]byte(input), &mqlQuery)
	if err != nil {
		return
	}
	m.currentQuery = NewQuery(m)
	m.currentQuery.BuildIteratorTree(mqlQuery)
	output := make(map[string]interface{})
	iterator.OutputQueryShapeForIterator(m.currentQuery.it, m.ts, &output)
	nodes := output["nodes"].([]iterator.Node)
	new_nodes := make([]iterator.Node, 0)
	for _, n := range nodes {
		n.Tags = nil
		new_nodes = append(new_nodes, n)
	}
	output["nodes"] = new_nodes
	output_struct <- output
}
Exemplo n.º 5
0
func (wk *worker) runIterator(it graph.Iterator) {
	if wk.wantShape() {
		iterator.OutputQueryShapeForIterator(it, wk.ts, wk.shape)
		return
	}
	it, _ = it.Optimize()
	glog.V(2).Infoln(it.DebugString(0))
	for {
		select {
		case <-wk.kill:
			return
		default:
		}
		if !graph.Next(it) {
			break
		}
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		if !wk.send(&Result{actualResults: tags}) {
			break
		}
		for it.NextPath() {
			select {
			case <-wk.kill:
				return
			default:
			}
			tags := make(map[string]graph.Value)
			it.TagResults(tags)
			if !wk.send(&Result{actualResults: tags}) {
				break
			}
		}
	}
	if glog.V(2) {
		bytes, _ := json.MarshalIndent(graph.DumpStats(it), "", "  ")
		glog.V(2).Infoln(string(bytes))
	}
	it.Close()
}
Exemplo n.º 6
0
func runIteratorOnSession(it graph.Iterator, ses *Session) {
	if ses.wantShape {
		iterator.OutputQueryShapeForIterator(it, ses.ts, ses.shape)
		return
	}
	it, _ = it.Optimize()
	glog.V(2).Infoln(it.DebugString(0))
	for {
		select {
		case <-ses.kill:
			return
		default:
		}
		if !graph.Next(it) {
			break
		}
		tags := make(map[string]graph.Value)
		it.TagResults(tags)
		if !ses.SendResult(&Result{actualResults: &tags}) {
			break
		}
		for it.NextPath() {
			select {
			case <-ses.kill:
				return
			default:
			}
			tags := make(map[string]graph.Value)
			it.TagResults(tags)
			if !ses.SendResult(&Result{actualResults: &tags}) {
				break
			}
		}
	}
	if glog.V(2) {
		bytes, _ := json.MarshalIndent(graph.DumpStats(it), "", "  ")
		glog.V(2).Infoln(string(bytes))
	}
	it.Close()
}
Exemplo n.º 7
0
func runIteratorOnSession(it graph.Iterator, ses *Session) {
	if ses.lookingForQueryShape {
		iterator.OutputQueryShapeForIterator(it, ses.ts, &(ses.queryShape))
		return
	}
	it, _ = it.Optimize()
	glog.V(2).Infoln(it.DebugString(0))
	for {
		// TODO(barakmich): Better halting.
		if ses.doHalt {
			return
		}
		_, ok := it.Next()
		if !ok {
			break
		}
		tags := make(map[string]graph.TSVal)
		it.TagResults(&tags)
		cont := ses.SendResult(&GremlinResult{metaresult: false, err: "", val: nil, actualResults: &tags})
		if !cont {
			break
		}
		for it.NextResult() == true {
			if ses.doHalt {
				return
			}
			tags := make(map[string]graph.TSVal)
			it.TagResults(&tags)
			cont := ses.SendResult(&GremlinResult{metaresult: false, err: "", val: nil, actualResults: &tags})
			if !cont {
				break
			}
		}
	}
	it.Close()
}