@@ -88,3 +88,129 @@ testcase histogram_quantile_minvalue {
88
88
89
89
testing.diff(got, want)
90
90
}
91
+
92
+ testcase histogramQuantileInvalidOnNonmonotonic {
93
+ inData =
94
+ "
95
+ #datatype,string,long,dateTime:RFC3339,string,double,double,string
96
+ #group,false,false,true,true,false,false,true
97
+ #default,_result,,,,,,
98
+ ,result,table,_time,_field,_value,le,_measurement
99
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,10,-80,mm
100
+ "
101
+ fn = () =>
102
+ csv.from(csv: inData)
103
+ |> range(start: 2018-05-22T19:53:00Z)
104
+ |> histogramQuantile(quantile: 0.25, minValue: -100.0, onNonmonotonic: "asdf")
105
+
106
+ testing.shouldError(
107
+ fn: fn,
108
+ want: /value provided to histogramQuantile parameter onNonmonotonic is invalid/,
109
+ )
110
+ }
111
+
112
+ testcase histogramQuantileOnNonmonotonicError {
113
+ inData =
114
+ "
115
+ #datatype,string,long,dateTime:RFC3339,string,double,double,string
116
+ #group,false,false,true,true,false,false,true
117
+ #default,_result,,,,,,
118
+ ,result,table,_time,_field,_value,le,_measurement
119
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,1,0.1,l
120
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,2,0.2,l
121
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,2,0.3,l
122
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,3,0.4,l
123
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,2,0.5,l
124
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,2,0.6,l
125
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,2,0.7,l
126
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,8,0.8,l
127
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,10,0.9,l
128
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,10,+Inf,l
129
+ "
130
+ fn = () =>
131
+ csv.from(csv: inData)
132
+ |> histogramQuantile(quantile: 0.9)
133
+ |> tableFind(fn: (key) => true)
134
+ |> findRecord(fn: (key) => true, idx: 0)
135
+
136
+ testing.shouldError(fn: fn, want: /histogram records counts are not monotonic/)
137
+ }
138
+
139
+ testcase histogramQuantileOnNonmonotonicForce {
140
+ inData =
141
+ "
142
+ #datatype,string,long,dateTime:RFC3339,string,double,double,string
143
+ #group,false,false,true,true,false,false,true
144
+ #default,_result,,,,,,
145
+ ,result,table,_time,_field,_value,le,_measurement
146
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,1,0.1,l
147
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,2,0.2,l
148
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,2,0.3,l
149
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,0,0.4,l
150
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,1,0.5,l
151
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,1,0.6,l
152
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,2,0.7,l
153
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,8,0.8,l
154
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,10,0.9,l
155
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,10,+Inf,l
156
+ "
157
+ outData =
158
+ "
159
+ #datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,double,string
160
+ #group,false,false,true,true,true,true,false,true
161
+ #default,_result,,,,,,,
162
+ ,result,table,_start,_stop,_time,_field,_value,_measurement
163
+ ,,0,2018-05-22T19:53:00Z,2030-01-01T00:00:00Z,2018-05-22T19:53:00Z,x_duration_seconds,0.8500000000000001,l
164
+ "
165
+
166
+ got =
167
+ csv.from(csv: inData)
168
+ |> range(start: 2018-05-22T19:53:00Z)
169
+ |> histogramQuantile(quantile: 0.9, onNonmonotonic: "force")
170
+ want = csv.from(csv: outData)
171
+
172
+ testing.diff(got, want)
173
+ }
174
+
175
+ testcase histogramQuantileOnNonmonotonicDrop {
176
+ inData =
177
+ "
178
+ #datatype,string,long,dateTime:RFC3339,string,double,double,string
179
+ #group,false,false,true,true,false,false,true
180
+ #default,_result,,,,,,
181
+ ,result,table,_time,_field,_value,le,_measurement
182
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,1,0.1,l
183
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,2,0.2,l
184
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,2,0.3,l
185
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,0,0.4,l
186
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,1,0.5,l
187
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,1,0.6,l
188
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,2,0.7,l
189
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,8,0.8,l
190
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,10,0.9,l
191
+ ,,0,2018-05-22T19:53:00Z,x_duration_seconds,10,+Inf,l
192
+ ,,1,2018-05-22T19:53:00Z,y_duration_seconds,0,-Inf,l
193
+ ,,1,2018-05-22T19:53:00Z,y_duration_seconds,10,0.2,l
194
+ ,,1,2018-05-22T19:53:00Z,y_duration_seconds,15,0.4,l
195
+ ,,1,2018-05-22T19:53:00Z,y_duration_seconds,25,0.6,l
196
+ ,,1,2018-05-22T19:53:00Z,y_duration_seconds,35,0.8,l
197
+ ,,1,2018-05-22T19:53:00Z,y_duration_seconds,45,1,l
198
+ ,,1,2018-05-22T19:53:00Z,y_duration_seconds,45,+Inf,l
199
+ "
200
+ outData =
201
+ "
202
+ #datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,dateTime:RFC3339,string,double,string
203
+ #group,false,false,true,true,true,true,false,true
204
+ #default,_result,,,,,,,
205
+ ,result,table,_start,_stop,_time,_field,_value,_measurement
206
+ ,,1,2018-05-22T19:53:00Z,2030-01-01T00:00:00Z,2018-05-22T19:53:00Z,y_duration_seconds,0.91,l
207
+ "
208
+
209
+ got =
210
+ csv.from(csv: inData)
211
+ |> range(start: 2018-05-22T19:53:00Z)
212
+ |> histogramQuantile(quantile: 0.9, onNonmonotonic: "drop")
213
+ want = csv.from(csv: outData)
214
+
215
+ testing.diff(got, want)
216
+ }
0 commit comments