4
4
"context"
5
5
"sort"
6
6
"testing"
7
+ "time"
7
8
8
9
"github.com/google/go-cmp/cmp"
9
10
"github.com/influxdata/flux"
@@ -13,11 +14,104 @@ import (
13
14
"github.com/influxdata/flux/execute/executetest"
14
15
"github.com/influxdata/flux/execute/table"
15
16
"github.com/influxdata/flux/internal/gen"
17
+ "github.com/influxdata/flux/internal/operation"
16
18
"github.com/influxdata/flux/memory"
19
+ "github.com/influxdata/flux/querytest"
20
+ "github.com/influxdata/flux/stdlib/influxdata/influxdb"
17
21
"github.com/influxdata/flux/stdlib/universe"
18
22
"github.com/influxdata/flux/values"
19
23
)
20
24
25
+ func TestLimit_NewQuery (t * testing.T ) {
26
+ tests := []querytest.NewQueryTestCase {
27
+ {
28
+ Name : "no offset" ,
29
+ Raw : `
30
+ from(bucket:"db") |> range(start:-1h) |> limit(n: 1)` ,
31
+ Want : & operation.Spec {
32
+ Operations : []* operation.Node {
33
+ {
34
+ ID : "from0" ,
35
+ Spec : & influxdb.FromOpSpec {Bucket : influxdb.NameOrID {Name : "db" }},
36
+ },
37
+ {
38
+ ID : "range1" ,
39
+ Spec : & universe.RangeOpSpec {
40
+ Start : flux.Time {
41
+ Relative : - 1 * time .Hour ,
42
+ IsRelative : true ,
43
+ },
44
+ Stop : flux.Time {
45
+ IsRelative : true ,
46
+ },
47
+ TimeColumn : "_time" ,
48
+ StartColumn : "_start" ,
49
+ StopColumn : "_stop" ,
50
+ },
51
+ },
52
+ {
53
+ ID : "limit2" ,
54
+ Spec : & universe.LimitOpSpec {N : 1 },
55
+ },
56
+ },
57
+ Edges : []operation.Edge {
58
+ {Parent : "from0" , Child : "range1" },
59
+ {Parent : "range1" , Child : "limit2" },
60
+ },
61
+ },
62
+ },
63
+ {
64
+ Name : "positive offset" ,
65
+ Raw : `
66
+ from(bucket:"db") |> range(start:-1h) |> limit(n: 1, offset: 2)` ,
67
+ Want : & operation.Spec {
68
+ Operations : []* operation.Node {
69
+ {
70
+ ID : "from0" ,
71
+ Spec : & influxdb.FromOpSpec {Bucket : influxdb.NameOrID {Name : "db" }},
72
+ },
73
+ {
74
+ ID : "range1" ,
75
+ Spec : & universe.RangeOpSpec {
76
+ Start : flux.Time {
77
+ Relative : - 1 * time .Hour ,
78
+ IsRelative : true ,
79
+ },
80
+ Stop : flux.Time {
81
+ IsRelative : true ,
82
+ },
83
+ TimeColumn : "_time" ,
84
+ StartColumn : "_start" ,
85
+ StopColumn : "_stop" ,
86
+ },
87
+ },
88
+ {
89
+ ID : "limit2" ,
90
+ Spec : & universe.LimitOpSpec {N : 1 , Offset : 2 },
91
+ },
92
+ },
93
+ Edges : []operation.Edge {
94
+ {Parent : "from0" , Child : "range1" },
95
+ {Parent : "range1" , Child : "limit2" },
96
+ },
97
+ },
98
+ },
99
+ {
100
+ Name : "negative offset" ,
101
+ Raw : `
102
+ from(bucket:"db") |> range(start:-1h) |> limit(n: 1, offset: -1)` ,
103
+ WantErr : true ,
104
+ },
105
+ }
106
+ for _ , tc := range tests {
107
+ tc := tc
108
+ t .Run (tc .Name , func (t * testing.T ) {
109
+ t .Parallel ()
110
+ querytest .NewQueryTestHelper (t , tc )
111
+ })
112
+ }
113
+ }
114
+
21
115
func TestLimit_Process (t * testing.T ) {
22
116
testCases := []struct {
23
117
name string
0 commit comments