Skip to content

Commit 062d580

Browse files
authored
Verify usage of CATEGORIZE function in the ES|QL telemetry tests (#126105)
1 parent 0faa960 commit 062d580

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/telemetry/VerifierMetricsTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,31 @@ public void testKeep() {
441441
assertEquals(0, rename(c));
442442
}
443443

444+
public void testCategorize() {
445+
Counters c = esql("""
446+
from employees
447+
| keep emp_no, languages, gender
448+
| where languages is null or emp_no <= 10030
449+
| STATS COUNT() BY CATEGORIZE(gender)""");
450+
assertEquals(0, dissect(c));
451+
assertEquals(0, eval(c));
452+
assertEquals(0, grok(c));
453+
assertEquals(0, limit(c));
454+
assertEquals(0, sort(c));
455+
assertEquals(1L, stats(c));
456+
assertEquals(1L, where(c));
457+
assertEquals(0, enrich(c));
458+
assertEquals(0, mvExpand(c));
459+
assertEquals(0, show(c));
460+
assertEquals(0, row(c));
461+
assertEquals(1L, from(c));
462+
assertEquals(0, drop(c));
463+
assertEquals(1L, keep(c));
464+
assertEquals(0, rename(c));
465+
assertEquals(1, function("count", c));
466+
assertEquals(1, function("categorize", c));
467+
}
468+
444469
private long dissect(Counters c) {
445470
return c.get(FPREFIX + DISSECT);
446471
}

x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ setup:
2121
type: long
2222
count:
2323
type: integer
24+
message:
25+
type: keyword
2426

2527
---
2628
"Basic ESQL usage output (telemetry) snapshot version":
@@ -65,11 +67,16 @@ setup:
6567
- set: {esql.functions.cos: functions_cos}
6668
- set: {esql.functions.to_long: functions_to_long}
6769
- set: {esql.functions.coalesce: functions_coalesce}
70+
- set: {esql.functions.categorize: functions_categorize}
6871

6972
- do:
7073
esql.query:
7174
body:
72-
query: 'from test | where data > 2 and to_long(data) > 2 | sort count desc | limit 5 | stats m = max(data)'
75+
query: 'from test
76+
| where data > 2 and to_long(data) > 2
77+
| sort count desc
78+
| limit 5
79+
| stats m = max(data) by categorize(message)'
7380

7481
- do: {xpack.usage: {}}
7582
- match: { esql.available: true }
@@ -92,6 +99,7 @@ setup:
9299
- match: {esql.functions.cos: $functions_cos}
93100
- gt: {esql.functions.to_long: $functions_to_long}
94101
- match: {esql.functions.coalesce: $functions_coalesce}
102+
- gt: {esql.functions.categorize: $functions_categorize}
95103
# Testing for the entire function set isn't feasbile, so we just check that we return the correct count as an approximation.
96104
- length: {esql.functions: 134} # check the "sister" test below for a likely update to the same esql.functions length check
97105

@@ -137,11 +145,16 @@ setup:
137145
- set: {esql.functions.cos: functions_cos}
138146
- set: {esql.functions.to_long: functions_to_long}
139147
- set: {esql.functions.coalesce: functions_coalesce}
148+
- set: {esql.functions.categorize: functions_categorize}
140149

141150
- do:
142151
esql.query:
143152
body:
144-
query: 'from test | where data > 2 and to_long(data) > 2 | sort count desc | limit 5 | stats m = max(data)'
153+
query: 'from test
154+
| where data > 2 and to_long(data) > 2
155+
| sort count desc
156+
| limit 5
157+
| stats m = max(data) by categorize(message)'
145158

146159
- do: {xpack.usage: {}}
147160
- match: { esql.available: true }
@@ -164,4 +177,5 @@ setup:
164177
- match: {esql.functions.cos: $functions_cos}
165178
- gt: {esql.functions.to_long: $functions_to_long}
166179
- match: {esql.functions.coalesce: $functions_coalesce}
180+
- gt: {esql.functions.categorize: $functions_categorize}
167181
- length: {esql.functions: 131} # check the "sister" test above for a likely update to the same esql.functions length check

0 commit comments

Comments
 (0)