From 3307710e035c30120133abf89a707ded01e98581 Mon Sep 17 00:00:00 2001 From: Vadim Kibana <82822460+vadimkibana@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:17:16 +0100 Subject: [PATCH] [ES|QL] Fix param parsing in qualified name (#203801) ## Summary - Handle params in "identifier pattern" parser nodes. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --- .../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();