Skip to content

Commit b3dcc54

Browse files
authored
[ES|QL] Supports boolean in max min aggs (#188199)
## Summary Closes #188109 (we now allow max and min in boolean fields) ### Checklist - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
1 parent 58c82e8 commit b3dcc54

5 files changed

Lines changed: 185 additions & 18 deletions

File tree

packages/kbn-esql-validation-autocomplete/src/autocomplete/autocomplete.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,8 @@ describe('autocomplete', () => {
708708
testSuggestions(
709709
'from a | stats a=min()',
710710
[
711-
...getFieldNamesByType(['number', 'date']),
712-
...getFunctionSignaturesByReturnType('stats', ['number', 'date'], {
711+
...getFieldNamesByType(['number', 'date', 'boolean']),
712+
...getFunctionSignaturesByReturnType('stats', ['number', 'date', 'boolean'], {
713713
evalMath: true,
714714
}),
715715
],
@@ -731,8 +731,8 @@ describe('autocomplete', () => {
731731
testSuggestions(
732732
'from a | stats a=min(b), b=max()',
733733
[
734-
...getFieldNamesByType(['number', 'date']),
735-
...getFunctionSignaturesByReturnType('stats', ['number', 'date'], {
734+
...getFieldNamesByType(['number', 'date', 'boolean']),
735+
...getFunctionSignaturesByReturnType('stats', ['number', 'date', 'boolean'], {
736736
evalMath: true,
737737
}),
738738
],

packages/kbn-esql-validation-autocomplete/src/definitions/aggs.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ export const statsAggregationFunctionDefinitions: FunctionDefinition[] = [
108108
params: [{ name: 'column', type: 'date', noNestingFunctions: true }],
109109
returnType: 'number',
110110
},
111+
{
112+
params: [{ name: 'column', type: 'boolean', noNestingFunctions: true }],
113+
returnType: 'boolean',
114+
},
111115
],
112116
examples: [`from index | stats result = max(field)`, `from index | stats max(field)`],
113117
},
@@ -127,6 +131,10 @@ export const statsAggregationFunctionDefinitions: FunctionDefinition[] = [
127131
params: [{ name: 'column', type: 'date', noNestingFunctions: true }],
128132
returnType: 'number',
129133
},
134+
{
135+
params: [{ name: 'column', type: 'boolean', noNestingFunctions: true }],
136+
returnType: 'boolean',
137+
},
130138
],
131139
examples: [`from index | stats result = min(field)`, `from index | stats min(field)`],
132140
},

packages/kbn-esql-validation-autocomplete/src/validation/esql_validation_meta_tests.json

Lines changed: 110 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24122,9 +24122,7 @@
2412224122
},
2412324123
{
2412424124
"query": "from a_index | stats max(booleanField)",
24125-
"error": [
24126-
"Argument of [max] must be [number], found value [booleanField] type [boolean]"
24127-
],
24125+
"error": [],
2412824126
"warning": []
2412924127
},
2413024128
{
@@ -24149,6 +24147,60 @@
2414924147
],
2415024148
"warning": []
2415124149
},
24150+
{
24151+
"query": "from a_index | stats max(cartesianPointField)",
24152+
"error": [
24153+
"Argument of [max] must be [number], found value [cartesianPointField] type [cartesian_point]"
24154+
],
24155+
"warning": []
24156+
},
24157+
{
24158+
"query": "from a_index | stats var = max(booleanField)",
24159+
"error": [],
24160+
"warning": []
24161+
},
24162+
{
24163+
"query": "from a_index | where max(booleanField)",
24164+
"error": [
24165+
"WHERE does not support function max"
24166+
],
24167+
"warning": []
24168+
},
24169+
{
24170+
"query": "from a_index | where max(booleanField) > 0",
24171+
"error": [
24172+
"WHERE does not support function max"
24173+
],
24174+
"warning": []
24175+
},
24176+
{
24177+
"query": "from a_index | eval var = max(booleanField)",
24178+
"error": [
24179+
"EVAL does not support function max"
24180+
],
24181+
"warning": []
24182+
},
24183+
{
24184+
"query": "from a_index | eval var = max(booleanField) > 0",
24185+
"error": [
24186+
"EVAL does not support function max"
24187+
],
24188+
"warning": []
24189+
},
24190+
{
24191+
"query": "from a_index | eval max(booleanField)",
24192+
"error": [
24193+
"EVAL does not support function max"
24194+
],
24195+
"warning": []
24196+
},
24197+
{
24198+
"query": "from a_index | eval max(booleanField) > 0",
24199+
"error": [
24200+
"EVAL does not support function max"
24201+
],
24202+
"warning": []
24203+
},
2415224204
{
2415324205
"query": "from a_index | stats var = min(numberField)",
2415424206
"error": [],
@@ -24395,9 +24447,7 @@
2439524447
},
2439624448
{
2439724449
"query": "from a_index | stats min(booleanField)",
24398-
"error": [
24399-
"Argument of [min] must be [number], found value [booleanField] type [boolean]"
24400-
],
24450+
"error": [],
2440124451
"warning": []
2440224452
},
2440324453
{
@@ -24422,6 +24472,60 @@
2442224472
],
2442324473
"warning": []
2442424474
},
24475+
{
24476+
"query": "from a_index | stats min(cartesianPointField)",
24477+
"error": [
24478+
"Argument of [min] must be [number], found value [cartesianPointField] type [cartesian_point]"
24479+
],
24480+
"warning": []
24481+
},
24482+
{
24483+
"query": "from a_index | stats var = min(booleanField)",
24484+
"error": [],
24485+
"warning": []
24486+
},
24487+
{
24488+
"query": "from a_index | where min(booleanField)",
24489+
"error": [
24490+
"WHERE does not support function min"
24491+
],
24492+
"warning": []
24493+
},
24494+
{
24495+
"query": "from a_index | where min(booleanField) > 0",
24496+
"error": [
24497+
"WHERE does not support function min"
24498+
],
24499+
"warning": []
24500+
},
24501+
{
24502+
"query": "from a_index | eval var = min(booleanField)",
24503+
"error": [
24504+
"EVAL does not support function min"
24505+
],
24506+
"warning": []
24507+
},
24508+
{
24509+
"query": "from a_index | eval var = min(booleanField) > 0",
24510+
"error": [
24511+
"EVAL does not support function min"
24512+
],
24513+
"warning": []
24514+
},
24515+
{
24516+
"query": "from a_index | eval min(booleanField)",
24517+
"error": [
24518+
"EVAL does not support function min"
24519+
],
24520+
"warning": []
24521+
},
24522+
{
24523+
"query": "from a_index | eval min(booleanField) > 0",
24524+
"error": [
24525+
"EVAL does not support function min"
24526+
],
24527+
"warning": []
24528+
},
2442524529
{
2442624530
"query": "from a_index | stats var = count(stringField)",
2442724531
"error": [],

packages/kbn-esql-validation-autocomplete/src/validation/validation.test.ts

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9165,15 +9165,43 @@ describe('validation logic', () => {
91659165
'EVAL does not support function max',
91669166
]);
91679167

9168-
testErrorsAndWarnings('from a_index | stats max(booleanField)', [
9169-
'Argument of [max] must be [number], found value [booleanField] type [boolean]',
9170-
]);
9168+
testErrorsAndWarnings('from a_index | stats max(booleanField)', []);
91719169
testErrorsAndWarnings('from a_index | stats max(null)', []);
91729170
testErrorsAndWarnings('row nullVar = null | stats max(nullVar)', []);
91739171
testErrorsAndWarnings('from a_index | stats max("2022")', []);
91749172
testErrorsAndWarnings('from a_index | stats max(concat("20", "22"))', [
91759173
'Argument of [max] must be [number], found value [concat("20", "22")] type [string]',
91769174
]);
9175+
9176+
testErrorsAndWarnings('from a_index | stats max(cartesianPointField)', [
9177+
'Argument of [max] must be [number], found value [cartesianPointField] type [cartesian_point]',
9178+
]);
9179+
9180+
testErrorsAndWarnings('from a_index | stats var = max(booleanField)', []);
9181+
9182+
testErrorsAndWarnings('from a_index | where max(booleanField)', [
9183+
'WHERE does not support function max',
9184+
]);
9185+
9186+
testErrorsAndWarnings('from a_index | where max(booleanField) > 0', [
9187+
'WHERE does not support function max',
9188+
]);
9189+
9190+
testErrorsAndWarnings('from a_index | eval var = max(booleanField)', [
9191+
'EVAL does not support function max',
9192+
]);
9193+
9194+
testErrorsAndWarnings('from a_index | eval var = max(booleanField) > 0', [
9195+
'EVAL does not support function max',
9196+
]);
9197+
9198+
testErrorsAndWarnings('from a_index | eval max(booleanField)', [
9199+
'EVAL does not support function max',
9200+
]);
9201+
9202+
testErrorsAndWarnings('from a_index | eval max(booleanField) > 0', [
9203+
'EVAL does not support function max',
9204+
]);
91779205
});
91789206

91799207
describe('min', () => {
@@ -9309,15 +9337,43 @@ describe('validation logic', () => {
93099337
'EVAL does not support function min',
93109338
]);
93119339

9312-
testErrorsAndWarnings('from a_index | stats min(booleanField)', [
9313-
'Argument of [min] must be [number], found value [booleanField] type [boolean]',
9314-
]);
9340+
testErrorsAndWarnings('from a_index | stats min(booleanField)', []);
93159341
testErrorsAndWarnings('from a_index | stats min(null)', []);
93169342
testErrorsAndWarnings('row nullVar = null | stats min(nullVar)', []);
93179343
testErrorsAndWarnings('from a_index | stats min("2022")', []);
93189344
testErrorsAndWarnings('from a_index | stats min(concat("20", "22"))', [
93199345
'Argument of [min] must be [number], found value [concat("20", "22")] type [string]',
93209346
]);
9347+
9348+
testErrorsAndWarnings('from a_index | stats min(cartesianPointField)', [
9349+
'Argument of [min] must be [number], found value [cartesianPointField] type [cartesian_point]',
9350+
]);
9351+
9352+
testErrorsAndWarnings('from a_index | stats var = min(booleanField)', []);
9353+
9354+
testErrorsAndWarnings('from a_index | where min(booleanField)', [
9355+
'WHERE does not support function min',
9356+
]);
9357+
9358+
testErrorsAndWarnings('from a_index | where min(booleanField) > 0', [
9359+
'WHERE does not support function min',
9360+
]);
9361+
9362+
testErrorsAndWarnings('from a_index | eval var = min(booleanField)', [
9363+
'EVAL does not support function min',
9364+
]);
9365+
9366+
testErrorsAndWarnings('from a_index | eval var = min(booleanField) > 0', [
9367+
'EVAL does not support function min',
9368+
]);
9369+
9370+
testErrorsAndWarnings('from a_index | eval min(booleanField)', [
9371+
'EVAL does not support function min',
9372+
]);
9373+
9374+
testErrorsAndWarnings('from a_index | eval min(booleanField) > 0', [
9375+
'EVAL does not support function min',
9376+
]);
93219377
});
93229378

93239379
describe('count', () => {

test/api_integration/apis/esql/errors.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,8 +237,7 @@ export default function ({ getService }: FtrProviderContext) {
237237
await cleanup();
238238
});
239239

240-
// FAILING ES PROMOTION: https://github.com/elastic/kibana/issues/188109
241-
it.skip(`Checking error messages`, async () => {
240+
it(`Checking error messages`, async () => {
242241
for (const { query, error } of queryToErrors) {
243242
const jsonBody = await sendESQLQuery(query);
244243

0 commit comments

Comments
 (0)