influxdb/query/promql/query.go

29 lines
639 B
Go
Raw Normal View History

// Package promql implements a promql parser to build flux query specifications from promql.
2018-05-21 21:13:54 +00:00
package promql
import (
"fmt"
"github.com/influxdata/flux"
2018-05-21 21:13:54 +00:00
)
func ParsePromQL(promql string, opts ...Option) (interface{}, error) {
f, err := Parse("", []byte(promql), opts...)
if err != nil {
return "", err
}
return f, nil
}
func Build(promql string, opts ...Option) (*flux.Spec, error) {
2018-05-21 21:13:54 +00:00
parsed, err := ParsePromQL(promql, opts...)
if err != nil {
return nil, err
}
builder, ok := parsed.(QueryBuilder)
if !ok {
return nil, fmt.Errorf("unable to build as %t is not a QueryBuilder", parsed)
2018-05-21 21:13:54 +00:00
}
return builder.QuerySpec()
}