[ES|QL] Supports boolean in max min aggs (#188199)

## Summary

Closes https://github.com/elastic/kibana/issues/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
This commit is contained in:
Stratoula Kalafateli 2024-07-15 11:27:41 -07:00 committed by GitHub
parent 58c82e8f81
commit b3dcc542fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 185 additions and 18 deletions

View file

@ -708,8 +708,8 @@ describe('autocomplete', () => {
testSuggestions(
'from a | stats a=min()',
[
...getFieldNamesByType(['number', 'date']),
...getFunctionSignaturesByReturnType('stats', ['number', 'date'], {
...getFieldNamesByType(['number', 'date', 'boolean']),
...getFunctionSignaturesByReturnType('stats', ['number', 'date', 'boolean'], {
evalMath: true,
}),
],
@ -731,8 +731,8 @@ describe('autocomplete', () => {
testSuggestions(
'from a | stats a=min(b), b=max()',
[
...getFieldNamesByType(['number', 'date']),
...getFunctionSignaturesByReturnType('stats', ['number', 'date'], {
...getFieldNamesByType(['number', 'date', 'boolean']),
...getFunctionSignaturesByReturnType('stats', ['number', 'date', 'boolean'], {
evalMath: true,
}),
],

View file

@ -108,6 +108,10 @@ export const statsAggregationFunctionDefinitions: FunctionDefinition[] = [
params: [{ name: 'column', type: 'date', noNestingFunctions: true }],
returnType: 'number',
},
{
params: [{ name: 'column', type: 'boolean', noNestingFunctions: true }],
returnType: 'boolean',
},
],
examples: [`from index | stats result = max(field)`, `from index | stats max(field)`],
},
@ -127,6 +131,10 @@ export const statsAggregationFunctionDefinitions: FunctionDefinition[] = [
params: [{ name: 'column', type: 'date', noNestingFunctions: true }],
returnType: 'number',
},
{
params: [{ name: 'column', type: 'boolean', noNestingFunctions: true }],
returnType: 'boolean',
},
],
examples: [`from index | stats result = min(field)`, `from index | stats min(field)`],
},

View file

@ -24122,9 +24122,7 @@
},
{
"query": "from a_index | stats max(booleanField)",
"error": [
"Argument of [max] must be [number], found value [booleanField] type [boolean]"
],
"error": [],
"warning": []
},
{
@ -24149,6 +24147,60 @@
],
"warning": []
},
{
"query": "from a_index | stats max(cartesianPointField)",
"error": [
"Argument of [max] must be [number], found value [cartesianPointField] type [cartesian_point]"
],
"warning": []
},
{
"query": "from a_index | stats var = max(booleanField)",
"error": [],
"warning": []
},
{
"query": "from a_index | where max(booleanField)",
"error": [
"WHERE does not support function max"
],
"warning": []
},
{
"query": "from a_index | where max(booleanField) > 0",
"error": [
"WHERE does not support function max"
],
"warning": []
},
{
"query": "from a_index | eval var = max(booleanField)",
"error": [
"EVAL does not support function max"
],
"warning": []
},
{
"query": "from a_index | eval var = max(booleanField) > 0",
"error": [
"EVAL does not support function max"
],
"warning": []
},
{
"query": "from a_index | eval max(booleanField)",
"error": [
"EVAL does not support function max"
],
"warning": []
},
{
"query": "from a_index | eval max(booleanField) > 0",
"error": [
"EVAL does not support function max"
],
"warning": []
},
{
"query": "from a_index | stats var = min(numberField)",
"error": [],
@ -24395,9 +24447,7 @@
},
{
"query": "from a_index | stats min(booleanField)",
"error": [
"Argument of [min] must be [number], found value [booleanField] type [boolean]"
],
"error": [],
"warning": []
},
{
@ -24422,6 +24472,60 @@
],
"warning": []
},
{
"query": "from a_index | stats min(cartesianPointField)",
"error": [
"Argument of [min] must be [number], found value [cartesianPointField] type [cartesian_point]"
],
"warning": []
},
{
"query": "from a_index | stats var = min(booleanField)",
"error": [],
"warning": []
},
{
"query": "from a_index | where min(booleanField)",
"error": [
"WHERE does not support function min"
],
"warning": []
},
{
"query": "from a_index | where min(booleanField) > 0",
"error": [
"WHERE does not support function min"
],
"warning": []
},
{
"query": "from a_index | eval var = min(booleanField)",
"error": [
"EVAL does not support function min"
],
"warning": []
},
{
"query": "from a_index | eval var = min(booleanField) > 0",
"error": [
"EVAL does not support function min"
],
"warning": []
},
{
"query": "from a_index | eval min(booleanField)",
"error": [
"EVAL does not support function min"
],
"warning": []
},
{
"query": "from a_index | eval min(booleanField) > 0",
"error": [
"EVAL does not support function min"
],
"warning": []
},
{
"query": "from a_index | stats var = count(stringField)",
"error": [],

View file

@ -9165,15 +9165,43 @@ describe('validation logic', () => {
'EVAL does not support function max',
]);
testErrorsAndWarnings('from a_index | stats max(booleanField)', [
'Argument of [max] must be [number], found value [booleanField] type [boolean]',
]);
testErrorsAndWarnings('from a_index | stats max(booleanField)', []);
testErrorsAndWarnings('from a_index | stats max(null)', []);
testErrorsAndWarnings('row nullVar = null | stats max(nullVar)', []);
testErrorsAndWarnings('from a_index | stats max("2022")', []);
testErrorsAndWarnings('from a_index | stats max(concat("20", "22"))', [
'Argument of [max] must be [number], found value [concat("20", "22")] type [string]',
]);
testErrorsAndWarnings('from a_index | stats max(cartesianPointField)', [
'Argument of [max] must be [number], found value [cartesianPointField] type [cartesian_point]',
]);
testErrorsAndWarnings('from a_index | stats var = max(booleanField)', []);
testErrorsAndWarnings('from a_index | where max(booleanField)', [
'WHERE does not support function max',
]);
testErrorsAndWarnings('from a_index | where max(booleanField) > 0', [
'WHERE does not support function max',
]);
testErrorsAndWarnings('from a_index | eval var = max(booleanField)', [
'EVAL does not support function max',
]);
testErrorsAndWarnings('from a_index | eval var = max(booleanField) > 0', [
'EVAL does not support function max',
]);
testErrorsAndWarnings('from a_index | eval max(booleanField)', [
'EVAL does not support function max',
]);
testErrorsAndWarnings('from a_index | eval max(booleanField) > 0', [
'EVAL does not support function max',
]);
});
describe('min', () => {
@ -9309,15 +9337,43 @@ describe('validation logic', () => {
'EVAL does not support function min',
]);
testErrorsAndWarnings('from a_index | stats min(booleanField)', [
'Argument of [min] must be [number], found value [booleanField] type [boolean]',
]);
testErrorsAndWarnings('from a_index | stats min(booleanField)', []);
testErrorsAndWarnings('from a_index | stats min(null)', []);
testErrorsAndWarnings('row nullVar = null | stats min(nullVar)', []);
testErrorsAndWarnings('from a_index | stats min("2022")', []);
testErrorsAndWarnings('from a_index | stats min(concat("20", "22"))', [
'Argument of [min] must be [number], found value [concat("20", "22")] type [string]',
]);
testErrorsAndWarnings('from a_index | stats min(cartesianPointField)', [
'Argument of [min] must be [number], found value [cartesianPointField] type [cartesian_point]',
]);
testErrorsAndWarnings('from a_index | stats var = min(booleanField)', []);
testErrorsAndWarnings('from a_index | where min(booleanField)', [
'WHERE does not support function min',
]);
testErrorsAndWarnings('from a_index | where min(booleanField) > 0', [
'WHERE does not support function min',
]);
testErrorsAndWarnings('from a_index | eval var = min(booleanField)', [
'EVAL does not support function min',
]);
testErrorsAndWarnings('from a_index | eval var = min(booleanField) > 0', [
'EVAL does not support function min',
]);
testErrorsAndWarnings('from a_index | eval min(booleanField)', [
'EVAL does not support function min',
]);
testErrorsAndWarnings('from a_index | eval min(booleanField) > 0', [
'EVAL does not support function min',
]);
});
describe('count', () => {

View file

@ -237,8 +237,7 @@ export default function ({ getService }: FtrProviderContext) {
await cleanup();
});
// FAILING ES PROMOTION: https://github.com/elastic/kibana/issues/188109
it.skip(`Checking error messages`, async () => {
it(`Checking error messages`, async () => {
for (const { query, error } of queryToErrors) {
const jsonBody = await sendESQLQuery(query);