Skip to content

Commit e39096d

Browse files
authored
refactor: general refactors around removing unused functions and types (#5094)
* refactor: remove spec json marshal and unmarshal functions The spec marshaling and unmarshaling functions are unused and don't work. Removing the code related to this. * refactor: remove all calls to RegisterOpSpec This removes all calls to `RegisterOpSpec` with the intent to deprecate and remove the function. This function doesn't do anything in the current version of Flux. A long time ago, it was possible to serialize and deserialize the flux spec which was generated from the interpreter. We removed this ability from everything except for the interpreter because it was unreliable and led to bugs. Since this code was only useful for the serialization and deserialization, and this is long unsupported and doesn't work, I'm finally removing the setup function that enabled this capability since it doesn't work and has led mostly to confusion about what's necessary when creating a source/transformation. * refactor: remove unused spec format functions * refactor: remove the unused priority type
1 parent af382a7 commit e39096d

File tree

140 files changed

+6
-1379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+6
-1379
lines changed

format.go

Lines changed: 0 additions & 55 deletions
This file was deleted.

lang/compiler.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"log"
87
"time"
98

109
"github.com/influxdata/flux"
@@ -50,8 +49,6 @@ func AddCompilerMappings(mappings flux.CompilerMappings) error {
5049
type CompileOption func(*compileOptions)
5150

5251
type compileOptions struct {
53-
verbose bool
54-
5552
extern flux.ASTHandle
5653

5754
planOptions struct {
@@ -92,12 +89,6 @@ func applyOptions(opts ...CompileOption) *compileOptions {
9289
// NOTE: compileOptions can be used only when invoking Compile* functions.
9390
// They can't be used when unmarshaling a Compiler and invoking its Compile method.
9491

95-
func Verbose(v bool) CompileOption {
96-
return func(o *compileOptions) {
97-
o.verbose = v
98-
}
99-
}
100-
10192
// Compile evaluates a Flux script producing a flux.Program.
10293
// now parameter must be non-zero, that is the default now time should be set before compiling.
10394
func Compile(q string, runtime flux.Runtime, now time.Time, opts ...CompileOption) (*AstProgram, error) {
@@ -129,9 +120,6 @@ func CompileTableObject(ctx context.Context, to *flux.TableObject, now time.Time
129120
if err != nil {
130121
return nil, err
131122
}
132-
if o.verbose {
133-
log.Println("Query Spec: ", flux.Formatted(s, flux.FmtJSON))
134-
}
135123
ps, err := buildPlan(ctx, s, o)
136124
if err != nil {
137125
return nil, err
@@ -499,9 +487,6 @@ func (p *AstProgram) Start(ctx context.Context, alloc memory.Allocator) (flux.Qu
499487

500488
// Planning.
501489
s, cctx := opentracing.StartSpanFromContext(ctx, "plan")
502-
if p.opts.verbose {
503-
log.Println("Query Spec: ", flux.Formatted(sp, flux.FmtJSON))
504-
}
505490
if err := p.updateOpts(scope); err != nil {
506491
return nil, errors.Wrap(err, codes.Inherit, "error in reading options while starting program")
507492
}

operation.go

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package flux
22

33
import (
4-
"encoding/json"
5-
6-
"github.com/influxdata/flux/codes"
7-
"github.com/influxdata/flux/internal/errors"
84
"github.com/influxdata/flux/interpreter"
95
)
106

@@ -15,58 +11,6 @@ type Operation struct {
1511
Source OperationSource `json:"source"`
1612
}
1713

18-
func (o *Operation) UnmarshalJSON(data []byte) error {
19-
type Alias Operation
20-
raw := struct {
21-
*Alias
22-
Kind OperationKind `json:"kind"`
23-
Spec json.RawMessage `json:"spec"`
24-
}{}
25-
err := json.Unmarshal(data, &raw)
26-
if err != nil {
27-
return err
28-
}
29-
if raw.Alias != nil {
30-
*o = *(*Operation)(raw.Alias)
31-
}
32-
spec, err := unmarshalOpSpec(raw.Kind, raw.Spec)
33-
if err != nil {
34-
return errors.Wrapf(err, codes.Inherit, "failed to unmarshal operation %q", o.ID)
35-
}
36-
o.Spec = spec
37-
return nil
38-
}
39-
40-
func unmarshalOpSpec(k OperationKind, data []byte) (OperationSpec, error) {
41-
createOpSpec, ok := kindToOp[k]
42-
if !ok {
43-
return nil, errors.Newf(codes.Invalid, "unknown operation spec kind %v", k)
44-
}
45-
spec := createOpSpec()
46-
47-
if len(data) > 0 {
48-
err := json.Unmarshal(data, spec)
49-
if err != nil {
50-
return nil, err
51-
}
52-
}
53-
return spec, nil
54-
}
55-
56-
func (o Operation) MarshalJSON() ([]byte, error) {
57-
type Alias Operation
58-
raw := struct {
59-
Kind OperationKind `json:"kind"`
60-
Alias
61-
}{
62-
Kind: o.Spec.Kind(),
63-
Alias: (Alias)(o),
64-
}
65-
return json.Marshal(raw)
66-
}
67-
68-
type NewOperationSpec func() OperationSpec
69-
7014
// OperationSpec specifies an operation as part of a query.
7115
type OperationSpec interface {
7216
// Kind returns the kind of the operation.
@@ -84,24 +28,3 @@ type OperationID string
8428

8529
// OperationKind denotes the kind of operations.
8630
type OperationKind string
87-
88-
var kindToOp = make(map[OperationKind]NewOperationSpec)
89-
90-
// RegisterOpSpec registers an operation spec with a given kind.
91-
// k is a label that uniquely identifies this operation. If the kind has already been registered the call panics.
92-
// c is a function reference that creates a new, default-initialized opSpec for the given kind.
93-
// TODO:(nathanielc) make this part of RegisterMethod/RegisterFunction
94-
func RegisterOpSpec(k OperationKind, c NewOperationSpec) {
95-
if kindToOp[k] != nil {
96-
panic(errors.Newf(codes.Internal, "duplicate registration for operation kind %v", k))
97-
}
98-
kindToOp[k] = c
99-
}
100-
101-
func NumberOfOperations() int {
102-
return len(kindToOp)
103-
}
104-
105-
func OperationSpecNewFn(k OperationKind) NewOperationSpec {
106-
return kindToOp[k]
107-
}

querytest/operations.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

resource_management.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
package flux
22

3-
import (
4-
"math"
5-
"strconv"
6-
7-
"github.com/influxdata/flux/codes"
8-
"github.com/influxdata/flux/internal/errors"
9-
)
10-
113
// ResourceManagement defines how the query should consume avaliable resources.
124
type ResourceManagement struct {
13-
// Priority or the query.
14-
// Queries with a lower value will move to the front of the priority queue.
15-
// A zero value indicates the highest priority.
16-
Priority Priority `json:"priority"`
175
// ConcurrencyQuota is the number of concurrency workers allowed to process this query.
186
// A zero value indicates the planner can pick the optimal concurrency.
197
ConcurrencyQuota int `json:"concurrency_quota"`
@@ -22,42 +10,3 @@ type ResourceManagement struct {
2210
// A zero value indicates unlimited.
2311
MemoryBytesQuota int64 `json:"memory_bytes_quota"`
2412
}
25-
26-
// Priority is an integer that represents the query priority.
27-
// Any positive 32bit integer value may be used.
28-
// Special constants are provided to represent the extreme high and low priorities.
29-
type Priority int32
30-
31-
const (
32-
// High is the highest possible priority = 0
33-
High Priority = 0
34-
// Low is the lowest possible priority = MaxInt32
35-
Low Priority = math.MaxInt32
36-
)
37-
38-
func (p Priority) MarshalText() ([]byte, error) {
39-
switch p {
40-
case Low:
41-
return []byte("low"), nil
42-
case High:
43-
return []byte("high"), nil
44-
default:
45-
return []byte(strconv.FormatInt(int64(p), 10)), nil
46-
}
47-
}
48-
49-
func (p *Priority) UnmarshalText(txt []byte) error {
50-
switch s := string(txt); s {
51-
case "low":
52-
*p = Low
53-
case "high":
54-
*p = High
55-
default:
56-
i, err := strconv.ParseInt(s, 10, 32)
57-
if err != nil {
58-
return errors.Wrap(err, codes.Invalid, "invalid priority, must be an integer or 'low','high'")
59-
}
60-
*p = Priority(i)
61-
}
62-
return nil
63-
}

stdlib/contrib/tomhollingworth/events/duration.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ type DurationOpSpec struct {
2828
func init() {
2929
durationSignature := runtime.MustLookupBuiltinType(pkgPath, DurationKind)
3030
runtime.RegisterPackageValue(pkgPath, DurationKind, flux.MustValue(flux.FunctionValue(DurationKind, createDurationOpSpec, durationSignature)))
31-
flux.RegisterOpSpec(DurationKind, newDurationOp)
3231
plan.RegisterProcedureSpec(DurationKind, newDurationProcedure, DurationKind)
3332
execute.RegisterTransformation(DurationKind, createDurationTransformation)
3433
}
@@ -85,10 +84,6 @@ func createDurationOpSpec(args flux.Arguments, a *flux.Administration) (flux.Ope
8584
return spec, nil
8685
}
8786

88-
func newDurationOp() flux.OperationSpec {
89-
return new(DurationOpSpec)
90-
}
91-
9287
func (s *DurationOpSpec) Kind() flux.OperationKind {
9388
return DurationKind
9489
}

stdlib/contrib/tomhollingworth/events/duration_test.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,6 @@ func TestDuration_NewQuery(t *testing.T) {
167167
}
168168
}
169169

170-
func TestDurationOperation_Marshaling(t *testing.T) {
171-
data := []byte(`{"id":"duration","kind":"duration","spec":{"timeColumn": "_time"}}`)
172-
op := &flux.Operation{
173-
ID: "duration",
174-
Spec: &events.DurationOpSpec{
175-
TimeColumn: "_time",
176-
},
177-
}
178-
querytest.OperationMarshalingTestHelper(t, data, op)
179-
}
180-
181170
func TestDuration_PassThrough(t *testing.T) {
182171
executetest.TransformationPassThroughTestHelper(t, func(d execute.Dataset, c execute.TableBuilderCache) execute.Transformation {
183172
s := events.NewDurationTransformation(

stdlib/csv/from.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const (
3333
func init() {
3434
fromCSVSignature := runtime.MustLookupBuiltinType("csv", "from")
3535
runtime.RegisterPackageValue("csv", "from", flux.MustValue(flux.FunctionValue(FromCSVKind, createFromCSVOpSpec, fromCSVSignature)))
36-
flux.RegisterOpSpec(FromCSVKind, newFromCSVOp)
3736
plan.RegisterProcedureSpec(FromCSVKind, newFromCSVProcedure, FromCSVKind)
3837
execute.RegisterSource(FromCSVKind, createFromCSVSource)
3938
}
@@ -73,10 +72,6 @@ func createFromCSVOpSpec(args flux.Arguments, a *flux.Administration) (flux.Oper
7372
return spec, nil
7473
}
7574

76-
func newFromCSVOp() flux.OperationSpec {
77-
return new(FromCSVOpSpec)
78-
}
79-
8075
func (s *FromCSVOpSpec) Kind() flux.OperationKind {
8176
return FromCSVKind
8277
}

stdlib/csv/from_test.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,6 @@ func TestFromCSV_NewQuery(t *testing.T) {
255255
}
256256
}
257257

258-
func TestFromCSVOperation_Marshaling(t *testing.T) {
259-
data := []byte(`{"id":"fromCSV","kind":"fromCSV","spec":{"csv":"1,2","mode":"annotations"}}`)
260-
op := &flux.Operation{
261-
ID: "fromCSV",
262-
Spec: &csv.FromCSVOpSpec{
263-
CSV: "1,2",
264-
Mode: "annotations",
265-
},
266-
}
267-
querytest.OperationMarshalingTestHelper(t, data, op)
268-
}
269-
270258
func TestFromCSV_Run(t *testing.T) {
271259
spec := &csv.FromCSVProcedureSpec{
272260
CSV: `#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,string,double

stdlib/doc.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ If a builtin OperationSpec is not found, then it will check for functions define
2626
The following registrations are typically executed in the function's init() for the query phase to execute properly:
2727
2828
flux.RegisterPackageValue(pkgpath, name string, value values.Value)
29-
flux.RegisterOpSpec(k flux.OperationKind, c flux.NewOperationSpec)
3029
3130
Note that to register a function value with a package, the value passed into flux.RegisterPackageValue is computed using the
3231
followingfunction:

0 commit comments

Comments
 (0)