WIP supporting integers/floats for influxql arguments
parent
a5d28c3eca
commit
0d3762e272
|
@ -495,10 +495,10 @@ 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"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupBy represents influxql group by tags from the UI
|
// GroupBy represents influxql group by tags from the UI
|
||||||
|
|
|
@ -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{}
|
||||||
return raw, nil
|
for _, arg := range f.Args {
|
||||||
}
|
switch ref := arg.(type) {
|
||||||
ref, ok := f.Args[0].(*influxql.VarRef)
|
case *influxql.VarRef:
|
||||||
// query config only support fields in the function
|
fldArgs = append(fldArgs, chronograf.Field{
|
||||||
if !ok {
|
Name: ref.Val,
|
||||||
return raw, nil
|
Type: "field",
|
||||||
}
|
})
|
||||||
// We only support field strings
|
case *influxql.IntegerLiteral:
|
||||||
if ref.Type != influxql.Unknown {
|
fldArgs = append(fldArgs, chronograf.Field{
|
||||||
return raw, nil
|
Name: ref.Val,
|
||||||
|
Type: "integer",
|
||||||
|
})
|
||||||
|
case *influxql.NumberLiteral:
|
||||||
|
fldArgs = append(fldArgs, chronograf.Field{
|
||||||
|
Name: ref.Val,
|
||||||
|
Type: "number",
|
||||||
|
})
|
||||||
|
default:
|
||||||
|
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 {
|
||||||
|
@ -443,16 +449,17 @@ func isTagFilter(exp influxql.Expr) (tagFilter, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var supportedFuncs = map[string]bool{
|
var supportedFuncs = map[string]bool{
|
||||||
"mean": true,
|
"mean": true,
|
||||||
"median": true,
|
"median": true,
|
||||||
"count": true,
|
"count": true,
|
||||||
"min": true,
|
"min": true,
|
||||||
"max": true,
|
"max": true,
|
||||||
"sum": true,
|
"sum": true,
|
||||||
"first": true,
|
"first": true,
|
||||||
"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
|
||||||
|
|
|
@ -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")
|
||||||
|
|
Loading…
Reference in New Issue