Skip to content

Commit

Permalink
[ES|QL] Fixes the problem with Discover and queries without the from …
Browse files Browse the repository at this point in the history
…command
  • Loading branch information
stratoula committed Apr 12, 2024
1 parent fb9d095 commit b5c0597
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,19 @@ describe('getDataViewByTextBasedQueryLang', () => {
expect(dataView.isPersisted()).toEqual(false);
expect(dataView.timeFieldName).toBeUndefined();
});

it('creates an adhoc ES|QL dataview if the query doesnt have from command', async () => {
discoverServiceMock.dataViews.create = jest.fn().mockReturnValue({
...dataViewAdHoc,
isPersisted: () => false,
id: 'ad-hoc-id-1',
title: 'test-1',
timeFieldName: undefined,
});
const query = { esql: 'ROW x = "ES|QL is awesome"' };
const dataView = await getDataViewByTextBasedQueryLang(query, dataViewAdHoc, services);
expect(dataView.isPersisted()).toEqual(false);
expect(dataView.name).toEqual(dataViewAdHoc.name);
expect(dataView.timeFieldName).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ export async function getDataViewByTextBasedQueryLang(
indexPatternFromQuery = getIndexPatternFromESQLQuery(query.esql);
}
// we should find a better way to work with ESQL queries which dont need a dataview
if (!indexPatternFromQuery && currentDataView) return currentDataView;
if (!indexPatternFromQuery && currentDataView) {
// Here the user used either the ROW or SHOW META / SHOW INFO commands
// if we use the current dataview will create this error https://github.com/elastic/kibana/issues/163417
// so we are creating an adhoc dataview without an @timestamp timeFieldName
return await getESQLAdHocDataview(currentDataView.name, services.dataViews);
}

if (
currentDataView?.isPersisted() ||
Expand Down

0 comments on commit b5c0597

Please sign in to comment.