@@ -14,7 +14,6 @@ import (
14
14
"github.com/influxdata/flux/internal/spec"
15
15
"github.com/influxdata/flux/memory"
16
16
"github.com/influxdata/flux/plan"
17
- "github.com/influxdata/flux/runtime"
18
17
"github.com/influxdata/flux/semantic"
19
18
"github.com/influxdata/flux/values"
20
19
"github.com/opentracing/opentracing-go"
@@ -97,20 +96,21 @@ func Verbose(v bool) CompileOption {
97
96
98
97
// Compile evaluates a Flux script producing a flux.Program.
99
98
// now parameter must be non-zero, that is the default now time should be set before compiling.
100
- func Compile (q string , now time.Time , opts ... CompileOption ) (* AstProgram , error ) {
99
+ func Compile (q string , runtime flux. Runtime , now time.Time , opts ... CompileOption ) (* AstProgram , error ) {
101
100
astPkg , err := runtime .Parse (q )
102
101
if err != nil {
103
102
return nil , err
104
103
}
105
- return CompileAST (astPkg , now , opts ... ), nil
104
+ return CompileAST (astPkg , runtime , now , opts ... ), nil
106
105
}
107
106
108
107
// CompileAST evaluates a Flux AST and produces a flux.Program.
109
108
// now parameter must be non-zero, that is the default now time should be set before compiling.
110
- func CompileAST (astPkg * ast.Package , now time.Time , opts ... CompileOption ) * AstProgram {
109
+ func CompileAST (astPkg * ast.Package , runtime flux. Runtime , now time.Time , opts ... CompileOption ) * AstProgram {
111
110
return & AstProgram {
112
111
Program : & Program {
113
- opts : applyOptions (opts ... ),
112
+ Runtime : runtime ,
113
+ opts : applyOptions (opts ... ),
114
114
},
115
115
Ast : astPkg ,
116
116
Now : now ,
@@ -165,9 +165,9 @@ type FluxCompiler struct {
165
165
Query string `json:"query"`
166
166
}
167
167
168
- func (c FluxCompiler ) Compile (ctx context.Context ) (flux.Program , error ) {
168
+ func (c FluxCompiler ) Compile (ctx context.Context , runtime flux. Runtime ) (flux.Program , error ) {
169
169
// Ignore context, it will be provided upon Program Start.
170
- return Compile (c .Query , c .Now , WithExtern (c .Extern ))
170
+ return Compile (c .Query , runtime , c .Now , WithExtern (c .Extern ))
171
171
}
172
172
173
173
func (c FluxCompiler ) CompilerType () flux.CompilerType {
@@ -180,13 +180,13 @@ type ASTCompiler struct {
180
180
Now time.Time
181
181
}
182
182
183
- func (c ASTCompiler ) Compile (ctx context.Context ) (flux.Program , error ) {
183
+ func (c ASTCompiler ) Compile (ctx context.Context , runtime flux. Runtime ) (flux.Program , error ) {
184
184
now := c .Now
185
185
if now .IsZero () {
186
186
now = time .Now ()
187
187
}
188
188
// Ignore context, it will be provided upon Program Start.
189
- return CompileAST (c .AST , now ), nil
189
+ return CompileAST (c .AST , runtime , now ), nil
190
190
}
191
191
192
192
func (ASTCompiler ) CompilerType () flux.CompilerType {
@@ -224,6 +224,7 @@ type LoggingProgram interface {
224
224
type Program struct {
225
225
Logger * zap.Logger
226
226
PlanSpec * plan.Spec
227
+ Runtime flux.Runtime
227
228
228
229
opts * compileOptions
229
230
}
@@ -296,7 +297,7 @@ type AstProgram struct {
296
297
Now time.Time
297
298
}
298
299
299
- func (p * AstProgram ) getSpec (ctx context.Context , alloc * memory.Allocator ) (* flux.Spec , values.Scope , error ) {
300
+ func (p * AstProgram ) getSpec (ctx context.Context , runtime flux. Runtime , alloc * memory.Allocator ) (* flux.Spec , values.Scope , error ) {
300
301
if p .opts == nil {
301
302
p .opts = defaultOptions ()
302
303
}
@@ -314,7 +315,7 @@ func (p *AstProgram) getSpec(ctx context.Context, alloc *memory.Allocator) (*flu
314
315
}
315
316
ctx = deps .Inject (ctx )
316
317
s , cctx := opentracing .StartSpanFromContext (ctx , "eval" )
317
- sideEffects , scope , err := runtime .EvalAST (cctx , p .Ast , runtime .SetNowOption (p .Now ))
318
+ sideEffects , scope , err := runtime .Eval (cctx , p .Ast , flux .SetNowOption (p .Now ))
318
319
if err != nil {
319
320
return nil , nil , err
320
321
}
@@ -339,7 +340,7 @@ func (p *AstProgram) getSpec(ctx context.Context, alloc *memory.Allocator) (*flu
339
340
}
340
341
341
342
func (p * AstProgram ) Start (ctx context.Context , alloc * memory.Allocator ) (flux.Query , error ) {
342
- sp , scope , err := p .getSpec (ctx , alloc )
343
+ sp , scope , err := p .getSpec (ctx , p . Runtime , alloc )
343
344
if err != nil {
344
345
return nil , err
345
346
}
@@ -451,15 +452,3 @@ func getRules(plannerPkg values.Object, optionName string) ([]string, error) {
451
452
})
452
453
return rs , nil
453
454
}
454
-
455
- // WalkIR applies the function `f` to each operation in the compiled spec.
456
- // WARNING: this function evaluates the AST using an unlimited allocator.
457
- // In case of dynamic queries this could lead to unexpected memory usage.
458
- func WalkIR (ctx context.Context , astPkg * ast.Package , f func (o * flux.Operation ) error ) error {
459
- p := CompileAST (astPkg , time .Now ())
460
- if sp , _ , err := p .getSpec (ctx , new (memory.Allocator )); err != nil {
461
- return err
462
- } else {
463
- return sp .Walk (f )
464
- }
465
- }
0 commit comments