Skip to content

Commit

Permalink
[8.x] [ES|QL] Fix param parsing in qualified name (#203801) (#203822)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [[ES|QL] Fix param parsing in qualified name
(#203801)](#203801)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Vadim
Kibana","email":"82822460+vadimkibana@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-12-11T15:17:16Z","message":"[ES|QL]
Fix param parsing in qualified name (#203801)\n\n## Summary\r\n\r\n-
Handle params in \"identifier pattern\" parser nodes.\r\n\r\n\r\n###
Checklist\r\n\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"df16472e910c2c5d7883931ef0630582c7c9edd2","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["review","release_note:skip","v9.0.0","backport:prev-minor","Feature:ES|QL","Team:ESQL","v8.18.0"],"title":"[ES|QL]
Fix param parsing in qualified name identifier pattern
nodes","number":203801,"url":"https://github.com/elastic/kibana/pull/203801","mergeCommit":{"message":"[ES|QL]
Fix param parsing in qualified name (#203801)\n\n## Summary\r\n\r\n-
Handle params in \"identifier pattern\" parser nodes.\r\n\r\n\r\n###
Checklist\r\n\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"df16472e910c2c5d7883931ef0630582c7c9edd2"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203801","number":203801,"mergeCommit":{"message":"[ES|QL]
Fix param parsing in qualified name (#203801)\n\n## Summary\r\n\r\n-
Handle params in \"identifier pattern\" parser nodes.\r\n\r\n\r\n###
Checklist\r\n\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios","sha":"df16472e910c2c5d7883931ef0630582c7c9edd2"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Vadim Kibana <82822460+vadimkibana@users.noreply.github.com>
  • Loading branch information
kibanamachine and vadimkibana authored Dec 11, 2024
1 parent 8eb5049 commit 4eb0b23
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 4eb0b23

Please sign in to comment.