Skip to content

Commit

Permalink
[8.11] [ES|QL] fixes getIndexPatternFromESQLQuery for comma separated…
Browse files Browse the repository at this point in the history
… indices (elastic#169562) (elastic#169624)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[ES|QL] fixes getIndexPatternFromESQLQuery for comma separated
indices (elastic#169562)](elastic#169562)

<!--- Backport version: 8.9.7 -->

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

<!--BACKPORT [{"author":{"name":"Vitalii
Dmyterko","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-10-24T10:13:48Z","message":"[ES|QL]
fixes getIndexPatternFromESQLQuery for comma separated indices
(elastic#169562)\n\n## Summary\r\n\r\nComma separated source indices work as
expected with ES|QL query, but\r\n`getIndexPatternFromESQLQuery` does
not parses it correctly. This small\r\nPR is an attempt to fix this
behavior\r\n\r\n### Before\r\n\r\n```ts\r\n const idxPattern7 =
getIndexPatternFromESQLQuery('from foo-1, foo-2 | limit 2');\r\n
expect(idxPattern7).toBe('foo-1,');\r\n```\r\n\r\n### After\r\n```ts\r\n
const idxPattern7 = getIndexPatternFromESQLQuery('from foo-1, foo-2 |
limit 2');\r\n expect(idxPattern7).toBe('foo-1,
foo-2');\r\n```\r\n\r\n### Checklist\r\n\r\nDelete any items that are
not applicable to this PR.\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\r\n\r\nCo-authored-by: Stratoula Kalafateli
<[email protected]>","sha":"7112690e8e88307b75a5420b41d489847d36fce9","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:DataDiscovery","backport:prev-minor","v8.11.0","Feature:ES|QL","v8.12.0"],"number":169562,"url":"https://github.com/elastic/kibana/pull/169562","mergeCommit":{"message":"[ES|QL]
fixes getIndexPatternFromESQLQuery for comma separated indices
(elastic#169562)\n\n## Summary\r\n\r\nComma separated source indices work as
expected with ES|QL query, but\r\n`getIndexPatternFromESQLQuery` does
not parses it correctly. This small\r\nPR is an attempt to fix this
behavior\r\n\r\n### Before\r\n\r\n```ts\r\n const idxPattern7 =
getIndexPatternFromESQLQuery('from foo-1, foo-2 | limit 2');\r\n
expect(idxPattern7).toBe('foo-1,');\r\n```\r\n\r\n### After\r\n```ts\r\n
const idxPattern7 = getIndexPatternFromESQLQuery('from foo-1, foo-2 |
limit 2');\r\n expect(idxPattern7).toBe('foo-1,
foo-2');\r\n```\r\n\r\n### Checklist\r\n\r\nDelete any items that are
not applicable to this PR.\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\r\n\r\nCo-authored-by: Stratoula Kalafateli
<[email protected]>","sha":"7112690e8e88307b75a5420b41d489847d36fce9"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"8.11","label":"v8.11.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/169562","number":169562,"mergeCommit":{"message":"[ES|QL]
fixes getIndexPatternFromESQLQuery for comma separated indices
(elastic#169562)\n\n## Summary\r\n\r\nComma separated source indices work as
expected with ES|QL query, but\r\n`getIndexPatternFromESQLQuery` does
not parses it correctly. This small\r\nPR is an attempt to fix this
behavior\r\n\r\n### Before\r\n\r\n```ts\r\n const idxPattern7 =
getIndexPatternFromESQLQuery('from foo-1, foo-2 | limit 2');\r\n
expect(idxPattern7).toBe('foo-1,');\r\n```\r\n\r\n### After\r\n```ts\r\n
const idxPattern7 = getIndexPatternFromESQLQuery('from foo-1, foo-2 |
limit 2');\r\n expect(idxPattern7).toBe('foo-1,
foo-2');\r\n```\r\n\r\n### Checklist\r\n\r\nDelete any items that are
not applicable to this PR.\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\r\n\r\nCo-authored-by: Stratoula Kalafateli
<[email protected]>","sha":"7112690e8e88307b75a5420b41d489847d36fce9"}}]}]
BACKPORT-->

Co-authored-by: Vitalii Dmyterko <[email protected]>
  • Loading branch information
kibanamachine and vitaliidm authored Oct 24, 2023
1 parent 9f0d7bb commit 4f44a52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/kbn-es-query/src/es_query/es_aggregate_query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ describe('sql query helpers', () => {

const idxPattern5 = getIndexPatternFromESQLQuery('from foo | limit 2');
expect(idxPattern5).toBe('foo');

const idxPattern6 = getIndexPatternFromESQLQuery('from foo-1,foo-2 | limit 2');
expect(idxPattern6).toBe('foo-1,foo-2');

const idxPattern7 = getIndexPatternFromESQLQuery('from foo-1, foo-2 | limit 2');
expect(idxPattern7).toBe('foo-1, foo-2');

const idxPattern8 = getIndexPatternFromESQLQuery('FROM foo-1, foo-2');
expect(idxPattern8).toBe('foo-1, foo-2');

const idxPattern9 = getIndexPatternFromESQLQuery('FROM foo-1, foo-2 [metadata _id]');
expect(idxPattern9).toBe('foo-1, foo-2');
});
});
});
4 changes: 2 additions & 2 deletions packages/kbn-es-query/src/es_query/es_aggregate_query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ export function getIndexPatternFromESQLQuery(esql?: string): string {
}
const parsedString = esql?.replaceAll('`', '');
// case insensitive match for the index pattern
const regex = new RegExp(/FROM\s+([\w*-.!@$^()~;]+)/, 'i');
const regex = new RegExp(/FROM\s+([\w*-.!@$^()~;\s]+)/, 'i');
const matches = parsedString?.match(regex);
if (matches) {
return matches[1];
return matches[1]?.trim();
}
return '';
}

0 comments on commit 4f44a52

Please sign in to comment.