2018-07-25 18:27:10 +00:00
|
|
|
package influxql
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2018-09-06 18:09:52 +00:00
|
|
|
"github.com/influxdata/flux"
|
2018-07-25 18:27:10 +00:00
|
|
|
"github.com/influxdata/platform"
|
|
|
|
)
|
|
|
|
|
|
|
|
const CompilerType = "influxql"
|
|
|
|
|
|
|
|
// AddCompilerMappings adds the influxql specific compiler mappings.
|
2018-09-06 18:09:52 +00:00
|
|
|
func AddCompilerMappings(mappings flux.CompilerMappings, dbrpMappingSvc platform.DBRPMappingService) error {
|
|
|
|
return mappings.Add(CompilerType, func() flux.Compiler {
|
2018-07-25 18:27:10 +00:00
|
|
|
return NewCompiler(dbrpMappingSvc)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compiler is the transpiler to convert InfluxQL to a Flux specification.
|
|
|
|
type Compiler struct {
|
|
|
|
Cluster string `json:"cluster,omitempty"`
|
|
|
|
DB string `json:"db,omitempty"`
|
|
|
|
RP string `json:"rp,omitempty"`
|
|
|
|
Query string `json:"query"`
|
|
|
|
|
|
|
|
dbrpMappingSvc platform.DBRPMappingService
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewCompiler(dbrpMappingSvc platform.DBRPMappingService) *Compiler {
|
|
|
|
return &Compiler{
|
|
|
|
dbrpMappingSvc: dbrpMappingSvc,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compile tranpiles the query into a specification.
|
2018-09-06 18:09:52 +00:00
|
|
|
func (c *Compiler) Compile(ctx context.Context) (*flux.Spec, error) {
|
2018-07-25 18:27:10 +00:00
|
|
|
transpiler := NewTranspilerWithConfig(
|
|
|
|
c.dbrpMappingSvc,
|
|
|
|
Config{
|
|
|
|
Cluster: c.Cluster,
|
|
|
|
DefaultDatabase: c.DB,
|
|
|
|
DefaultRetentionPolicy: c.RP,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
return transpiler.Transpile(ctx, c.Query)
|
|
|
|
}
|
2018-09-06 18:09:52 +00:00
|
|
|
func (c *Compiler) CompilerType() flux.CompilerType {
|
2018-07-25 18:27:10 +00:00
|
|
|
return CompilerType
|
|
|
|
}
|