// Main Entry point to take a Plan, and convert into Execution DAG func (m *JobExecutor) WalkPlan(p plan.Task) (Task, error) { switch p := p.(type) { case *plan.PreparedStatement: return m.Executor.WalkPreparedStatement(p) case *plan.Select: if len(p.From) > 0 { //u.Debugf("walk select p:%p m.Executor: %p ChildDag?%v %v", p, m.Executor, p.ChildDag, p.Stmt.String()) } if p.Ctx != nil && p.IsSchemaQuery() { //u.Debugf("is schema query. ctx nil? %v", p.Ctx == nil) if p.Ctx.Schema != nil && p.Ctx.Schema.InfoSchema != nil { p.Ctx.Schema = p.Ctx.Schema.InfoSchema } p.Stmt.SetSystemQry() } return m.Executor.WalkSelect(p) case *plan.Upsert: return m.Executor.WalkUpsert(p) case *plan.Insert: return m.Executor.WalkInsert(p) case *plan.Update: return m.Executor.WalkUpdate(p) case *plan.Delete: return m.Executor.WalkDelete(p) case *plan.Command: return m.Executor.WalkCommand(p) } panic(fmt.Sprintf("Not implemented for %T", p)) }
func (m *JobExecutor) WalkPlanAll(p plan.Task) (Task, error) { root, err := m.WalkPlanTask(p) if err != nil { u.Errorf("all damn %v err=%v", p, err) return nil, err } if len(p.Children()) > 0 { dagRoot := m.NewTask(p) //u.Debugf("sequential?%v parallel?%v", p.IsSequential(), p.IsParallel()) err = dagRoot.Add(root) if err != nil { u.Errorf("Could not add root: %v", err) return nil, err } return dagRoot, m.WalkChildren(p, dagRoot) } //u.Debugf("got root? %T for %T", root, p) //u.Debugf("len=%d for children:%v", len(p.Children()), p.Children()) return root, m.WalkChildren(p, root) }
// WalkChildren walk dag of plan taasks creating execution tasks func (m *JobExecutor) WalkChildren(p plan.Task, root Task) error { for _, t := range p.Children() { //u.Debugf("parent: %T walk child %p %T %#v", p, t, t, p.Children()) et, err := m.WalkPlanTask(t) if err != nil { u.Errorf("could not create task %#v err=%v", t, err) } if len(t.Children()) == 0 { err = root.Add(et) if err != nil { return err } } else { childRoot := m.Executor.NewTask(t) err = root.Add(childRoot) if err != nil { return err } err = childRoot.Add(et) if err != nil { return err } //u.Warnf("has children but not handled %#v", t) for _, c := range t.Children() { //u.Warnf("\tchild task %#v", c) ct, err := m.WalkPlanTask(c) if err != nil { u.Errorf("could not create child task %#v err=%v", c, err) return err } if err = childRoot.Add(ct); err != nil { u.Errorf("Could not add task %v", err) return err } } } } return nil }
func (m *JobExecutor) NewTask(p plan.Task) Task { if p.IsParallel() { return NewTaskParallel(m.Ctx) } return NewTaskSequential(m.Ctx) }