From 3e4f20c7bf2d2a8fe6772bc0038f44e9f312a84a Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Mon, 31 Mar 2025 14:15:36 +0200 Subject: [PATCH 1/3] Add CATEGORIZE to telemetry --- .../esql/telemetry/VerifierMetricsTests.java | 25 +++++++++++++++++++ .../rest-api-spec/test/esql/60_usage.yml | 24 ++++++++++++++---- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/telemetry/VerifierMetricsTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/telemetry/VerifierMetricsTests.java index de377fe78588c..a0db9e166d9df 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/telemetry/VerifierMetricsTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/telemetry/VerifierMetricsTests.java @@ -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); } diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml index 5c554fdac52f2..a682c4fe02920 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml @@ -21,6 +21,8 @@ setup: type: long count: type: integer + message: + type: keyword --- "Basic ESQL usage output (telemetry) snapshot version": @@ -37,7 +39,7 @@ setup: - do: {xpack.usage: {}} - match: { esql.available: true } - match: { esql.enabled: true } - - length: { esql.features: 15 } + - length: { esql.features: 16 } - set: {esql.features.dissect: dissect_counter} - set: {esql.features.drop: drop_counter} - set: {esql.features.eval: eval_counter} @@ -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 } @@ -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 @@ -109,7 +117,7 @@ setup: - do: {xpack.usage: {}} - match: { esql.available: true } - match: { esql.enabled: true } - - length: { esql.features: 15 } + - length: { esql.features: 16 } - set: {esql.features.dissect: dissect_counter} - set: {esql.features.drop: drop_counter} - set: {esql.features.eval: eval_counter} @@ -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 } @@ -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} - - length: {esql.functions: 131} # check the "sister" test above for a likely update to the same esql.functions length check + - gt: {esql.functions.categorize: $functions_categorize} + - length: {esql.functions: 134} # check the "sister" test above for a likely update to the same esql.functions length check From 1b8d20344adfd4925c48faa5670e948af6e4c73c Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Wed, 2 Apr 2025 12:03:42 +0200 Subject: [PATCH 2/3] Fix length assertion --- .../resources/rest-api-spec/test/esql/60_usage.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml index a682c4fe02920..3ce2bc7867fb1 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml @@ -39,7 +39,7 @@ setup: - do: {xpack.usage: {}} - match: { esql.available: true } - match: { esql.enabled: true } - - length: { esql.features: 16 } + - length: { esql.features: 15 } - set: {esql.features.dissect: dissect_counter} - set: {esql.features.drop: drop_counter} - set: {esql.features.eval: eval_counter} @@ -117,7 +117,7 @@ setup: - do: {xpack.usage: {}} - match: { esql.available: true } - match: { esql.enabled: true } - - length: { esql.features: 16 } + - length: { esql.features: 15 } - set: {esql.features.dissect: dissect_counter} - set: {esql.features.drop: drop_counter} - set: {esql.features.eval: eval_counter} From 7b43cab0a1213736dec22d8fb909aaf47e960bfe Mon Sep 17 00:00:00 2001 From: Przemyslaw Witek Date: Wed, 2 Apr 2025 16:00:59 +0200 Subject: [PATCH 3/3] Fix yet another length assertion --- .../yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml index 3ce2bc7867fb1..3b657f03b149f 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/60_usage.yml @@ -178,4 +178,4 @@ setup: - gt: {esql.functions.to_long: $functions_to_long} - match: {esql.functions.coalesce: $functions_coalesce} - gt: {esql.functions.categorize: $functions_categorize} - - length: {esql.functions: 134} # check the "sister" test above for a likely update to the same esql.functions length check + - length: {esql.functions: 131} # check the "sister" test above for a likely update to the same esql.functions length check