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 @@ -331,7 +331,7 @@ describe('FORK Autocomplete', () => {
...getFunctionSignaturesByReturnType(
Location.STATS,
[...AVG_TYPES, 'aggregate_metric_double'],
{ scalar: true }
{ scalar: true, grouping: true }
),
],
mockCallbacks
Expand All @@ -345,6 +345,7 @@ describe('FORK Autocomplete', () => {
[...AVG_TYPES, 'unsigned_long'],
{
scalar: true,
grouping: true,
},
undefined,
['acos']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ describe('STATS Autocomplete', () => {
[
...getFieldNamesByType([...ESQL_COMMON_NUMERIC_TYPES, 'date', 'date_nanos']),
...getFunctionSignaturesByReturnType(
Location.EVAL,
Location.STATS_BY,
['date', 'date_nanos', ...ESQL_COMMON_NUMERIC_TYPES],
{
scalar: true,
Expand All @@ -277,9 +277,9 @@ describe('STATS Autocomplete', () => {
}),
...getFieldNamesByType(roundParameterTypes),
...getFunctionSignaturesByReturnType(
Location.EVAL,
Location.STATS_BY,
roundParameterTypes,
{ scalar: true },
{ scalar: true, grouping: true },
undefined,
['round']
),
Expand All @@ -294,9 +294,9 @@ describe('STATS Autocomplete', () => {
}),
...getFieldNamesByType(roundParameterTypes),
...getFunctionSignaturesByReturnType(
Location.EVAL,
Location.STATS_BY,
ESQL_NUMBER_TYPES,
{ scalar: true },
{ scalar: true, grouping: true },
undefined,
['round']
),
Expand All @@ -308,9 +308,9 @@ describe('STATS Autocomplete', () => {
[
...getFieldNamesByType(roundParameterTypes),
...getFunctionSignaturesByReturnType(
Location.STATS,
Location.STATS_BY,
ESQL_NUMBER_TYPES,
{ scalar: true },
{ scalar: true, grouping: true },
undefined,
['round']
),
Expand All @@ -325,8 +325,9 @@ describe('STATS Autocomplete', () => {
'from a | stats avg(',
[
...expectedFieldsAvg,
...getFunctionSignaturesByReturnType(Location.STATS, AVG_TYPES, {
...getFunctionSignaturesByReturnType(Location.STATS_BY, AVG_TYPES, {
scalar: true,
grouping: true,
}),
],
mockCallbacks
Expand All @@ -352,9 +353,9 @@ describe('STATS Autocomplete', () => {
[
...expectedFieldsAvg,
...getFunctionSignaturesByReturnType(
Location.EVAL,
Location.STATS_BY,
AVG_TYPES,
{ scalar: true },
{ scalar: true, grouping: true },
undefined,
['round']
),
Expand Down Expand Up @@ -395,6 +396,7 @@ describe('STATS Autocomplete', () => {
],
{
scalar: true,
grouping: true,
}
),
];
Expand All @@ -414,10 +416,11 @@ describe('STATS Autocomplete', () => {
[
...getFieldNamesByType(AVG_TYPES),
...getFunctionSignaturesByReturnType(
Location.EVAL,
Location.STATS_BY,
[...AVG_TYPES, 'aggregate_metric_double'],
{
scalar: true,
grouping: true,
}
),
],
Expand Down Expand Up @@ -570,11 +573,6 @@ describe('STATS Autocomplete', () => {
await statsExpectSuggestions('from a | stats a=min(b) by ', expected);
});

test('no grouping functions as args to scalar function', async () => {
const suggestions = await suggest('FROM a | STATS a=MIN(b) BY ACOS(');
expect(suggestions.some((s) => allGroupingFunctions.includes(s.text))).toBe(false);
});

test('on partial column name', async () => {
const expected = [
...allEvalFunctionsForStats,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function autocomplete(
let location: Location;

if (isInBy) {
location = Location.EVAL;
location = Location.STATS_BY;
} else if (isTimeseriesSource && isAggFunctionUsedAlready(command, command.args.length - 1)) {
location = Location.STATS_TIMESERIES;
} else {
Expand Down Expand Up @@ -400,9 +400,11 @@ function buildCustomFilteringContext(
}

const statsSpecificFunctionsToIgnore: string[] = [];
statsSpecificFunctionsToIgnore.push(
...getAllFunctions({ type: FunctionDefinitionTypes.GROUPING }).map(({ name }) => name)
);
if (basicContext.functionDefinition?.type === 'grouping') {
statsSpecificFunctionsToIgnore.push(
...getAllFunctions({ type: FunctionDefinitionTypes.GROUPING }).map(({ name }) => name)
);
}

const finalCommandArgIndex = command.args.length - 1;
const isInBy = isNodeWithinByClause(foundFunction, command);
Expand Down
Loading