forked from influxdata/flux
/
output.go
74 lines (59 loc) · 2.11 KB
/
output.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
62
63
64
65
66
67
68
69
70
71
72
73
74
package executetest
import (
"errors"
"github.com/wolffcm/flux"
"github.com/wolffcm/flux/execute"
"github.com/wolffcm/flux/plan"
)
// ToTestKind represents an side-effect producing kind for testing
const ToTestKind = "to-test"
// ToProcedureSpec defines an output operation. That is, an
// operation that does not transform its input data but performs a
// side effect while passing its input data through to the next op.
type ToProcedureSpec struct{}
func NewToProcedure(flux.OperationSpec, plan.Administration) (plan.ProcedureSpec, error) {
return &ToProcedureSpec{}, nil
}
func (s *ToProcedureSpec) Kind() plan.ProcedureKind {
return ToTestKind
}
func (s *ToProcedureSpec) Copy() plan.ProcedureSpec {
return s
}
func (s *ToProcedureSpec) Cost(inStats []plan.Statistics) (plan.Cost, plan.Statistics) {
return plan.Cost{}, plan.Statistics{}
}
// ToTransformation simulates an output or an identity transformation
type ToTransformation struct {
d execute.Dataset
c execute.TableBuilderCache
}
func CreateToTransformation(id execute.DatasetID, mode execute.AccumulationMode, spec plan.ProcedureSpec, a execute.Administration) (execute.Transformation, execute.Dataset, error) {
c := execute.NewTableBuilderCache(a.Allocator())
d := execute.NewDataset(id, mode, c)
return &ToTransformation{d: d, c: c}, d, nil
}
func (t *ToTransformation) Process(id execute.DatasetID, tbl flux.Table) error {
if builder, new := t.c.TableBuilder(tbl.Key()); new {
if err := execute.AddTableCols(tbl, builder); err != nil {
return err
}
if err := execute.AppendTable(tbl, builder); err != nil {
return err
}
return nil
}
return errors.New("duplicate group key")
}
func (t *ToTransformation) RetractTable(id execute.DatasetID, key flux.GroupKey) error {
return t.d.RetractTable(key)
}
func (t *ToTransformation) UpdateWatermark(id execute.DatasetID, pt execute.Time) error {
return t.d.UpdateWatermark(pt)
}
func (t *ToTransformation) UpdateProcessingTime(id execute.DatasetID, pt execute.Time) error {
return t.d.UpdateProcessingTime(pt)
}
func (t *ToTransformation) Finish(id execute.DatasetID, err error) {
t.d.Finish(err)
}