2018-07-12 14:46:29 +00:00
|
|
|
package spectests
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-10-31 18:39:36 +00:00
|
|
|
|
2018-10-05 04:06:14 +00:00
|
|
|
"github.com/influxdata/flux/functions/inputs"
|
|
|
|
"github.com/influxdata/flux/functions/transformations"
|
|
|
|
|
2018-07-12 14:46:29 +00:00
|
|
|
"math"
|
|
|
|
"time"
|
|
|
|
|
2018-09-06 18:09:52 +00:00
|
|
|
"github.com/influxdata/flux"
|
|
|
|
"github.com/influxdata/flux/ast"
|
|
|
|
"github.com/influxdata/flux/execute"
|
2018-10-05 04:06:14 +00:00
|
|
|
|
2018-09-06 18:09:52 +00:00
|
|
|
"github.com/influxdata/flux/semantic"
|
2018-07-12 14:46:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RegisterFixture(
|
2018-09-06 18:09:52 +00:00
|
|
|
AggregateTest(func(aggregate flux.Operation) (stmt string, spec *flux.Spec) {
|
2018-07-12 14:46:29 +00:00
|
|
|
return fmt.Sprintf(`SELECT %s(value) FROM db0..cpu WHERE time >= now() - 10m GROUP BY time(5m, 12m)`, aggregate.Spec.Kind()),
|
2018-09-06 18:09:52 +00:00
|
|
|
&flux.Spec{
|
|
|
|
Operations: []*flux.Operation{
|
2018-07-12 14:46:29 +00:00
|
|
|
{
|
|
|
|
ID: "from0",
|
2018-10-05 04:06:14 +00:00
|
|
|
Spec: &inputs.FromOpSpec{
|
2018-10-10 00:36:41 +00:00
|
|
|
BucketID: bucketID.String(),
|
2018-07-12 14:46:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "range0",
|
2018-10-05 04:06:14 +00:00
|
|
|
Spec: &transformations.RangeOpSpec{
|
2018-11-05 18:49:01 +00:00
|
|
|
Start: flux.Time{Absolute: Now().Add(-10 * time.Minute)},
|
|
|
|
Stop: flux.Time{Absolute: Now()},
|
|
|
|
TimeColumn: execute.DefaultTimeColLabel,
|
|
|
|
StartColumn: execute.DefaultStartColLabel,
|
|
|
|
StopColumn: execute.DefaultStopColLabel,
|
2018-07-12 14:46:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "filter0",
|
2018-10-05 04:06:14 +00:00
|
|
|
Spec: &transformations.FilterOpSpec{
|
2018-07-12 14:46:29 +00:00
|
|
|
Fn: &semantic.FunctionExpression{
|
2018-10-31 18:39:36 +00:00
|
|
|
Block: &semantic.FunctionBlock{
|
|
|
|
Parameters: &semantic.FunctionParameters{
|
|
|
|
List: []*semantic.FunctionParameter{
|
|
|
|
{Key: &semantic.Identifier{Name: "r"}},
|
2018-07-12 14:46:29 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-31 18:39:36 +00:00
|
|
|
Body: &semantic.LogicalExpression{
|
|
|
|
Operator: ast.AndOperator,
|
|
|
|
Left: &semantic.BinaryExpression{
|
|
|
|
Operator: ast.EqualOperator,
|
|
|
|
Left: &semantic.MemberExpression{
|
|
|
|
Object: &semantic.IdentifierExpression{
|
|
|
|
Name: "r",
|
|
|
|
},
|
|
|
|
Property: "_measurement",
|
|
|
|
},
|
|
|
|
Right: &semantic.StringLiteral{
|
|
|
|
Value: "cpu",
|
2018-07-12 14:46:29 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-31 18:39:36 +00:00
|
|
|
Right: &semantic.BinaryExpression{
|
|
|
|
Operator: ast.EqualOperator,
|
|
|
|
Left: &semantic.MemberExpression{
|
|
|
|
Object: &semantic.IdentifierExpression{
|
|
|
|
Name: "r",
|
|
|
|
},
|
|
|
|
Property: "_field",
|
|
|
|
},
|
|
|
|
Right: &semantic.StringLiteral{
|
|
|
|
Value: "value",
|
|
|
|
},
|
2018-07-12 14:46:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "group0",
|
2018-10-05 04:06:14 +00:00
|
|
|
Spec: &transformations.GroupOpSpec{
|
2018-12-04 17:32:37 +00:00
|
|
|
Columns: []string{"_measurement", "_start"},
|
|
|
|
Mode: "by",
|
2018-07-12 14:46:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "window0",
|
2018-10-05 04:06:14 +00:00
|
|
|
Spec: &transformations.WindowOpSpec{
|
2018-11-05 18:49:01 +00:00
|
|
|
Every: flux.Duration(5 * time.Minute),
|
|
|
|
Period: flux.Duration(5 * time.Minute),
|
|
|
|
Start: flux.Time{Absolute: time.Unix(0, 0).Add(time.Minute * 2)},
|
|
|
|
TimeColumn: execute.DefaultTimeColLabel,
|
|
|
|
StartColumn: execute.DefaultStartColLabel,
|
|
|
|
StopColumn: execute.DefaultStopColLabel,
|
2018-07-12 14:46:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
&aggregate,
|
2018-09-11 22:04:53 +00:00
|
|
|
{
|
|
|
|
ID: "duplicate0",
|
2018-10-05 04:06:14 +00:00
|
|
|
Spec: &transformations.DuplicateOpSpec{
|
2018-11-05 18:49:01 +00:00
|
|
|
Column: execute.DefaultStartColLabel,
|
|
|
|
As: execute.DefaultTimeColLabel,
|
2018-09-11 22:04:53 +00:00
|
|
|
},
|
|
|
|
},
|
2018-07-12 14:46:29 +00:00
|
|
|
{
|
|
|
|
ID: "window1",
|
2018-10-05 04:06:14 +00:00
|
|
|
Spec: &transformations.WindowOpSpec{
|
2018-11-05 18:49:01 +00:00
|
|
|
Every: flux.Duration(math.MaxInt64),
|
|
|
|
Period: flux.Duration(math.MaxInt64),
|
|
|
|
TimeColumn: execute.DefaultTimeColLabel,
|
|
|
|
StartColumn: execute.DefaultStartColLabel,
|
|
|
|
StopColumn: execute.DefaultStopColLabel,
|
2018-07-12 14:46:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "map0",
|
2018-10-05 04:06:14 +00:00
|
|
|
Spec: &transformations.MapOpSpec{
|
2018-07-12 14:46:29 +00:00
|
|
|
Fn: &semantic.FunctionExpression{
|
2018-10-31 18:39:36 +00:00
|
|
|
Block: &semantic.FunctionBlock{
|
|
|
|
Parameters: &semantic.FunctionParameters{
|
|
|
|
List: []*semantic.FunctionParameter{{
|
|
|
|
Key: &semantic.Identifier{Name: "r"},
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
Body: &semantic.ObjectExpression{
|
|
|
|
Properties: []*semantic.Property{
|
|
|
|
{
|
|
|
|
Key: &semantic.Identifier{Name: "_time"},
|
|
|
|
Value: &semantic.MemberExpression{
|
|
|
|
Object: &semantic.IdentifierExpression{
|
|
|
|
Name: "r",
|
|
|
|
},
|
|
|
|
Property: "_time",
|
2018-07-12 14:46:29 +00:00
|
|
|
},
|
|
|
|
},
|
2018-10-31 18:39:36 +00:00
|
|
|
{
|
|
|
|
Key: &semantic.Identifier{Name: string(aggregate.Spec.Kind())},
|
|
|
|
Value: &semantic.MemberExpression{
|
|
|
|
Object: &semantic.IdentifierExpression{
|
|
|
|
Name: "r",
|
|
|
|
},
|
|
|
|
Property: "_value",
|
2018-07-12 14:46:29 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
MergeKey: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
ID: "yield0",
|
2018-10-05 04:06:14 +00:00
|
|
|
Spec: &transformations.YieldOpSpec{
|
2018-07-12 14:46:29 +00:00
|
|
|
Name: "0",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2018-09-06 18:09:52 +00:00
|
|
|
Edges: []flux.Edge{
|
2018-07-12 14:46:29 +00:00
|
|
|
{Parent: "from0", Child: "range0"},
|
|
|
|
{Parent: "range0", Child: "filter0"},
|
|
|
|
{Parent: "filter0", Child: "group0"},
|
|
|
|
{Parent: "group0", Child: "window0"},
|
|
|
|
{Parent: "window0", Child: aggregate.ID},
|
2018-09-11 22:04:53 +00:00
|
|
|
{Parent: aggregate.ID, Child: "duplicate0"},
|
|
|
|
{Parent: "duplicate0", Child: "window1"},
|
2018-07-12 14:46:29 +00:00
|
|
|
{Parent: "window1", Child: "map0"},
|
|
|
|
{Parent: "map0", Child: "yield0"},
|
|
|
|
},
|
2018-07-25 13:34:41 +00:00
|
|
|
Now: Now(),
|
2018-07-12 14:46:29 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
}
|