func SourceFromPB(pb *PlanPb, ctx *Context) (*Source, error) { m := Source{ SourcePb: pb.Source, ctx: ctx, } if len(pb.Source.Custom) > 0 { m.Custom = make(u.JsonHelper) if err := json.Unmarshal(pb.Source.Custom, &m.Custom); err != nil { u.Errorf("Could not unmarshall custom data %v", err) } //u.Debugf("custom %v", m.Custom) } if pb.Source.Projection != nil { m.Proj = rel.ProjectionFromPb(pb.Source.Projection) } if pb.Source.SqlSource != nil { m.Stmt = rel.SqlSourceFromPb(pb.Source.SqlSource) } m.PlanBase = NewPlanBase(pb.Parallel) if len(pb.Children) > 0 { m.tasks = make([]Task, len(pb.Children)) for i, pbt := range pb.Children { childPlan, err := SelectTaskFromTaskPb(pbt, ctx, m.Stmt.Source) if err != nil { u.Errorf("%T not implemented? %v", pbt, err) return nil, err } m.tasks[i] = childPlan } } err := m.load() if err != nil { u.Errorf("could not load? %v", err) return nil, err } if m.Conn == nil { err = m.LoadConn() if err != nil { u.Errorf("conn error? %v", err) return nil, err } if m.Conn == nil { if m.Stmt != nil { if m.Stmt.IsLiteral() { // this is fine } else { u.Warnf("no data source and not literal query? %s", m.Stmt.String()) return nil, ErrNoDataSource } } else { //u.Warnf("hm no conn, no stmt?....") //return nil, ErrNoDataSource } } } return &m, nil }
func ProjectionFromPB(pb *PlanPb, sel *rel.SqlSelect) *Projection { m := Projection{ Proj: rel.ProjectionFromPb(pb.Projection), } m.Final = pb.Projection.Final m.PlanBase = NewPlanBase(pb.Parallel) m.Stmt = sel return &m }