Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,31 @@ public void testKeep() {
assertEquals(0, rename(c));
}

public void testCategorize() {
Counters c = esql("""
from employees
| keep emp_no, languages, gender
| where languages is null or emp_no <= 10030
| STATS COUNT() BY CATEGORIZE(gender)""");
assertEquals(0, dissect(c));
assertEquals(0, eval(c));
assertEquals(0, grok(c));
assertEquals(0, limit(c));
assertEquals(0, sort(c));
assertEquals(1L, stats(c));
assertEquals(1L, where(c));
assertEquals(0, enrich(c));
assertEquals(0, mvExpand(c));
assertEquals(0, show(c));
assertEquals(0, row(c));
assertEquals(1L, from(c));
assertEquals(0, drop(c));
assertEquals(1L, keep(c));
assertEquals(0, rename(c));
assertEquals(1, function("count", c));
assertEquals(1, function("categorize", c));
}

private long dissect(Counters c) {
return c.get(FPREFIX + DISSECT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ setup:
type: long
count:
type: integer
message:
type: keyword

---
"Basic ESQL usage output (telemetry) snapshot version":
Expand Down Expand Up @@ -65,11 +67,16 @@ setup:
- set: {esql.functions.cos: functions_cos}
- set: {esql.functions.to_long: functions_to_long}
- set: {esql.functions.coalesce: functions_coalesce}
- set: {esql.functions.categorize: functions_categorize}

- do:
esql.query:
body:
query: 'from test | where data > 2 and to_long(data) > 2 | sort count desc | limit 5 | stats m = max(data)'
query: 'from test
| where data > 2 and to_long(data) > 2
| sort count desc
| limit 5
| stats m = max(data) by categorize(message)'

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

Expand Down Expand Up @@ -137,11 +145,16 @@ setup:
- set: {esql.functions.cos: functions_cos}
- set: {esql.functions.to_long: functions_to_long}
- set: {esql.functions.coalesce: functions_coalesce}
- set: {esql.functions.categorize: functions_categorize}

- do:
esql.query:
body:
query: 'from test | where data > 2 and to_long(data) > 2 | sort count desc | limit 5 | stats m = max(data)'
query: 'from test
| where data > 2 and to_long(data) > 2
| sort count desc
| limit 5
| stats m = max(data) by categorize(message)'

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