Skip to content

Commit

Permalink
[ES|QL] Fix param parsing in qualified name (elastic#203801)
Browse files Browse the repository at this point in the history
## 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
  • Loading branch information
vadimkibana authored Dec 11, 2024
1 parent 6f5d5cd commit df16472
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
18 changes: 14 additions & 4 deletions src/platform/packages/shared/kbn-esql-ast/src/parser/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit df16472

Please sign in to comment.