Skip to content

Commit

Permalink
[ES|QL] Supports boolean in max min aggs (#188199)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
stratoula committed Jul 15, 2024
1 parent 58c82e8 commit b3dcc54
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
],
Expand All @@ -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,
}),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)`],
},
Expand All @@ -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)`],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
},
{
Expand All @@ -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": [],
Expand Down Expand Up @@ -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": []
},
{
Expand All @@ -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": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
3 changes: 1 addition & 2 deletions test/api_integration/apis/esql/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b3dcc54

Please sign in to comment.