MCPcopy Create free account
hub / github.com/araddon/qlbridge / SourceFromPB

Function SourceFromPB

plan/plan.go:564–622  ·  view source on GitHub ↗
(pb *PlanPb, ctx *Context)

Source from the content-addressed store, hash-verified

562}
563
564func SourceFromPB(pb *PlanPb, ctx *Context) (*Source, error) {
565 m := Source{
566 SourcePb: pb.Source,
567 ctx: ctx,
568 }
569 if len(pb.Source.Custom) > 0 {
570 m.Custom = make(u.JsonHelper)
571 if err := json.Unmarshal(pb.Source.Custom, &m.Custom); err != nil {
572 u.Errorf("Could not unmarshall custom data %v", err)
573 }
574 //u.Debugf("custom %v", m.Custom)
575 }
576 if pb.Source.Projection != nil {
577 m.Proj = rel.ProjectionFromPb(pb.Source.Projection)
578 }
579 if pb.Source.SqlSource != nil {
580 m.Stmt = rel.SqlSourceFromPb(pb.Source.SqlSource)
581 }
582 m.PlanBase = NewPlanBase(pb.Parallel)
583 if len(pb.Children) > 0 {
584 m.tasks = make([]Task, len(pb.Children))
585 for i, pbt := range pb.Children {
586 childPlan, err := SelectTaskFromTaskPb(pbt, ctx, m.Stmt.Source)
587 if err != nil {
588 u.Errorf("%T not implemented? %v", pbt, err)
589 return nil, err
590 }
591 m.tasks[i] = childPlan
592 }
593 }
594
595 err := m.load()
596 if err != nil {
597 u.Errorf("could not load? %v", err)
598 return nil, err
599 }
600 if m.Conn == nil {
601 err = m.LoadConn()
602 if err != nil {
603 u.Errorf("conn error? %v", err)
604 return nil, err
605 }
606 if m.Conn == nil {
607 if m.Stmt != nil {
608 if m.Stmt.IsLiteral() {
609 // this is fine
610 } else {
611 u.Warnf("no data source and not literal query? %s", m.Stmt.String())
612 return nil, ErrNoDataSource
613 }
614 } else {
615 //u.Warnf("hm no conn, no stmt?....")
616 //return nil, ErrNoDataSource
617 }
618 }
619 }
620
621 return &m, nil

Callers 1

SelectTaskFromTaskPbFunction · 0.85

Calls 10

loadMethod · 0.95
LoadConnMethod · 0.95
ProjectionFromPbFunction · 0.92
SqlSourceFromPbFunction · 0.92
NewPlanBaseFunction · 0.85
SelectTaskFromTaskPbFunction · 0.85
ErrorfMethod · 0.80
StringMethod · 0.65
UnmarshalMethod · 0.45
IsLiteralMethod · 0.45

Tested by

no test coverage detected