WIP supporting integers/floats for influxql arguments

pull/2105/head
Chris Goller 2017-10-11 14:45:01 -05:00
parent a5d28c3eca
commit 0d3762e272
3 changed files with 41 additions and 34 deletions

View File

@ -495,7 +495,7 @@ type TriggerValues struct {
// Field represent influxql fields and functions from the UI // Field represent influxql fields and functions from the UI
type Field struct { type Field struct {
Name string `json:"name"` Name interface{} `json:"name"`
Type string `json:"type"` Type string `json:"type"`
Alias string `json:"alias"` Alias string `json:"alias"`
Args []Field `json:"args,omitempty"` Args []Field `json:"args,omitempty"`

View File

@ -146,29 +146,35 @@ func Convert(influxQL string) (chronograf.QueryConfig, error) {
if _, ok = supportedFuncs[f.Name]; !ok { if _, ok = supportedFuncs[f.Name]; !ok {
return raw, nil return raw, nil
} }
// Query configs only support single argument functions
if len(f.Args) != 1 { fldArgs := []chronograf.Field{}
for _, arg := range f.Args {
switch ref := arg.(type) {
case *influxql.VarRef:
fldArgs = append(fldArgs, chronograf.Field{
Name: ref.Val,
Type: "field",
})
case *influxql.IntegerLiteral:
fldArgs = append(fldArgs, chronograf.Field{
Name: ref.Val,
Type: "integer",
})
case *influxql.NumberLiteral:
fldArgs = append(fldArgs, chronograf.Field{
Name: ref.Val,
Type: "number",
})
default:
return raw, nil return raw, nil
} }
ref, ok := f.Args[0].(*influxql.VarRef)
// query config only support fields in the function
if !ok {
return raw, nil
}
// We only support field strings
if ref.Type != influxql.Unknown {
return raw, nil
} }
qc.Fields = append(qc.Fields, chronograf.Field{ qc.Fields = append(qc.Fields, chronograf.Field{
Name: f.Name, Name: f.Name,
Type: "func", Type: "func",
Alias: fld.Alias, Alias: fld.Alias,
Args: []chronograf.Field{ Args: fldArgs,
{
Name: ref.Val,
Type: "field",
},
},
}) })
case *influxql.VarRef: case *influxql.VarRef:
if f.Type != influxql.Unknown { if f.Type != influxql.Unknown {
@ -453,6 +459,7 @@ var supportedFuncs = map[string]bool{
"last": true, "last": true,
"spread": true, "spread": true,
"stddev": true, "stddev": true,
"percentile": true,
} }
// shortDur converts duration into the queryConfig duration format // shortDur converts duration into the queryConfig duration format

View File

@ -156,12 +156,12 @@ func field(q *chronograf.QueryConfig) (string, error) {
if field.Type == "func" && len(field.Args) > 0 { if field.Type == "func" && len(field.Args) > 0 {
for _, arg := range field.Args { for _, arg := range field.Args {
if arg.Type == "field" { if arg.Type == "field" {
return arg.Name, nil return arg.Name.(string), nil
} }
} }
return "", fmt.Errorf("No fields set in query") return "", fmt.Errorf("No fields set in query")
} }
return field.Name, nil return field.Name.(string), nil
} }
} }
return "", fmt.Errorf("No fields set in query") return "", fmt.Errorf("No fields set in query")