-
Notifications
You must be signed in to change notification settings - Fork 154
/
builder.go
54 lines (46 loc) · 1.25 KB
/
builder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package plan
import (
"context"
"github.com/influxdata/flux/internal/operation"
)
// PlannerBuilder provides clients with an easy way to create planners.
type PlannerBuilder struct {
lopts []LogicalOption
popts []PhysicalOption
}
// AddLogicalOptions lets callers specify attributes of the logical planner
// that will be part of the created planner.
func (pb *PlannerBuilder) AddLogicalOptions(lopt ...LogicalOption) {
pb.lopts = append(pb.lopts, lopt...)
}
// AddPhysicalOptions lets callers specify attributes of the physical planner
// that will be part of the created planner.
func (pb *PlannerBuilder) AddPhysicalOptions(popt ...PhysicalOption) {
pb.popts = append(pb.popts, popt...)
}
// Build builds a planner with specified attributes.
func (pb PlannerBuilder) Build() Planner {
return &planner{
lp: NewLogicalPlanner(pb.lopts...),
pp: NewPhysicalPlanner(pb.popts...),
}
}
type planner struct {
lp LogicalPlanner
pp PhysicalPlanner
}
func (p *planner) Plan(ctx context.Context, fspec *operation.Spec) (*Spec, error) {
ip, err := p.lp.CreateInitialPlan(fspec)
if err != nil {
return nil, err
}
lp, err := p.lp.Plan(ctx, ip)
if err != nil {
return nil, err
}
pp, err := p.pp.Plan(ctx, lp)
if err != nil {
return nil, err
}
return pp, nil
}