Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 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
6900864
Merge branch 'main' of github.com:elastic/kibana into expressions-in-…
drewdaemon Mar 27, 2025
6ba3f08
Basic WHERE support
drewdaemon Mar 27, 2025
0c30f12
make it work
drewdaemon Mar 28, 2025
9363312
add a few expression smoke tests
drewdaemon Mar 28, 2025
fd11634
make the tests happy
drewdaemon Mar 28, 2025
8cb4376
Merge branch 'main' of github.com:elastic/kibana into expressions-in-…
drewdaemon Mar 28, 2025
2cf33a9
Merge branch 'main' of github.com:elastic/kibana into expressions-in-…
drewdaemon Apr 1, 2025
592eecb
increase operator support, test WHERE parity
drewdaemon Apr 1, 2025
59a3eba
support multiple expressions
drewdaemon Apr 1, 2025
866a5e4
clean up some stuff
drewdaemon Apr 1, 2025
40ada59
re-enable stats behavior
drewdaemon Apr 1, 2025
f03e5b6
fix undefined arg bug
drewdaemon Apr 1, 2025
e2554ed
Merge branch 'main' of github.com:elastic/kibana into expressions-in-…
drewdaemon Apr 2, 2025
c471a3e
update operators
drewdaemon Apr 2, 2025
File filter

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 @@ -37,6 +37,16 @@ describe('STATS', () => {
]);
});

it("doesn't append an undefined arg with a trailing comma", () => {
const src = `
FROM employees
| STATS 123 ,`;
const query = EsqlQuery.fromSrc(src);

expect(query.ast.commands[1].args).toHaveLength(1);
expect(query.ast.commands[1].args.every((arg) => arg)).toBe(true);
});

it('aggregation function with escaped values', () => {
const src = `
FROM employees
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export const createStatsCommand = (ctx: StatsCommandContext, src: string): ESQLC
const fields = ctx.aggFields();

for (const fieldCtx of fields.aggField_list()) {
if (fieldCtx.getText() === '') continue;

const node = createAggField(fieldCtx);

command.args.push(node);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class Visitor<

for (let i = nodes.length - 1; i >= 0; i--) {
const node = nodes[i];
if (!node) continue;
const { location } = node;
if (!location) continue;
const isInside = location.min <= pos && location.max >= pos;
Expand All @@ -145,6 +146,7 @@ export class Visitor<
const nodes = [...ctx.arguments()];
for (let i = nodes.length - 1; i >= 0; i--) {
const node = nodes[i];
if (!node) continue;
const { location } = node;
if (!location) continue;
const isInside = location.min <= pos && location.max >= pos;
Expand All @@ -163,6 +165,7 @@ export class Visitor<
const nodes = [...ctx.commands()];
for (let i = nodes.length - 1; i >= 0; i--) {
const node = nodes[i];
if (!node) continue;
const { location } = node;
if (!location) continue;
const isInside = location.min <= pos && location.max >= pos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ const enrichOperators = (
Location.WHERE,
Location.ROW,
Location.SORT,
Location.STATS_WHERE,
Location.STATS_BY,
]);
}
Expand All @@ -741,13 +742,20 @@ const enrichOperators = (
Location.EVAL,
Location.WHERE,
Location.ROW,
Location.STATS,
Location.SORT,
Location.STATS,
Location.STATS_WHERE,
Location.STATS_BY,
]);
}
if (isInOperator || isLikeOperator || isNotOperator || arePredicates) {
locationsAvailable = [Location.EVAL, Location.WHERE, Location.SORT, Location.ROW];
locationsAvailable = [
Location.EVAL,
Location.WHERE,
Location.SORT,
Location.ROW,
Location.STATS_WHERE,
];
}
if (isInOperator) {
// Override the signatures to be array types instead of singular
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { ESQL_COMMON_NUMERIC_TYPES } from '../../shared/esql_types';
import { scalarFunctionDefinitions } from '../../definitions/generated/scalar_functions';
import { timeUnitsToSuggest } from '../../definitions/literals';
import { FunctionDefinitionTypes } from '../../definitions/types';
import { FunctionDefinitionTypes, Location } from '../../definitions/types';
import {
getCompatibleTypesToSuggestNext,
getValidFunctionSignaturesForPreviousArgs,
Expand All @@ -46,7 +46,7 @@ const getTypesFromParamDefs = (paramDefs: FunctionParameter[]): SupportedDataTyp
) as SupportedDataType[];

describe('autocomplete.suggest', () => {
describe('eval', () => {
describe(Location.EVAL, () => {
let assertSuggestions: AssertSuggestionsFn;

beforeEach(async () => {
Expand All @@ -58,39 +58,39 @@ describe('autocomplete.suggest', () => {
await assertSuggestions('from a | eval /', [
'var0 = ',
...getFieldNamesByType('any').map((v) => `${v} `),
...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }),
...getFunctionSignaturesByReturnType(Location.EVAL, 'any', { scalar: true }),
]);

await assertSuggestions('from a | eval col0 = /', [
...getFieldNamesByType('any').map((v) => `${v} `),
...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }),
...getFunctionSignaturesByReturnType(Location.EVAL, 'any', { scalar: true }),
]);

await assertSuggestions('from a | eval col0 = 1, /', [
'var0 = ',
...getFieldNamesByType('any').map((v) => `${v} `),
...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }),
...getFunctionSignaturesByReturnType(Location.EVAL, 'any', { scalar: true }),
]);

await assertSuggestions('from a | eval col0 = 1, col1 = /', [
...getFieldNamesByType('any').map((v) => `${v} `),
...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }),
...getFunctionSignaturesByReturnType(Location.EVAL, 'any', { scalar: true }),
]);

// Re-enable with https://github.com/elastic/kibana/issues/210639
// await assertSuggestions('from a | eval a=doubleField, /', [
// 'var0 = ',
// ...getFieldNamesByType('any').map((v) => `${v} `),
// 'a',
// ...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }),
// ...getFunctionSignaturesByReturnType(Location.EVAL, 'any', { scalar: true }),
// ]);

await assertSuggestions(
'from a | stats avg(doubleField) by keywordField | eval /',
[
'var0 = ',
'`avg(doubleField)` ',
...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }),
...getFunctionSignaturesByReturnType(Location.EVAL, 'any', { scalar: true }),
],
{
triggerCharacter: ' ',
Expand All @@ -108,7 +108,7 @@ describe('autocomplete.suggest', () => {
'var0 = ',
...getFieldNamesByType('any').map((v) => `${v} `),
'`abs(doubleField) + 1` ',
...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }),
...getFunctionSignaturesByReturnType(Location.EVAL, 'any', { scalar: true }),
],
{
triggerCharacter: ' ',
Expand All @@ -124,7 +124,7 @@ describe('autocomplete.suggest', () => {
[
'var0 = ',
'`avg(doubleField)` ',
...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }),
...getFunctionSignaturesByReturnType(Location.EVAL, 'any', { scalar: true }),
],
{
triggerCharacter: ' ',
Expand All @@ -139,9 +139,12 @@ describe('autocomplete.suggest', () => {

test('after column', async () => {
await assertSuggestions('from a | eval doubleField /', [
...getFunctionSignaturesByReturnType('eval', 'any', { operators: true, skipAssign: true }, [
'double',
]),
...getFunctionSignaturesByReturnType(
Location.EVAL,
'any',
{ operators: true, skipAssign: true },
['double']
),
]);
});

Expand All @@ -160,7 +163,7 @@ describe('autocomplete.suggest', () => {

await assertSuggestions('from index | EVAL not /', [
...getFieldNamesByType('boolean').map((v) => `${v} `),
...getFunctionSignaturesByReturnType('eval', 'boolean', { scalar: true }),
...getFunctionSignaturesByReturnType(Location.EVAL, 'boolean', { scalar: true }),
]);
});

Expand All @@ -170,7 +173,7 @@ describe('autocomplete.suggest', () => {
'from index | EVAL doubleField in (/)',
[
...getFieldNamesByType('double').filter((name) => name !== 'doubleField'),
...getFunctionSignaturesByReturnType('eval', 'double', { scalar: true }),
...getFunctionSignaturesByReturnType(Location.EVAL, 'double', { scalar: true }),
],
{ triggerCharacter: '(' }
);
Expand All @@ -182,15 +185,15 @@ describe('autocomplete.suggest', () => {
'from a | eval a=/',
[
...getFieldNamesByType('any').map((v) => `${v} `),
...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }),
...getFunctionSignaturesByReturnType(Location.EVAL, 'any', { scalar: true }),
],
{ triggerCharacter: '=' }
);
await assertSuggestions(
'from a | eval a=abs(doubleField), b= /',
[
...getFieldNamesByType('any').map((v) => `${v} `),
...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }),
...getFunctionSignaturesByReturnType(Location.EVAL, 'any', { scalar: true }),
],
{ triggerCharacter: '=' }
);
Expand All @@ -202,7 +205,7 @@ describe('autocomplete.suggest', () => {
[
...getFieldNamesByType(roundParameterTypes),
...getFunctionSignaturesByReturnType(
'eval',
Location.EVAL,
roundParameterTypes,
{ scalar: true },
undefined,
Expand Down Expand Up @@ -237,10 +240,12 @@ describe('autocomplete.suggest', () => {
await assertSuggestions('from a | eval a=round(doubleField) /', [
', ',
'| ',
...getFunctionSignaturesByReturnType('eval', 'any', { operators: true, skipAssign: true }, [
'double',
'long',
]),
...getFunctionSignaturesByReturnType(
Location.EVAL,
'any',
{ operators: true, skipAssign: true },
['double', 'long']
),
'IN $0',
'IS NOT NULL',
'IS NULL',
Expand All @@ -250,7 +255,7 @@ describe('autocomplete.suggest', () => {
[
...getFieldNamesByType(['integer', 'long']),
...getFunctionSignaturesByReturnType(
'eval',
Location.EVAL,
['integer', 'long'],
{ scalar: true },
undefined,
Expand All @@ -264,7 +269,7 @@ describe('autocomplete.suggest', () => {
[
...getFieldNamesByType(['integer', 'long']),
...getFunctionSignaturesByReturnType(
'eval',
Location.EVAL,
['integer', 'long'],
{ scalar: true },
undefined,
Expand All @@ -278,29 +283,29 @@ describe('autocomplete.suggest', () => {
...getFieldNamesByType('any').map((v) => `${v} `),
// Re-enable with https://github.com/elastic/kibana/issues/210639
// 'a',
...getFunctionSignaturesByReturnType('eval', 'any', { scalar: true }),
...getFunctionSignaturesByReturnType(Location.EVAL, 'any', { scalar: true }),
]);
await assertSuggestions('from a | eval a=round(doubleField) + /', [
...getFieldNamesByType(ESQL_COMMON_NUMERIC_TYPES),
...getFunctionSignaturesByReturnType('eval', ESQL_COMMON_NUMERIC_TYPES, {
...getFunctionSignaturesByReturnType(Location.EVAL, ESQL_COMMON_NUMERIC_TYPES, {
scalar: true,
}),
]);
await assertSuggestions('from a | eval a=round(doubleField)+ /', [
...getFieldNamesByType(ESQL_COMMON_NUMERIC_TYPES),
...getFunctionSignaturesByReturnType('eval', ESQL_COMMON_NUMERIC_TYPES, {
...getFunctionSignaturesByReturnType(Location.EVAL, ESQL_COMMON_NUMERIC_TYPES, {
scalar: true,
}),
]);
await assertSuggestions('from a | eval a=doubleField+ /', [
...getFieldNamesByType(ESQL_COMMON_NUMERIC_TYPES),
...getFunctionSignaturesByReturnType('eval', ESQL_COMMON_NUMERIC_TYPES, {
...getFunctionSignaturesByReturnType(Location.EVAL, ESQL_COMMON_NUMERIC_TYPES, {
scalar: true,
}),
]);
await assertSuggestions('from a | eval a=`any#Char$Field`+ /', [
...getFieldNamesByType(ESQL_COMMON_NUMERIC_TYPES),
...getFunctionSignaturesByReturnType('eval', ESQL_COMMON_NUMERIC_TYPES, {
...getFunctionSignaturesByReturnType(Location.EVAL, ESQL_COMMON_NUMERIC_TYPES, {
scalar: true,
}),
]);
Expand All @@ -310,7 +315,7 @@ describe('autocomplete.suggest', () => {
[
...getFieldNamesByType(roundParameterTypes),
...getFunctionSignaturesByReturnType(
'eval',
Location.EVAL,
roundParameterTypes,
{ scalar: true },
undefined,
Expand All @@ -323,7 +328,7 @@ describe('autocomplete.suggest', () => {
await assertSuggestions('from a | eval a=concat( /', [
...getFieldNamesByType(['text', 'keyword']).map((v) => `${v}, `),
...getFunctionSignaturesByReturnType(
'eval',
Location.EVAL,
['text', 'keyword'],
{ scalar: true },
undefined,
Expand All @@ -335,7 +340,7 @@ describe('autocomplete.suggest', () => {
[
...getFieldNamesByType(['text', 'keyword']),
...getFunctionSignaturesByReturnType(
'eval',
Location.EVAL,
['text', 'keyword'],
{ scalar: true },
undefined,
Expand All @@ -351,7 +356,7 @@ describe('autocomplete.suggest', () => {
// test that comma is correctly added to the suggestions if minParams is not reached yet
await assertSuggestions('from a | eval a=cidr_match(/', [
...getFieldNamesByType('ip').map((v) => `${v}, `),
...getFunctionSignaturesByReturnType('eval', 'ip', { scalar: true }, undefined, [
...getFunctionSignaturesByReturnType(Location.EVAL, 'ip', { scalar: true }, undefined, [
'cidr_match',
]).map((v) => ({ ...v, text: `${v.text},` })),
]);
Expand All @@ -360,7 +365,7 @@ describe('autocomplete.suggest', () => {
[
...getFieldNamesByType(['text', 'keyword']),
...getFunctionSignaturesByReturnType(
'eval',
Location.EVAL,
['text', 'keyword'],
{ scalar: true },
undefined,
Expand All @@ -378,7 +383,7 @@ describe('autocomplete.suggest', () => {
[
...getFieldNamesByType(roundParameterTypes),
...getFunctionSignaturesByReturnType(
'eval',
Location.EVAL,
roundParameterTypes,
{ scalar: true },
undefined,
Expand All @@ -395,16 +400,19 @@ describe('autocomplete.suggest', () => {

// Smoke testing for suggestions in previous position than the end of the statement
await assertSuggestions('from a | eval var0 = abs(doubleField) / | eval abs(var0)', [
...getFunctionSignaturesByReturnType('eval', 'any', { operators: true, skipAssign: true }, [
'double',
]),
...getFunctionSignaturesByReturnType(
Location.EVAL,
'any',
{ operators: true, skipAssign: true },
['double']
),
', ',
'| ',
]);
await assertSuggestions('from a | eval var0 = abs(b/) | eval abs(var0)', [
...getFieldNamesByType(absParameterTypes),
...getFunctionSignaturesByReturnType(
'eval',
Location.EVAL,
absParameterTypes,
{ scalar: true },
undefined,
Expand Down Expand Up @@ -519,7 +527,7 @@ describe('autocomplete.suggest', () => {
getTypesFromParamDefs(typesToSuggestNext).filter(isFieldType)
),
...getFunctionSignaturesByReturnType(
'eval',
Location.EVAL,
getTypesFromParamDefs(typesToSuggestNext).filter(
isReturnType
) as FunctionReturnType[],
Expand Down Expand Up @@ -581,7 +589,7 @@ describe('autocomplete.suggest', () => {
', ',
'| ',
...getFunctionSignaturesByReturnType(
'eval',
Location.EVAL,
'any',
{ operators: true, skipAssign: true },
['integer']
Expand All @@ -594,7 +602,7 @@ describe('autocomplete.suggest', () => {
'from a | eval var0=date_trunc(/)',
[
...getLiteralsByType('time_literal').map((t) => `${t}, `),
...getFunctionSignaturesByReturnType('eval', ['time_duration', 'date_period'], {
...getFunctionSignaturesByReturnType(Location.EVAL, ['time_duration', 'date_period'], {
scalar: true,
}).map((t) => `${t.text},`),
],
Expand Down
Loading