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 @@ -181,10 +181,15 @@ export function checkFunctionContent(arg: ESQLFunction) {
if (isAggregation(arg) || isFunctionOperatorParam(arg)) {
return true;
}
return (arg as ESQLFunction).args.every(
(subArg): boolean =>
return (arg as ESQLFunction).args.every((subArg): boolean => {
// Differentiate between array and non-array arguments
if (Array.isArray(subArg)) {
return subArg.every((item) => checkFunctionContent(item as ESQLFunction));
}
return (
isLiteral(subArg) ||
isAggregation(subArg) ||
(isNotAnAggregation(subArg) ? checkFunctionContent(subArg) : false)
);
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ describe('STATS Validation', () => {
statsExpectErrors('from a_index | STATS abs( doubleField + sum( doubleField )) ', [
'Cannot combine aggregation and non-aggregation values in [STATS], found [abs(doubleField+sum(doubleField))]',
]);
// This is a valid expression as it is an operation on two aggregation functions
statsExpectErrors(
'from a_index | STATS sum(doubleField) / (min(doubleField) + max(doubleField)) ',
[]
);
});

test('errors on each aggregation field, which does not contain at least one agg function', () => {
Expand Down