Skip to content

Commit b582db0

Browse files
committed
grouping functions are now allowed as arguments to scalar functions
1 parent 645b895 commit b582db0

2 files changed

Lines changed: 20 additions & 20 deletions

File tree

src/platform/packages/shared/kbn-esql-language/src/commands/registry/stats/autocomplete.test.ts

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ describe('STATS Autocomplete', () => {
256256
[
257257
...getFieldNamesByType([...ESQL_COMMON_NUMERIC_TYPES, 'date', 'date_nanos']),
258258
...getFunctionSignaturesByReturnType(
259-
Location.EVAL,
259+
Location.STATS_BY,
260260
['date', 'date_nanos', ...ESQL_COMMON_NUMERIC_TYPES],
261261
{
262262
scalar: true,
@@ -277,9 +277,9 @@ describe('STATS Autocomplete', () => {
277277
}),
278278
...getFieldNamesByType(roundParameterTypes),
279279
...getFunctionSignaturesByReturnType(
280-
Location.EVAL,
280+
Location.STATS_BY,
281281
roundParameterTypes,
282-
{ scalar: true },
282+
{ scalar: true, grouping: true },
283283
undefined,
284284
['round']
285285
),
@@ -294,9 +294,9 @@ describe('STATS Autocomplete', () => {
294294
}),
295295
...getFieldNamesByType(roundParameterTypes),
296296
...getFunctionSignaturesByReturnType(
297-
Location.EVAL,
297+
Location.STATS_BY,
298298
ESQL_NUMBER_TYPES,
299-
{ scalar: true },
299+
{ scalar: true, grouping: true },
300300
undefined,
301301
['round']
302302
),
@@ -308,9 +308,9 @@ describe('STATS Autocomplete', () => {
308308
[
309309
...getFieldNamesByType(roundParameterTypes),
310310
...getFunctionSignaturesByReturnType(
311-
Location.STATS,
311+
Location.STATS_BY,
312312
ESQL_NUMBER_TYPES,
313-
{ scalar: true },
313+
{ scalar: true, grouping: true },
314314
undefined,
315315
['round']
316316
),
@@ -325,8 +325,9 @@ describe('STATS Autocomplete', () => {
325325
'from a | stats avg(',
326326
[
327327
...expectedFieldsAvg,
328-
...getFunctionSignaturesByReturnType(Location.STATS, AVG_TYPES, {
328+
...getFunctionSignaturesByReturnType(Location.STATS_BY, AVG_TYPES, {
329329
scalar: true,
330+
grouping: true,
330331
}),
331332
],
332333
mockCallbacks
@@ -352,9 +353,9 @@ describe('STATS Autocomplete', () => {
352353
[
353354
...expectedFieldsAvg,
354355
...getFunctionSignaturesByReturnType(
355-
Location.EVAL,
356+
Location.STATS_BY,
356357
AVG_TYPES,
357-
{ scalar: true },
358+
{ scalar: true, grouping: true },
358359
undefined,
359360
['round']
360361
),
@@ -395,6 +396,7 @@ describe('STATS Autocomplete', () => {
395396
],
396397
{
397398
scalar: true,
399+
grouping: true,
398400
}
399401
),
400402
];
@@ -414,10 +416,11 @@ describe('STATS Autocomplete', () => {
414416
[
415417
...getFieldNamesByType(AVG_TYPES),
416418
...getFunctionSignaturesByReturnType(
417-
Location.EVAL,
419+
Location.STATS_BY,
418420
[...AVG_TYPES, 'aggregate_metric_double'],
419421
{
420422
scalar: true,
423+
grouping: true,
421424
}
422425
),
423426
],
@@ -570,11 +573,6 @@ describe('STATS Autocomplete', () => {
570573
await statsExpectSuggestions('from a | stats a=min(b) by ', expected);
571574
});
572575

573-
test('no grouping functions as args to scalar function', async () => {
574-
const suggestions = await suggest('FROM a | STATS a=MIN(b) BY ACOS(');
575-
expect(suggestions.some((s) => allGroupingFunctions.includes(s.text))).toBe(false);
576-
});
577-
578576
test('on partial column name', async () => {
579577
const expected = [
580578
...allEvalFunctionsForStats,

src/platform/packages/shared/kbn-esql-language/src/commands/registry/stats/autocomplete.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function autocomplete(
8080
let location: Location;
8181

8282
if (isInBy) {
83-
location = Location.EVAL;
83+
location = Location.STATS_BY;
8484
} else if (isTimeseriesSource && isAggFunctionUsedAlready(command, command.args.length - 1)) {
8585
location = Location.STATS_TIMESERIES;
8686
} else {
@@ -400,9 +400,11 @@ function buildCustomFilteringContext(
400400
}
401401

402402
const statsSpecificFunctionsToIgnore: string[] = [];
403-
statsSpecificFunctionsToIgnore.push(
404-
...getAllFunctions({ type: FunctionDefinitionTypes.GROUPING }).map(({ name }) => name)
405-
);
403+
if (basicContext.functionDefinition?.type === 'grouping') {
404+
statsSpecificFunctionsToIgnore.push(
405+
...getAllFunctions({ type: FunctionDefinitionTypes.GROUPING }).map(({ name }) => name)
406+
);
407+
}
406408

407409
const finalCommandArgIndex = command.args.length - 1;
408410
const isInBy = isNodeWithinByClause(foundFunction, command);

0 commit comments

Comments
 (0)