[8.11] [ES|QL] fixes getIndexPatternFromESQLQuery for comma separated indices (#169562) (#169624)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[ES|QL] fixes getIndexPatternFromESQLQuery for comma separated
indices (#169562)](https://github.com/elastic/kibana/pull/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":"92328789+vitaliidm@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-10-24T10:13:48Z","message":"[ES|QL]
fixes getIndexPatternFromESQLQuery for comma separated indices
(#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
<efstratia.kalafateli@elastic.co>","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
(#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
<efstratia.kalafateli@elastic.co>","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
(#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
<efstratia.kalafateli@elastic.co>","sha":"7112690e8e88307b75a5420b41d489847d36fce9"}}]}]
BACKPORT-->

Co-authored-by: Vitalii Dmyterko <92328789+vitaliidm@users.noreply.github.com>
This commit is contained in:
Kibana Machine 2023-10-24 07:48:49 -04:00 committed by GitHub
parent 9f0d7bb7f4
commit 4f44a52dd2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View file

@ -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');
});
});
});

View file

@ -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 '';
}