mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[ES|QL] fixes getIndexPatternFromESQLQuery for comma separated indices (#169562)
## Summary Comma separated source indices work as expected with ES|QL query, but `getIndexPatternFromESQLQuery` does not parses it correctly. This small PR is an attempt to fix this behavior ### Before ```ts const idxPattern7 = getIndexPatternFromESQLQuery('from foo-1, foo-2 | limit 2'); expect(idxPattern7).toBe('foo-1,'); ``` ### After ```ts const idxPattern7 = getIndexPatternFromESQLQuery('from foo-1, foo-2 | limit 2'); expect(idxPattern7).toBe('foo-1, foo-2'); ``` ### Checklist Delete any items that are not applicable to this PR. - [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 Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
This commit is contained in:
parent
2b91c31fd0
commit
7112690e8e
2 changed files with 14 additions and 2 deletions
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -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 '';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue