Skip to content
Merged
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 @@ -30,6 +30,7 @@ import type {
ESQLBinaryExpression,
ESQLUnaryExpression,
ESQLPostfixUnaryExpression,
ESQLProperNode,
} from '@kbn/esql-language/src/types';
import type { DataView } from '@kbn/data-views-plugin/public';
import type { ESQLControlVariable } from '@kbn/esql-types';
Expand All @@ -54,6 +55,22 @@ import {
isCategorizeFunctionWithFunctionArgument,
} from './utils';

const hasUnsupportedGroupingFunction = (definition: ESQLProperNode): boolean => {
const funcExpr = isFunctionExpression(definition)
? definition
: isInlineCast(definition) && isFunctionExpression(definition.value)
? definition.value
: null;

if (!funcExpr) {
return false;
}

return (
!isSupportedStatsFunction(funcExpr.name) || isCategorizeFunctionWithFunctionArgument(funcExpr)
);
};

type NodeType = 'group' | 'leaf';

export interface AppliedStatsFunction {
Expand Down Expand Up @@ -143,14 +160,7 @@ export const getESQLStatsQueryMeta = (queryString: string): ESQLStatsQueryMeta =

const groupFieldDefinition = getFieldDefinitionFromArg(groupFieldNode.arg);

if (
(isFunctionExpression(groupFieldDefinition) &&
(!isSupportedStatsFunction(groupFieldDefinition.name) ||
isCategorizeFunctionWithFunctionArgument(groupFieldDefinition))) ||
(isInlineCast(groupFieldDefinition) &&
isFunctionExpression(groupFieldDefinition.value) &&
!isSupportedStatsFunction(groupFieldDefinition.value.name))
) {
if (hasUnsupportedGroupingFunction(groupFieldDefinition)) {
// if the group field has a grouping function that is not supported,
// this nullifies the entire query to count as a valid query for the cascade experience
groupByFields.splice(0, groupByFields.length);
Expand Down
Loading