Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
0e937a9
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 6, 2025
7ffbf4c
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 10, 2025
b426318
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 13, 2025
511ccaa
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 14, 2025
2d71300
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 18, 2025
0076de9
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 21, 2025
2898ce1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Feb 24, 2025
ace0009
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 3, 2025
6cdd8c1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 4, 2025
98616e9
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 6, 2025
64e40fd
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 7, 2025
1e3f8d1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 11, 2025
afd5630
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 13, 2025
31c6cb3
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 18, 2025
08f4b1b
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 18, 2025
0c11f55
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 20, 2025
de2bc7a
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 21, 2025
828d142
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Mar 25, 2025
34bd1ef
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 1, 2025
f0070c6
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 3, 2025
16a27c7
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 3, 2025
cde697e
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 8, 2025
8b66178
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 10, 2025
3555b0c
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 14, 2025
57a5f4a
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 16, 2025
420eb2b
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Apr 29, 2025
8e5e4a8
Merge branch 'main' of github.com:elastic/kibana
drewdaemon May 5, 2025
141765f
Merge branch 'main' of github.com:elastic/kibana
drewdaemon May 21, 2025
cdf4d20
Merge branch 'main' of github.com:elastic/kibana
drewdaemon May 23, 2025
d177eb1
Merge branch 'main' of github.com:elastic/kibana
drewdaemon May 28, 2025
4fd1791
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Jun 4, 2025
aa1c776
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Jun 5, 2025
5fe324c
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Jun 9, 2025
6dfd40a
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Jul 15, 2025
5b804dc
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Jul 17, 2025
072394a
Merge branch 'main' of github.com:elastic/kibana
drewdaemon Jul 23, 2025
be5404b
kinda sorta workin
drewdaemon Jul 24, 2025
0ec8541
kinda sorta workin after assignment
drewdaemon Jul 24, 2025
d9c58d3
kinda sorta workin for agg statements
drewdaemon Jul 25, 2025
dd4b095
dedupe a bit
drewdaemon Jul 25, 2025
aeac452
fix position calculation, exclude new col suggestion
drewdaemon Jul 25, 2025
c0b3b06
some clean up
drewdaemon Jul 25, 2025
29d26b2
reenable function arg suggestions
drewdaemon Jul 28, 2025
5377034
reinstate controls suggestions
drewdaemon Jul 28, 2025
47d0cc5
enable suggestions right after grouping column
drewdaemon Jul 28, 2025
8c6e3a9
ignored columns
drewdaemon Jul 28, 2025
ed027e4
fix suggestions after WHERE
drewdaemon Jul 28, 2025
929324d
Merge branch 'main' of github.com:elastic/kibana into 216492/support-…
drewdaemon Jul 29, 2025
8b0d1ff
fix suggestions after assignment and comma
drewdaemon Jul 30, 2025
dbace66
pass correct location for grouping clauses
drewdaemon Jul 30, 2025
cf3ec98
handle the right-after-column-name case
drewdaemon Jul 30, 2025
b7a24e0
respect the offset, man
drewdaemon Jul 30, 2025
ce45629
add a few more tests
drewdaemon Jul 30, 2025
0badaf1
Update marker_node_removal.test.ts
drewdaemon Jul 30, 2025
0cfd903
Merge branch '216492/support-expressions-in-stats' of github.com:drew…
drewdaemon Jul 30, 2025
6dfdbfd
fix import
drewdaemon Jul 30, 2025
40d8e85
fix around not keyword
drewdaemon Jul 30, 2025
058f1f9
fix right-after-column behavior in case of assignment
drewdaemon Jul 31, 2025
b5fd981
add test case
drewdaemon Jul 31, 2025
9c6f87d
Include empty state suggestions if root is partial column
drewdaemon Jul 31, 2025
62d9f84
fix invalid test
drewdaemon Jul 31, 2025
0be1508
Merge branch 'main' into 216492/support-expressions-in-stats
stratoula Aug 1, 2025
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 @@ -57,7 +57,8 @@ export const suggest = (
) => Promise<ISuggestionItem[]>,
offset?: number
): Promise<ISuggestionItem[]> => {
const correctedQuery = correctQuerySyntax(query);
const innerText = query.substring(0, offset ?? query.length);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This step that is executed in the real autocomplete routine was missed here, causing one of my tests to fail.

const correctedQuery = correctQuerySyntax(innerText);
const { ast } = parse(correctedQuery, { withFormatting: true });
const cursorPosition = offset ?? query.length;
const { command } = findAstPosition(ast, cursorPosition);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function autocomplete(
expressionRoot: undefined,
location: Location.SORT,
context,
advanceCursorAfterInitialField: false,
advanceCursorAfterInitialColumn: false,
hasMinimumLicenseRequired: callbacks?.hasMinimumLicenseRequired,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ describe('STATS Autocomplete', () => {
return autocomplete(query, command, mockCallbacks, mockContext, cursorPosition);
};
describe('STATS ...', () => {
afterEach(() => setTestFunctions([]));

describe('... <aggregates> ...', () => {
test('suggestions for a fresh expression', async () => {
const expected = EXPECTED_FOR_EMPTY_EXPRESSION;
Expand All @@ -138,7 +140,44 @@ describe('STATS Autocomplete', () => {
});

test('on space after aggregate field', async () => {
await statsExpectSuggestions('from a | stats a=min(b) ', ['WHERE ', 'BY ', ', ', '| ']);
await statsExpectSuggestions('from a | stats a=min(integerField) ', [
'WHERE ',
'BY ',
', ',
'| ',
...getFunctionSignaturesByReturnType(
Location.STATS,
'any',
{ operators: true, skipAssign: true },
['integer']
),
]);

await statsExpectSuggestions('FROM index1 | STATS AVG(doubleField) WHE', [
'WHERE ',
'BY ',
', ',
'| ',
...getFunctionSignaturesByReturnType(
Location.STATS,
'any',
{ operators: true, skipAssign: true },
['double']
),
]);

await statsExpectSuggestions('FROM index1 | STATS AVG(doubleField) B', [
'WHERE ',
'BY ',
', ',
'| ',
...getFunctionSignaturesByReturnType(
Location.STATS,
'any',
{ operators: true, skipAssign: true },
['double']
),
]);
});

test('on function left paren', async () => {
Expand Down Expand Up @@ -356,11 +395,22 @@ describe('STATS Autocomplete', () => {

test('when typing right paren', async () => {
await statsExpectSuggestions(
'from a | stats a = min(b) | sort b',
['WHERE ', 'BY ', ', ', '| '],
'from a | stats a = min(integerField) | sort b',
[
'WHERE ',
'BY ',
', ',
'| ',
...getFunctionSignaturesByReturnType(
Location.STATS,
'any',
{ operators: true, skipAssign: true },
['integer']
),
],
mockCallbacks,
mockContext,
25
36
);
});

Expand All @@ -380,6 +430,28 @@ describe('STATS Autocomplete', () => {
]);
});

test('expressions with aggregates', async () => {
await statsExpectSuggestions('from a | stats col0 = min(integerField) ', [
'BY ',
'WHERE ',
'| ',
', ',
...getFunctionSignaturesByReturnType(
Location.STATS,
'any',
{ operators: true, skipAssign: true },
['integer']
),
]);
await statsExpectSuggestions('from a | stats col0 = min(integerField) + ', [
...getFunctionSignaturesByReturnType(Location.STATS, ['integer', 'double', 'long'], {
scalar: true,
agg: true,
grouping: true,
}),
]);
});

describe('...WHERE expression...', () => {
it('suggests fields and functions in empty expression', async () => {
await statsExpectSuggestions('FROM a | STATS MIN(b) WHERE ', [
Expand Down Expand Up @@ -473,13 +545,13 @@ describe('STATS Autocomplete', () => {

test('on partial column name', async () => {
const expected = [
' = ',
getDateHistogramCompletionItem().text,
...allEvalFunctionsForStats,
...allGroupingFunctions,
getDateHistogramCompletionItem().text,
' = ',
];

await statsExpectSuggestions('from a | stats a=max(b) BY keywor/', [
await statsExpectSuggestions('from a | stats a=max(b) BY keywor', [
...expected,
...getFieldNamesByType('any'),
]);
Expand All @@ -492,16 +564,24 @@ describe('STATS Autocomplete', () => {

test('on complete column name', async () => {
await statsExpectSuggestions('from a | stats a=max(b) by integerField', [
' = ',
'integerField | ',
'integerField, ',
]);

await statsExpectSuggestions('from a | stats a=max(b) by col0 = integerField', [
'integerField | ',
'integerField, ',
]);

await statsExpectSuggestions('from a | stats a=max(b) by keywordField, integerField', [
' = ',
'integerField | ',
'integerField, ',
]);

await statsExpectSuggestions(
'from a | stats a=max(b) by keywordField, col0 = integerField',
['integerField | ', 'integerField, ']
);
});

test('attaches field range', async () => {
Expand All @@ -514,7 +594,35 @@ describe('STATS Autocomplete', () => {
});

test('on space after grouping field', async () => {
await statsExpectSuggestions('from a | stats a=c by d ', [', ', '| ']);
await statsExpectSuggestions('from a | stats a=c by keywordField ', [
', ',
'| ',
...getFunctionSignaturesByReturnType(
Location.STATS_BY,
'any',
{
operators: true,
skipAssign: true,
},
['keyword']
),
]);
});

test('on space after grouping function', async () => {
await statsExpectSuggestions('from a | stats a=c by CATEGORIZE(keywordField) ', [
', ',
'| ',
...getFunctionSignaturesByReturnType(
Location.STATS_BY,
'any',
{
operators: true,
skipAssign: true,
},
['keyword']
),
]);
});

test('after comma "," in grouping fields', async () => {
Expand Down Expand Up @@ -587,15 +695,46 @@ describe('STATS Autocomplete', () => {
});

test('on space after expression right hand side operand', async () => {
await statsExpectSuggestions('from a | stats avg(b) by doubleField % 2 ', [', ', '| ']);
await statsExpectSuggestions('from a | stats avg(b) by doubleField % 2 ', [
', ',
'| ',
...getFunctionSignaturesByReturnType(
Location.STATS_BY,
'any',
{
operators: true,
skipAssign: true,
},
['double']
),
]);

await statsExpectSuggestions(
'from a | stats col0 = AVG(doubleField) BY col1 = BUCKET(dateField, 1 day) ',
[', ', '| ']
[
', ',
'| ',
...getFunctionSignaturesByReturnType(
Location.STATS_BY,
'any',
{
operators: true,
skipAssign: true,
},
['date']
),
]
);
});

test('after NOT keyword', async () => {
await statsExpectSuggestions(
'FROM logs-apache_error | STATS count() by keywordField <= textField NOT ',
['LIKE $0', 'RLIKE $0', 'IN $0']
);
});

test('on space within bucket()', async () => {
test('within bucket()', async () => {
const expectedFields = getFieldNamesByType([
'date',
'date_nanos',
Expand All @@ -605,7 +744,7 @@ describe('STATS Autocomplete', () => {
expectedFields.map((name) => ({ label: name, text: name }))
);
await statsExpectSuggestions(
'from a | stats avg(b) by BUCKET(, 50, ?_tstart, ?_tend)',
'FROM a | STATS COUNT() BY BUCKET(, 50, ?_tstart, ?_tend)',
[
// Note there's no space or comma in the suggested field names
...getFieldNamesByType(['date', 'date_nanos', ...ESQL_COMMON_NUMERIC_TYPES]),
Expand All @@ -619,10 +758,10 @@ describe('STATS Autocomplete', () => {
],
mockCallbacks,
mockContext,
32
33
);
await statsExpectSuggestions(
'from a | stats avg(b) by BUCKET( , 50, ?_tstart, ?_tend)',
'FROM a | STATS COUNT() BY BUCKET( , 50, ?_tstart, ?_tend)',
[
// Note there's no space or comma in the suggested field names
...getFieldNamesByType(['date', 'date_nanos', ...ESQL_COMMON_NUMERIC_TYPES]),
Expand All @@ -636,7 +775,7 @@ describe('STATS Autocomplete', () => {
],
mockCallbacks,
mockContext,
32
33
);
const expectedFields1 = getFieldNamesByType([
'integer',
Expand All @@ -661,7 +800,7 @@ describe('STATS Autocomplete', () => {
],
mockCallbacks,
mockContext,
43
43 // at the second argument of the bucket function
);
});

Expand Down
Loading