Skip to content

Commit e74f6ac

Browse files
committed
ES|QL: Improve tests
1 parent 5603fae commit e74f6ac

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/resources/tbucket.csv-spec

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ FROM sample_data
77
| STATS min = MIN(@timestamp), max = MAX(@timestamp) BY bucket = TBUCKET(10 seconds)
88
| SORT min
99
;
10+
ignoreOrder:true
1011

1112
min:datetime | max:datetime | bucket:datetime
1213
2023-10-23T12:15:03.360Z | 2023-10-23T12:15:03.360Z | 2023-10-23T12:15:00.000Z
@@ -26,6 +27,7 @@ FROM sample_data
2627
| STATS min = MIN(@timestamp), max = MAX(@timestamp) BY bucket = TBUCKET("10 seconds")
2728
| SORT min
2829
;
30+
ignoreOrder:true
2931

3032
min:datetime | max:datetime | bucket:datetime
3133
2023-10-23T12:15:03.360Z | 2023-10-23T12:15:03.360Z | 2023-10-23T12:15:00.000Z
@@ -44,6 +46,7 @@ FROM sample_data
4446
| STATS min = MIN(@timestamp), max = MAX(@timestamp) BY bucket = TBUCKET(10 minutes)
4547
| SORT min
4648
;
49+
ignoreOrder:true
4750

4851
min:datetime | max:datetime | bucket:datetime
4952
2023-10-23T12:15:03.360Z | 2023-10-23T12:15:03.360Z | 2023-10-23T12:10:00.000Z
@@ -60,6 +63,7 @@ FROM sample_data
6063
| STATS min = MIN(@timestamp), max = MAX(@timestamp) BY bucket = TBUCKET("10 minutes")
6164
| SORT min
6265
;
66+
ignoreOrder:true
6367

6468
min:datetime | max:datetime | bucket:datetime
6569
2023-10-23T12:15:03.360Z | 2023-10-23T12:15:03.360Z | 2023-10-23T12:10:00.000Z
@@ -223,8 +227,8 @@ FROM sample_data
223227
| WHERE event_duration > 0
224228
| KEEP @timestamp, client_ip, event_duration
225229
| STATS count = COUNT(*), avg_dur = AVG(event_duration) BY hour = TBUCKET(1h), client_ip
226-
| SORT avg_dur DESC
227230
;
231+
ignoreOrder:true
228232

229233
count:long | avg_dur:double | hour:datetime | client_ip:ip
230234
4 | 3945955.75 | 2023-10-23T13:00:00.000Z | 172.21.3.15
@@ -241,8 +245,8 @@ FROM sample_data
241245
| WHERE message == "Connection error"
242246
| KEEP @*, message
243247
| STATS errors = COUNT() BY day = TBUCKET(1d), message
244-
| SORT day ASC, errors
245248
;
249+
ignoreOrder:true
246250

247251
errors:long | day:datetime | message:keyword
248252
3 | 2023-10-23T00:00:00.000Z | Connection error
@@ -256,8 +260,8 @@ FROM sample_data
256260
| WHERE client_ip IS NOT NULL
257261
| KEEP *stamp*, client_ip, event_duration
258262
| STATS p95 = PERCENTILE(event_duration, 95) BY ten_min = TBUCKET(10min), client_ip
259-
| SORT ten_min ASC, p95
260263
;
264+
ignoreOrder:true
261265

262266
p95:double | ten_min:datetime | client_ip:ip
263267
3450233.0 | 2023-10-23T12:10:00.000Z | 172.21.2.162
@@ -275,8 +279,8 @@ FROM sample_data
275279
| STATS day_count = COUNT(), day_p95 = PERCENTILE(event_duration, 95) BY day = TBUCKET(1d), @timestamp
276280
| WHERE day_count > 0
277281
| STATS hour_count = COUNT(), hour_p95 = PERCENTILE(day_p95, 95) BY hour = TBUCKET(1h), day
278-
| SORT day ASC, hour ASC, hour_count
279282
;
283+
ignoreOrder:true
280284

281285
hour_count:long | hour_p95:double | hour:datetime | day:datetime
282286
2 | 3415965.8 | 2023-10-23T12:00:00.000Z | 2023-10-23T00:00:00.000Z
@@ -292,8 +296,8 @@ FROM sample_data
292296
| STATS reqs = COUNT(), max_dur = MAX(event_duration) BY day = TBUCKET(1d), client_ip, @timestamp
293297
| WHERE max_dur > 1000
294298
| STATS spikes = COUNT() BY hour = TBUCKET(1h), client_ip, day
295-
| SORT spikes DESC, client_ip ASC
296299
;
300+
ignoreOrder:true
297301

298302
spikes:long | hour:datetime | client_ip:ip | day:datetime
299303
4 | 2023-10-23T13:00:00.000Z | 172.21.3.15 | 2023-10-23T00:00:00.000Z
@@ -310,8 +314,8 @@ FROM sample_data
310314
| KEEP @timestamp, event_duration, message
311315
| EVAL t = @timestamp
312316
| STATS total = COUNT(*), med = MEDIAN(event_duration) BY d = TBUCKET(1d), message
313-
| SORT med ASC
314317
;
318+
ignoreOrder:true
315319

316320
total:long | med:double | d:datetime | message:keyword
317321
1 | 1232382.0 | 2023-10-23T00:00:00.000Z | Disconnected
@@ -331,8 +335,8 @@ FROM sample_data
331335
| STATS total = COUNT(*), med = MEDIAN(event_duration) BY d = TBUCKET(1d), message, @timestamp
332336
| WHERE total > 0
333337
| STATS day_total = SUM(total), hour_med = MEDIAN(med) BY h = TBUCKET(1h), message
334-
| SORT hour_med DESC
335338
;
339+
ignoreOrder:true
336340

337341
day_total:long | hour_med:double | h:datetime | message:keyword
338342
3 | 5033755.0 | 2023-10-23T13:00:00.000Z | Connection error

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/grouping/TBucket.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
package org.elasticsearch.xpack.esql.expression.function.grouping;
99

10-
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
11-
import org.elasticsearch.common.io.stream.StreamInput;
1210
import org.elasticsearch.common.io.stream.StreamOutput;
1311
import org.elasticsearch.compute.operator.EvalOperator;
1412
import org.elasticsearch.xpack.esql.core.expression.Expression;
@@ -22,7 +20,6 @@
2220
import org.elasticsearch.xpack.esql.expression.function.FunctionInfo;
2321
import org.elasticsearch.xpack.esql.expression.function.FunctionType;
2422
import org.elasticsearch.xpack.esql.expression.function.Param;
25-
import org.elasticsearch.xpack.esql.io.stream.PlanStreamInput;
2623

2724
import java.io.IOException;
2825
import java.util.List;
@@ -35,7 +32,7 @@
3532
* Splits dates into a given number of buckets. The span is derived from a time range provided.
3633
*/
3734
public class TBucket extends GroupingFunction.EvaluatableGroupingFunction implements SurrogateExpression {
38-
public static final NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Expression.class, "TBucket", TBucket::new);
35+
public static final String NAME = "TBucket";
3936

4037
private final Expression buckets;
4138
private final Expression timestamp;
@@ -77,10 +74,6 @@ public TBucket(Source source, Expression buckets, Expression timestamp) {
7774
this.timestamp = timestamp;
7875
}
7976

80-
private TBucket(StreamInput in) throws IOException {
81-
this(Source.readFrom((PlanStreamInput) in), in.readNamedWriteable(Expression.class), in.readNamedWriteable(Expression.class));
82-
}
83-
8477
@Override
8578
public void writeTo(StreamOutput out) throws IOException {
8679
throw new UnsupportedOperationException("not serialized");

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/FieldNameUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
public class FieldNameUtils {
6161

62-
private static final Set<String> FUNCTIONS_REQUIRING_TIMESTAMP = Set.of(TBucket.ENTRY.name.toLowerCase(Locale.ROOT));
62+
private static final Set<String> FUNCTIONS_REQUIRING_TIMESTAMP = Set.of(TBucket.NAME.toLowerCase(Locale.ROOT));
6363

6464
public static PreAnalysisResult resolveFieldNames(LogicalPlan parsed, EnrichResolution enrichResolution) {
6565

0 commit comments

Comments
 (0)