diff --git a/src/platform/packages/shared/kbn-esql-ast/src/parser/__tests__/commands.test.ts b/src/platform/packages/shared/kbn-esql-ast/src/parser/__tests__/commands.test.ts index 6fb176c9624f7..865d8ef64e272 100644 --- a/src/platform/packages/shared/kbn-esql-ast/src/parser/__tests__/commands.test.ts +++ b/src/platform/packages/shared/kbn-esql-ast/src/parser/__tests__/commands.test.ts @@ -141,6 +141,35 @@ describe('commands', () => { ]); }); + it('KEEP (with param)', () => { + const query = 'FROM index | KEEP abc, ?param'; + const { ast } = parse(query); + + expect(ast).toMatchObject([ + {}, + { + type: 'command', + name: 'keep', + args: [ + { + type: 'column', + name: 'abc', + }, + { + type: 'column', + args: [ + { + type: 'literal', + literalType: 'param', + value: 'param', + }, + ], + }, + ], + }, + ]); + }); + it('SORT', () => { const query = 'FROM index | SORT 1'; const { ast } = parse(query); diff --git a/src/platform/packages/shared/kbn-esql-ast/src/parser/factories.ts b/src/platform/packages/shared/kbn-esql-ast/src/parser/factories.ts index 388469e82ab99..feada64c3cf9a 100644 --- a/src/platform/packages/shared/kbn-esql-ast/src/parser/factories.ts +++ b/src/platform/packages/shared/kbn-esql-ast/src/parser/factories.ts @@ -526,11 +526,21 @@ export function createColumn(ctx: ParserRuleContext): ESQLColumn { if (ctx instanceof QualifiedNamePatternContext) { const list = ctx.identifierPattern_list(); - for (const identifier of list) { - const name = parseIdentifier(identifier.getText()); - const node = Builder.identifier({ name }, createParserFields(identifier)); + for (const identifierPattern of list) { + const ID_PATTERN = identifierPattern.ID_PATTERN(); - args.push(node); + if (ID_PATTERN) { + const name = parseIdentifier(ID_PATTERN.getText()); + const node = Builder.identifier({ name }, createParserFields(identifierPattern)); + + args.push(node); + } else { + const parameter = createParam(identifierPattern.parameter()); + + if (parameter) { + args.push(parameter); + } + } } } else if (ctx instanceof QualifiedNameContext) { const list = ctx.identifierOrParameter_list();