2019-01-23 21:53:45 +00:00
|
|
|
package querytest
|
|
|
|
|
|
|
|
import (
|
2020-04-20 21:03:46 +00:00
|
|
|
"context"
|
|
|
|
|
2019-04-03 14:34:48 +00:00
|
|
|
"github.com/influxdata/flux/plan"
|
2020-03-03 02:08:19 +00:00
|
|
|
"github.com/influxdata/flux/stdlib/influxdata/influxdb"
|
2020-04-28 17:49:36 +00:00
|
|
|
v1 "github.com/influxdata/flux/stdlib/influxdata/influxdb/v1"
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/query/influxql"
|
2019-01-23 21:53:45 +00:00
|
|
|
)
|
|
|
|
|
2019-04-03 14:34:48 +00:00
|
|
|
// MakeFromInfluxJSONCompiler returns a compiler that replaces all From operations with FromJSON.
|
|
|
|
func MakeFromInfluxJSONCompiler(c *influxql.Compiler, jsonFile string) {
|
|
|
|
c.WithLogicalPlannerOptions(plan.AddLogicalRules(ReplaceFromRule{Filename: jsonFile}))
|
|
|
|
}
|
|
|
|
|
|
|
|
type ReplaceFromRule struct {
|
|
|
|
Filename string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ReplaceFromRule) Name() string {
|
|
|
|
return "ReplaceFromRule"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ReplaceFromRule) Pattern() plan.Pattern {
|
|
|
|
return plan.Pat(influxdb.FromKind)
|
|
|
|
}
|
|
|
|
|
2020-04-20 21:03:46 +00:00
|
|
|
func (r ReplaceFromRule) Rewrite(ctx context.Context, n plan.Node) (plan.Node, bool, error) {
|
2019-04-03 14:34:48 +00:00
|
|
|
if err := n.ReplaceSpec(&v1.FromInfluxJSONProcedureSpec{
|
|
|
|
File: r.Filename,
|
|
|
|
}); err != nil {
|
|
|
|
return nil, false, err
|
|
|
|
}
|
|
|
|
return n, true, nil
|
2019-01-23 21:53:45 +00:00
|
|
|
}
|