diff --git a/go.mod b/go.mod index 008dc73c13..99421c3241 100644 --- a/go.mod +++ b/go.mod @@ -42,7 +42,7 @@ require ( github.com/hashicorp/raft v1.0.0 // indirect github.com/hashicorp/vault/api v1.0.2 github.com/influxdata/cron v0.0.0-20191203200038-ded12750aac6 - github.com/influxdata/flux v0.60.1-0.20200305155158-1add321ebf7a + github.com/influxdata/flux v0.60.1-0.20200309174638-0dbc38c3785a github.com/influxdata/httprouter v1.3.1-0.20191122104820-ee83e2772f69 github.com/influxdata/influxql v0.0.0-20180925231337-1cbfca8e56b6 github.com/influxdata/usage-client v0.0.0-20160829180054-6d3895376368 diff --git a/go.sum b/go.sum index 28528e0421..65f1897c09 100644 --- a/go.sum +++ b/go.sum @@ -240,8 +240,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/cron v0.0.0-20191203200038-ded12750aac6 h1:OtjKkeWDjUbyMi82C7XXy7Tvm2LXMwiBBXyFIGNPaGA= github.com/influxdata/cron v0.0.0-20191203200038-ded12750aac6/go.mod h1:XabtPPW2qsCg0tl+kjaPU+cFS+CjQXEXbT1VJvHT4og= -github.com/influxdata/flux v0.60.1-0.20200305155158-1add321ebf7a h1:Dczh6cTotsat9rt7GzD7EhGzpGFO5h0L3zAkQ1sJSds= -github.com/influxdata/flux v0.60.1-0.20200305155158-1add321ebf7a/go.mod h1:BRxpm1xTUAZ+s+Mq6t0NZyaYtlGrw/8YoHoifso9vS8= +github.com/influxdata/flux v0.60.1-0.20200309174638-0dbc38c3785a h1:VUxuayL83N9Fj3re2mOAgHWKCqRJFKRqqXK2mihLXMI= +github.com/influxdata/flux v0.60.1-0.20200309174638-0dbc38c3785a/go.mod h1:BRxpm1xTUAZ+s+Mq6t0NZyaYtlGrw/8YoHoifso9vS8= github.com/influxdata/goreleaser v0.97.0-influx h1:jT5OrcW7WfS0e2QxfwmTBjhLvpIC9CDLRhNgZJyhj8s= github.com/influxdata/goreleaser v0.97.0-influx/go.mod h1:MnjA0e0Uq6ISqjG1WxxMAl+3VS1QYjILSWVnMYDxasE= github.com/influxdata/httprouter v1.3.1-0.20191122104820-ee83e2772f69 h1:WQsmW0fXO4ZE/lFGIE84G6rIV5SJN3P3sjIXAP1a8eU= diff --git a/http/influxdb/source_proxy_query_service.go b/http/influxdb/source_proxy_query_service.go index dbc61fa4ef..b1bcc6b94b 100644 --- a/http/influxdb/source_proxy_query_service.go +++ b/http/influxdb/source_proxy_query_service.go @@ -11,7 +11,6 @@ import ( "github.com/influxdata/flux" "github.com/influxdata/flux/csv" "github.com/influxdata/flux/lang" - "github.com/influxdata/flux/repl" platform "github.com/influxdata/influxdb" platformhttp "github.com/influxdata/influxdb/http" "github.com/influxdata/influxdb/kit/check" @@ -43,7 +42,6 @@ func (s *SourceProxyQueryService) fluxQuery(ctx context.Context, w io.Writer, re span, ctx := tracing.StartSpanFromContext(ctx) defer span.Finish() request := struct { - Spec *flux.Spec `json:"spec"` Query string `json:"query"` Type string `json:"type"` Dialect flux.Dialect `json:"dialect"` @@ -53,9 +51,6 @@ func (s *SourceProxyQueryService) fluxQuery(ctx context.Context, w io.Writer, re case lang.FluxCompiler: request.Query = c.Query request.Type = lang.FluxCompilerType - case repl.Compiler: - request.Spec = c.Spec - request.Type = repl.CompilerType default: return flux.Statistics{}, tracing.LogError(span, fmt.Errorf("compiler type not supported: %s", c.CompilerType())) } diff --git a/http/query.go b/http/query.go index da5f766805..5f1de8ded9 100644 --- a/http/query.go +++ b/http/query.go @@ -18,7 +18,6 @@ import ( "github.com/influxdata/flux/ast" "github.com/influxdata/flux/csv" "github.com/influxdata/flux/lang" - "github.com/influxdata/flux/repl" "github.com/influxdata/influxdb" "github.com/influxdata/influxdb/jsonweb" "github.com/influxdata/influxdb/query" @@ -33,7 +32,6 @@ type QueryRequest struct { // Flux fields Extern *ast.File `json:"extern,omitempty"` - Spec *flux.Spec `json:"spec,omitempty"` AST *ast.Package `json:"ast,omitempty"` Dialect QueryDialect `json:"dialect"` @@ -89,19 +87,10 @@ func (r QueryRequest) WithDefaults() QueryRequest { // Validate checks the query request and returns an error if the request is invalid. func (r QueryRequest) Validate() error { - // TODO(jsternberg): Remove this, but we are going to not mention - // the spec in the error if it is being used. - if r.Query == "" && r.Spec == nil && r.AST == nil { + if r.Query == "" && r.AST == nil { return errors.New(`request body requires either query or AST`) } - if r.Spec != nil && r.Extern != nil { - return &influxdb.Error{ - Code: influxdb.EInvalid, - Msg: "request body cannot specify both a spec and external declarations", - } - } - if r.Type != "flux" && r.Type != "influxql" { return fmt.Errorf(`unknown query type: %s`, r.Type) } @@ -283,10 +272,6 @@ func (r QueryRequest) proxyRequest(now func() time.Time) (*query.ProxyRequest, e c.PrependFile(r.Extern) } compiler = c - } else if r.Spec != nil { - compiler = repl.Compiler{ - Spec: r.Spec, - } } delimiter, _ := utf8.DecodeRuneInString(r.Dialect.Delimiter) @@ -341,9 +326,6 @@ func QueryRequestFromProxyRequest(req *query.ProxyRequest) (*QueryRequest, error qr.Type = "flux" qr.Query = c.Query qr.Extern = c.Extern - case repl.Compiler: - qr.Type = "flux" - qr.Spec = c.Spec case lang.ASTCompiler: qr.Type = "flux" qr.AST = c.AST diff --git a/http/query_handler.go b/http/query_handler.go index 4d371c27f0..006ff0a375 100644 --- a/http/query_handler.go +++ b/http/query_handler.go @@ -15,7 +15,6 @@ import ( "github.com/NYTimes/gziphandler" "github.com/influxdata/flux" "github.com/influxdata/flux/ast" - "github.com/influxdata/flux/complete" "github.com/influxdata/flux/csv" "github.com/influxdata/flux/iocounter" "github.com/influxdata/httprouter" @@ -80,7 +79,7 @@ type FluxHandler struct { Now func() time.Time OrganizationService influxdb.OrganizationService ProxyQueryService query.ProxyQueryService - LanguageService influxdb.FluxLanguageService + FluxLanguageService influxdb.FluxLanguageService EventRecorder metric.EventRecorder } @@ -101,7 +100,7 @@ func NewFluxHandler(log *zap.Logger, b *FluxBackend) *FluxHandler { ProxyQueryService: b.ProxyQueryService, OrganizationService: b.OrganizationService, EventRecorder: b.QueryEventRecorder, - LanguageService: b.FluxLanguageService, + FluxLanguageService: b.FluxLanguageService, } // query reponses can optionally be gzip encoded @@ -224,7 +223,7 @@ func (h *FluxHandler) postFluxAST(w http.ResponseWriter, r *http.Request) { return } - pkg, err := query.Parse(h.LanguageService, request.Query) + pkg, err := query.Parse(h.FluxLanguageService, request.Query) if err != nil { h.HandleHTTPError(ctx, &influxdb.Error{ Code: influxdb.EInvalid, @@ -261,7 +260,7 @@ func (h *FluxHandler) postQueryAnalyze(w http.ResponseWriter, r *http.Request) { return } - a, err := req.Analyze(h.LanguageService) + a, err := req.Analyze(h.FluxLanguageService) if err != nil { h.HandleHTTPError(ctx, err, w) return @@ -292,7 +291,7 @@ func (h *FluxHandler) getFluxSuggestions(w http.ResponseWriter, r *http.Request) defer span.Finish() ctx := r.Context() - completer := complete.DefaultCompleter() + completer := h.FluxLanguageService.Completer() names := completer.FunctionNames() var functions []suggestionResponse for _, name := range names { @@ -331,7 +330,7 @@ func (h *FluxHandler) getFluxSuggestion(w http.ResponseWriter, r *http.Request) ctx := r.Context() name := httprouter.ParamsFromContext(ctx).ByName("name") - completer := complete.DefaultCompleter() + completer := h.FluxLanguageService.Completer() suggestion, err := completer.FunctionSuggestion(name) if err != nil { diff --git a/http/query_handler_test.go b/http/query_handler_test.go index 400fa0b312..6bd1e49500 100644 --- a/http/query_handler_test.go +++ b/http/query_handler_test.go @@ -260,8 +260,8 @@ func TestFluxHandler_postFluxAST(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { h := &FluxHandler{ - HTTPErrorHandler: kithttp.ErrorHandler(0), - LanguageService: fluxlang.DefaultService, + HTTPErrorHandler: kithttp.ErrorHandler(0), + FluxLanguageService: fluxlang.DefaultService, } h.postFluxAST(tt.w, tt.r) if got := tt.w.Body.String(); got != tt.want { diff --git a/http/query_test.go b/http/query_test.go index 714e4ae842..a4ed7d84a8 100644 --- a/http/query_test.go +++ b/http/query_test.go @@ -16,7 +16,6 @@ import ( "github.com/influxdata/flux/ast" "github.com/influxdata/flux/csv" "github.com/influxdata/flux/lang" - "github.com/influxdata/flux/repl" platform "github.com/influxdata/influxdb" "github.com/influxdata/influxdb/mock" "github.com/influxdata/influxdb/query" @@ -60,7 +59,6 @@ func TestQueryRequest_WithDefaults(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { r := QueryRequest{ - Spec: tt.fields.Spec, AST: tt.fields.AST, Query: tt.fields.Query, Type: tt.fields.Type, @@ -77,7 +75,6 @@ func TestQueryRequest_WithDefaults(t *testing.T) { func TestQueryRequest_Validate(t *testing.T) { type fields struct { Extern *ast.File - Spec *flux.Spec AST *ast.Package Query string Type string @@ -96,19 +93,6 @@ func TestQueryRequest_Validate(t *testing.T) { }, wantErr: true, }, - { - name: "query cannot have both extern and spec", - fields: fields{ - Extern: &ast.File{}, - Spec: &flux.Spec{}, - Type: "flux", - Dialect: QueryDialect{ - Delimiter: ",", - DateTimeFormat: "RFC3339", - }, - }, - wantErr: true, - }, { name: "requires flux type", fields: fields{ @@ -190,7 +174,6 @@ func TestQueryRequest_Validate(t *testing.T) { t.Run(tt.name, func(t *testing.T) { r := QueryRequest{ Extern: tt.fields.Extern, - Spec: tt.fields.Spec, AST: tt.fields.AST, Query: tt.fields.Query, Type: tt.fields.Type, @@ -332,41 +315,11 @@ func TestQueryRequest_proxyRequest(t *testing.T) { }, }, }, - { - name: "valid spec", - fields: fields{ - Type: "flux", - Spec: &flux.Spec{ - Now: time.Unix(0, 0).UTC(), - }, - Dialect: QueryDialect{ - Delimiter: ",", - DateTimeFormat: "RFC3339", - }, - org: &platform.Organization{}, - }, - want: &query.ProxyRequest{ - Request: query.Request{ - Compiler: repl.Compiler{ - Spec: &flux.Spec{ - Now: time.Unix(0, 0).UTC(), - }, - }, - }, - Dialect: &csv.Dialect{ - ResultEncoderConfig: csv.ResultEncoderConfig{ - NoHeader: false, - Delimiter: ',', - }, - }, - }, - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { r := QueryRequest{ Extern: tt.fields.Extern, - Spec: tt.fields.Spec, AST: tt.fields.AST, Query: tt.fields.Query, Type: tt.fields.Type, diff --git a/http/source_service.go b/http/source_service.go index dd0ef331d8..36efc60f97 100644 --- a/http/source_service.go +++ b/http/source_service.go @@ -9,7 +9,6 @@ import ( "github.com/influxdata/flux" "github.com/influxdata/flux/csv" "github.com/influxdata/flux/lang" - "github.com/influxdata/flux/repl" "github.com/influxdata/httprouter" platform "github.com/influxdata/influxdb" "github.com/influxdata/influxdb/pkg/httpc" @@ -168,10 +167,6 @@ func decodeSourceQueryRequest(r *http.Request) (*query.ProxyRequest, error) { req.Request.Compiler = lang.FluxCompiler{ Query: request.Query, } - case repl.CompilerType: - req.Request.Compiler = repl.Compiler{ - Spec: request.Spec, - } case influxql.CompilerType: req.Request.Compiler = &influxql.Compiler{ Cluster: request.Cluster, diff --git a/query.go b/query.go index a90f19a4e2..8c8ae73a43 100644 --- a/query.go +++ b/query.go @@ -4,6 +4,7 @@ import ( "context" "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/complete" "github.com/influxdata/flux/interpreter" "github.com/influxdata/flux/values" ) @@ -28,4 +29,7 @@ type FluxLanguageService interface { // EvalAST will evaluate and run an AST. EvalAST(ctx context.Context, astPkg *ast.Package) ([]interpreter.SideEffect, values.Scope, error) + + // Completer will return a flux completer. + Completer() complete.Completer } diff --git a/query/control/controller.go b/query/control/controller.go index 1c74090e56..38c463fb18 100644 --- a/query/control/controller.go +++ b/query/control/controller.go @@ -29,6 +29,7 @@ import ( "github.com/influxdata/flux/codes" "github.com/influxdata/flux/lang" "github.com/influxdata/flux/memory" + "github.com/influxdata/flux/runtime" "github.com/influxdata/influxdb" "github.com/influxdata/influxdb/kit/errors" "github.com/influxdata/influxdb/kit/prom" @@ -338,7 +339,7 @@ func (c *Controller) compileQuery(q *Query, compiler flux.Compiler) (err error) } } - prog, err := compiler.Compile(ctx) + prog, err := compiler.Compile(ctx, runtime.Default) if err != nil { return &flux.Error{ Msg: "compilation failed", diff --git a/query/fluxlang/service.go b/query/fluxlang/service.go index 956df1abfc..88c1ef6fd2 100644 --- a/query/fluxlang/service.go +++ b/query/fluxlang/service.go @@ -5,6 +5,7 @@ import ( "context" "github.com/influxdata/flux/ast" + "github.com/influxdata/flux/complete" "github.com/influxdata/flux/interpreter" "github.com/influxdata/flux/parser" "github.com/influxdata/flux/runtime" @@ -28,3 +29,7 @@ func (d defaultService) Parse(source string) (pkg *ast.Package, err error) { func (d defaultService) EvalAST(ctx context.Context, astPkg *ast.Package) ([]interpreter.SideEffect, values.Scope, error) { return runtime.EvalAST(ctx, astPkg) } + +func (d defaultService) Completer() complete.Completer { + return complete.NewCompleter(runtime.Prelude()) +} diff --git a/query/influxql/compiler.go b/query/influxql/compiler.go index 4eadb5ea74..8e746635cd 100644 --- a/query/influxql/compiler.go +++ b/query/influxql/compiler.go @@ -42,7 +42,7 @@ func NewCompiler(dbrpMappingSvc platform.DBRPMappingService) *Compiler { } // Compile transpiles the query into a Program. -func (c *Compiler) Compile(ctx context.Context) (flux.Program, error) { +func (c *Compiler) Compile(ctx context.Context, runtime flux.Runtime) (flux.Program, error) { var now time.Time if c.Now != nil { now = *c.Now @@ -64,7 +64,7 @@ func (c *Compiler) Compile(ctx context.Context) (flux.Program, error) { return nil, err } compileOptions := lang.WithLogPlanOpts(c.logicalPlannerOptions...) - return lang.CompileAST(astPkg, now, compileOptions), nil + return lang.CompileAST(astPkg, runtime, now, compileOptions), nil } func (c *Compiler) CompilerType() flux.CompilerType { diff --git a/query/promql/internal/promqltests/go.mod b/query/promql/internal/promqltests/go.mod index 328723c30f..3330b105c5 100644 --- a/query/promql/internal/promqltests/go.mod +++ b/query/promql/internal/promqltests/go.mod @@ -7,7 +7,7 @@ require ( github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31 // indirect github.com/gogo/protobuf v1.3.0 // indirect github.com/google/go-cmp v0.3.1 - github.com/influxdata/flux v0.60.1-0.20200305155158-1add321ebf7a + github.com/influxdata/flux v0.60.1-0.20200309174638-0dbc38c3785a github.com/influxdata/influxdb v0.0.0-20190925213338-8af36d5aaedd github.com/influxdata/influxql v1.0.1 // indirect github.com/influxdata/promql/v2 v2.12.0 diff --git a/query/promql/internal/promqltests/go.sum b/query/promql/internal/promqltests/go.sum index 9625f0d8a3..b7830224fc 100644 --- a/query/promql/internal/promqltests/go.sum +++ b/query/promql/internal/promqltests/go.sum @@ -174,8 +174,6 @@ github.com/gogo/protobuf v1.3.0 h1:G8O7TerXerS4F6sx9OV7/nRfJdnXgHZu/S/7F2SN+UE= github.com/gogo/protobuf v1.3.0/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/golang/gddo v0.0.0-20181116215533-9bd4a3295021 h1:HYV500jCgk+IC68L5sWrLFIWMpaUFfXXpJSAb7XOoBk= github.com/golang/gddo v0.0.0-20181116215533-9bd4a3295021/go.mod h1:xEhNfoBDX1hzLm2Nf80qUvZ2sVwoMZ8d6IE2SrsQfh4= -github.com/golang/geo v0.0.0-20190916061304-5b978397cfec h1:lJwO/92dFXWeXOZdoGXgptLmNLwynMSHUmU6besqtiw= -github.com/golang/geo v0.0.0-20190916061304-5b978397cfec/go.mod h1:QZ0nwyI2jOfgRAoBvP+ab5aRr7c9x7lhGEJrKvBwjWI= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20180924190550-6f2cf27854a4/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -288,8 +286,8 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/influxdata/cron v0.0.0-20191203200038-ded12750aac6 h1:OtjKkeWDjUbyMi82C7XXy7Tvm2LXMwiBBXyFIGNPaGA= github.com/influxdata/cron v0.0.0-20191203200038-ded12750aac6/go.mod h1:XabtPPW2qsCg0tl+kjaPU+cFS+CjQXEXbT1VJvHT4og= -github.com/influxdata/flux v0.60.1-0.20200305155158-1add321ebf7a h1:Dczh6cTotsat9rt7GzD7EhGzpGFO5h0L3zAkQ1sJSds= -github.com/influxdata/flux v0.60.1-0.20200305155158-1add321ebf7a/go.mod h1:BRxpm1xTUAZ+s+Mq6t0NZyaYtlGrw/8YoHoifso9vS8= +github.com/influxdata/flux v0.60.1-0.20200309174638-0dbc38c3785a h1:VUxuayL83N9Fj3re2mOAgHWKCqRJFKRqqXK2mihLXMI= +github.com/influxdata/flux v0.60.1-0.20200309174638-0dbc38c3785a/go.mod h1:BRxpm1xTUAZ+s+Mq6t0NZyaYtlGrw/8YoHoifso9vS8= github.com/influxdata/httprouter v1.3.1-0.20191122104820-ee83e2772f69 h1:WQsmW0fXO4ZE/lFGIE84G6rIV5SJN3P3sjIXAP1a8eU= github.com/influxdata/httprouter v1.3.1-0.20191122104820-ee83e2772f69/go.mod h1:pwymjR6SrP3gD3pRj9RJwdl1j5s3doEEV8gS4X9qSzA= github.com/influxdata/influxql v0.0.0-20180925231337-1cbfca8e56b6/go.mod h1:KpVI7okXjK6PRi3Z5B+mtKZli+R1DnZgb3N+tzevNgo= diff --git a/query/service_test.go b/query/service_test.go index e740c2c0ed..d766758638 100644 --- a/query/service_test.go +++ b/query/service_test.go @@ -21,7 +21,7 @@ type compilerA struct { A string `json:"a"` } -func (c compilerA) Compile(ctx context.Context) (flux.Program, error) { +func (c compilerA) Compile(ctx context.Context, runtime flux.Runtime) (flux.Program, error) { panic("not implemented") }