Exemplo n.º 1
0
// Next implements Executor Next interface.
// The data in the returned row is not used by caller.
func (e *JoinInnerExec) Next() (*Row, error) {
	if e.done {
		return nil, nil
	}
	rowKeysSlice := make([][]*RowKeyEntry, len(e.InnerPlans))
	for {
		exec := e.innerExecs[e.cursor]
		if exec == nil {
			innerPlan := e.InnerPlans[e.cursor]
			plan.Refine(innerPlan)
			exec = e.builder.build(innerPlan)
			if e.builder.err != nil {
				return nil, errors.Trace(e.builder.err)
			}
			e.innerExecs[e.cursor] = exec
		}
		row, err := exec.Next()
		if err != nil {
			return nil, errors.Trace(err)
		}
		if row == nil {
			exec.Close()
			e.innerExecs[e.cursor] = nil
			if e.cursor == 0 {
				e.done = true
				return nil, nil
			}
			e.cursor--
			continue
		}
		rowKeysSlice[e.cursor] = row.RowKeys
		if e.cursor < len(e.innerExecs)-1 {
			e.cursor++
			continue
		}
		var match = true
		if e.Condition != nil {
			match, err = evaluator.EvalBool(e.ctx, e.Condition)
			if err != nil {
				return nil, errors.Trace(err)
			}
		}
		if match {
			row.RowKeys = joinRowKeys(rowKeysSlice)
			return row, nil
		}
	}
}
Exemplo n.º 2
0
// Next implements Executor Next interface.
func (e *FilterExec) Next() (*Row, error) {
	for {
		srcRow, err := e.Src.Next()
		if err != nil {
			return nil, errors.Trace(err)
		}
		if srcRow == nil {
			return nil, nil
		}
		match, err := evaluator.EvalBool(e.ctx, e.Condition)
		if err != nil {
			return nil, errors.Trace(err)
		}
		if match {
			return srcRow, nil
		}
	}
}