-
Notifications
You must be signed in to change notification settings - Fork 154
/
dual_impl_spec.go
61 lines (52 loc) · 1.6 KB
/
dual_impl_spec.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
55
56
57
58
59
60
61
package universe
import (
"fmt"
"github.com/influxdata/flux"
"github.com/influxdata/flux/execute"
"github.com/influxdata/flux/plan"
)
type DualImplProcedureSpec struct {
plan.ProcedureSpec
plan.DefaultCost
UseDeprecated bool
}
func (s *DualImplProcedureSpec) PlanDetails() string {
return fmt.Sprintf("DualImplProcedureSpec, UseDeprecated = %v", s.UseDeprecated)
}
func (s *DualImplProcedureSpec) Kind() plan.ProcedureKind {
return s.ProcedureSpec.Kind()
}
func (s *DualImplProcedureSpec) Copy() plan.ProcedureSpec {
ns := new(DualImplProcedureSpec)
*ns = *s
return ns
}
func UseDeprecatedImpl(spec plan.ProcedureSpec) {
if dualImplSpec, ok := spec.(*DualImplProcedureSpec); ok {
dualImplSpec.UseDeprecated = true
}
}
func newDualImplSpec(fn plan.CreateProcedureSpec) plan.CreateProcedureSpec {
return func(qs flux.OperationSpec, pa plan.Administration) (plan.ProcedureSpec, error) {
spec, err := fn(qs, pa)
if err != nil {
return nil, err
}
return &DualImplProcedureSpec{
ProcedureSpec: spec,
UseDeprecated: false,
}, nil
}
}
func createDualImplTf(fnNew execute.CreateTransformation, fnDeprecated execute.CreateTransformation) execute.CreateTransformation {
return func(id execute.DatasetID, mode execute.AccumulationMode, spec plan.ProcedureSpec, a execute.Administration) (execute.Transformation, execute.Dataset, error) {
dualImplSpec, ok := spec.(*DualImplProcedureSpec)
if !ok {
return fnNew(id, mode, spec, a)
}
if !dualImplSpec.UseDeprecated {
return fnNew(id, mode, dualImplSpec.ProcedureSpec, a)
}
return fnDeprecated(id, mode, dualImplSpec.ProcedureSpec, a)
}
}