From 654bad4a4faf667e46274f991d6b97a5e15509ed Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Tue, 19 Mar 2024 23:21:06 -0500 Subject: [PATCH 1/4] supply data view without index pattern --- .../main/utils/get_data_view_by_text_based_query_lang.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/plugins/discover/public/application/main/utils/get_data_view_by_text_based_query_lang.ts b/src/plugins/discover/public/application/main/utils/get_data_view_by_text_based_query_lang.ts index 42e36c7ac9ab8..32261f67d6286 100644 --- a/src/plugins/discover/public/application/main/utils/get_data_view_by_text_based_query_lang.ts +++ b/src/plugins/discover/public/application/main/utils/get_data_view_by_text_based_query_lang.ts @@ -25,6 +25,9 @@ export async function getDataViewByTextBasedQueryLang( } if ('esql' in query) { indexPatternFromQuery = getIndexPatternFromESQLQuery(query.esql); + if (indexPatternFromQuery === '') { + return new DataView({ fieldFormats: services.fieldFormats }); + } } // we should find a better way to work with ESQL queries which dont need a dataview if (!indexPatternFromQuery && currentDataView) return currentDataView; From 8a546bba6045d9395dc122d5d26c434336fb8da3 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Tue, 9 Apr 2024 18:24:13 -0500 Subject: [PATCH 2/4] add functional test --- test/functional/apps/discover/group4/_esql_view.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/test/functional/apps/discover/group4/_esql_view.ts b/test/functional/apps/discover/group4/_esql_view.ts index 1a328e415b951..9a949801ecb12 100644 --- a/test/functional/apps/discover/group4/_esql_view.ts +++ b/test/functional/apps/discover/group4/_esql_view.ts @@ -155,6 +155,19 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { 'machine.ram_range', ]); }); + + it('should work without a FROM statement', async function () { + await PageObjects.discover.selectTextBaseLang(); + const testQuery = `ROW a = 1, b = "two", c = null`; + + await monacoEditor.setCodeEditorValue(testQuery); + await testSubjects.click('querySubmitButton'); + await PageObjects.header.waitUntilLoadingHasFinished(); + + await PageObjects.discover.dragFieldToTable('a'); + const cell = await dataGrid.getCellElement(0, 2); + expect(await cell.getVisibleText()).to.be('1'); + }); }); describe('errors', () => { From 9c59118a01dc13dc81a3bb2b9b7a7110a93b9b3e Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Wed, 10 Apr 2024 12:47:30 -0500 Subject: [PATCH 3/4] remove check for no index pattern --- .../main/utils/get_data_view_by_text_based_query_lang.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/plugins/discover/public/application/main/utils/get_data_view_by_text_based_query_lang.ts b/src/plugins/discover/public/application/main/utils/get_data_view_by_text_based_query_lang.ts index 32261f67d6286..46db1deb8c7b0 100644 --- a/src/plugins/discover/public/application/main/utils/get_data_view_by_text_based_query_lang.ts +++ b/src/plugins/discover/public/application/main/utils/get_data_view_by_text_based_query_lang.ts @@ -25,12 +25,16 @@ export async function getDataViewByTextBasedQueryLang( } if ('esql' in query) { indexPatternFromQuery = getIndexPatternFromESQLQuery(query.esql); + + /* if (indexPatternFromQuery === '') { - return new DataView({ fieldFormats: services.fieldFormats }); + return new DataView({ id: 'esql-', fieldFormats: services.fieldFormats }); + return getESQLAdHocDataview(indexPatternFromQuery, services.dataViews); } + */ } // we should find a better way to work with ESQL queries which dont need a dataview - if (!indexPatternFromQuery && currentDataView) return currentDataView; + // if (!indexPatternFromQuery && currentDataView) return currentDataView; if ( currentDataView?.isPersisted() || From a354b6b63c400e1c9c2a3b10e96109f6ca20eb05 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Wed, 10 Apr 2024 15:44:57 -0500 Subject: [PATCH 4/4] remove unneeded comments --- .../main/utils/get_data_view_by_text_based_query_lang.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/plugins/discover/public/application/main/utils/get_data_view_by_text_based_query_lang.ts b/src/plugins/discover/public/application/main/utils/get_data_view_by_text_based_query_lang.ts index 46db1deb8c7b0..32653aaf4f327 100644 --- a/src/plugins/discover/public/application/main/utils/get_data_view_by_text_based_query_lang.ts +++ b/src/plugins/discover/public/application/main/utils/get_data_view_by_text_based_query_lang.ts @@ -25,16 +25,7 @@ export async function getDataViewByTextBasedQueryLang( } if ('esql' in query) { indexPatternFromQuery = getIndexPatternFromESQLQuery(query.esql); - - /* - if (indexPatternFromQuery === '') { - return new DataView({ id: 'esql-', fieldFormats: services.fieldFormats }); - return getESQLAdHocDataview(indexPatternFromQuery, services.dataViews); - } - */ } - // we should find a better way to work with ESQL queries which dont need a dataview - // if (!indexPatternFromQuery && currentDataView) return currentDataView; if ( currentDataView?.isPersisted() ||