From 4eb0b2358cee2876a45fe051ccc71843a5b702b5 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 12 Dec 2024 04:09:05 +1100 Subject: [PATCH] [8.x] [ES|QL] Fix param parsing in qualified name (#203801) (#203822) # Backport This will backport the following commits from `main` to `8.x`: - [[ES|QL] Fix param parsing in qualified name (#203801)](https://github.com/elastic/kibana/pull/203801) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: Vadim Kibana <82822460+vadimkibana@users.noreply.github.com> --- .../src/parser/__tests__/commands.test.ts | 29 +++++++++++++++++++ .../kbn-esql-ast/src/parser/factories.ts | 18 +++++++++--- 2 files changed, 43 insertions(+), 4 deletions(-) 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();