From 3a9dee3bdb50570a77cebd7c327724d33e8cf8e5 Mon Sep 17 00:00:00 2001 From: Sean Li Date: Wed, 24 Jul 2024 17:48:33 -0700 Subject: [PATCH 1/2] rewiring databases back into navigator Signed-off-by: Sean Li --- .../public/ui/dataset_navigator/dataset_navigator.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx b/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx index ad4490ff134d..d8751426bd93 100644 --- a/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx +++ b/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx @@ -238,7 +238,7 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { const handleSelectExternalDataSource = useCallback( async (dataSource) => { - if (selectedDataSetState.isExternal && dataSource) { + if (dataSource && dataSource.type === SIMPLE_DATA_SOURCE_TYPES.EXTERNAL) { const dataSourceCache = CatalogCacheManager.getOrCreateDataSource( dataSource.name, dataSource.id @@ -265,7 +265,7 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { } } }, - [databasesLoadStatus, selectedDataSetState.isExternal, startLoadingDatabases] + [databasesLoadStatus, startLoadingDatabases] ); // Start loading tables for selected database @@ -530,10 +530,10 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { ? selectedDataSetState.dataSourceRef?.name : 'Databases', items: [ - ...navigatorState.externalDataSources.map((db) => ({ + ...navigatorState.cachedDatabases.map((db) => ({ name: db.name, onClick: async () => { - await handleSelectExternalDatabase(db); + handleSelectExternalDatabase(db); }, panel: 6, })), @@ -608,7 +608,7 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { ...prevState, externalDataSources: externalDataSourcesCache.externalDataSources.map( (ds) => ({ - id: ds.name, + id: ds.dataSourceRef, name: ds.name, type: SIMPLE_DATA_SOURCE_TYPES.EXTERNAL, }) From 405b0b832c8fc072fcdc5cd349056a72e1965354 Mon Sep 17 00:00:00 2001 From: Sean Li Date: Thu, 25 Jul 2024 13:28:43 -0700 Subject: [PATCH 2/2] fixing async query support Signed-off-by: Sean Li --- .../dataset_navigator/dataset_navigator.tsx | 64 +++++++++---------- .../public/ui/dataset_navigator/lib/types.tsx | 9 ++- .../public/search/sql_search_interceptor.ts | 4 ++ .../search/sql_async_search_strategy.ts | 2 +- 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx b/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx index d8751426bd93..ff9bf1469deb 100644 --- a/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx +++ b/src/plugins/data/public/ui/dataset_navigator/dataset_navigator.tsx @@ -31,7 +31,7 @@ import { useLoadTablesToCache, } from './lib/catalog_cache/cache_loader'; import { CatalogCacheManager } from './lib/catalog_cache/cache_manager'; -import { CachedDataSourceStatus, DirectQueryLoadingStatus } from './lib/types'; +import { CachedDataSourceStatus, CachedDatabase, DirectQueryLoadingStatus } from './lib/types'; import { getIndexPatterns, getNotifications, @@ -181,7 +181,7 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { type: selectedPattern.dataSourceRef.type, }, } - : { dataSource: undefined }), + : { dataSourceRef: undefined }), database: undefined, isExternal: false, }); @@ -257,12 +257,12 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { ...prevState, cachedDatabases: dataSourceCache.databases, })); - setSelectedDataSetState((prevState) => ({ - ...prevState, - dataSource, - isExternal: true, - })); } + setSelectedDataSetState((prevState) => ({ + ...prevState, + dataSourceRef: dataSource, + isExternal: true, + })); } }, [databasesLoadStatus, startLoadingDatabases] @@ -272,7 +272,7 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { const handleSelectExternalDatabase = useCallback( (externalDatabase: SimpleDataSource) => { if (selectedDataSetState.dataSourceRef && externalDatabase) { - let databaseCache; + let databaseCache: CachedDatabase; try { databaseCache = CatalogCacheManager.getDatabase( selectedDataSetState.dataSourceRef.name, @@ -292,10 +292,6 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { databaseName: externalDatabase.name, dataSourceMDSId: selectedDataSetState.dataSourceRef.id, }); - setSelectedDataSetState((prevState) => ({ - ...prevState, - database: externalDatabase, - })); } else if (databaseCache.status === CachedDataSourceStatus.Updated) { setNavigatorState((prevState) => ({ ...prevState, @@ -315,7 +311,7 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { selectedDataSetState.database ) { const tablesStatus = tablesLoadStatus.toLowerCase(); - let databaseCache; + let databaseCache: CachedDatabase; try { databaseCache = CatalogCacheManager.getDatabase( selectedDataSetState.dataSourceRef.name, @@ -533,7 +529,11 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { ...navigatorState.cachedDatabases.map((db) => ({ name: db.name, onClick: async () => { - handleSelectExternalDatabase(db); + setSelectedDataSetState((prevState) => ({ + ...prevState, + database: db, + })); + await handleSelectExternalDatabase(db); }, panel: 6, })), @@ -628,28 +628,28 @@ export const DataSetNavigator = (props: DataSetNavigatorProps) => { createDatabasesPanel(), { id: 6, - title: selectedDataSetState.database ? selectedDataSetState.database : 'Tables', + title: selectedDataSetState.database ? selectedDataSetState.database.name : 'Tables', items: [ ...navigatorState.cachedTables.map((table) => ({ - name: table.title, + name: table.name, onClick: async () => { - setSelectedDataSetState((prevState) => ({ - ...prevState, - object: { - id: `${selectedDataSetState.dataSourceRef!.name}.${ - selectedDataSetState.database - }.${table.title}`, - title: `${selectedDataSetState.dataSourceRef!.name}.${ - selectedDataSetState.database - }.${table.title}`, - dataSource: { - id: selectedDataSetState.dataSourceRef!.id, - name: selectedDataSetState.dataSourceRef!.name, - type: selectedDataSetState.dataSourceRef!.type, - }, - type: SIMPLE_DATA_SET_TYPES.TEMPORARY_ASYNC, + const tableObject = { + ...selectedDataSetState, + id: `${selectedDataSetState.dataSourceRef!.name}.${ + selectedDataSetState.database.name + }.${table.name}`, + title: `${selectedDataSetState.dataSourceRef!.name}.${ + selectedDataSetState.database.name + }.${table.name}`, + dataSourceRef: { + id: selectedDataSetState.dataSourceRef!.id, + name: selectedDataSetState.dataSourceRef!.name, + type: selectedDataSetState.dataSourceRef!.type, }, - })); + type: SIMPLE_DATA_SET_TYPES.TEMPORARY_ASYNC, + }; + setSelectedDataSetState(tableObject); + handleSelectedDataSet(tableObject); }, })), ], diff --git a/src/plugins/data/public/ui/dataset_navigator/lib/types.tsx b/src/plugins/data/public/ui/dataset_navigator/lib/types.tsx index 03d844ff5689..6566b2ebe4a5 100644 --- a/src/plugins/data/public/ui/dataset_navigator/lib/types.tsx +++ b/src/plugins/data/public/ui/dataset_navigator/lib/types.tsx @@ -4,7 +4,7 @@ */ import { EuiComboBoxOptionOption } from '@elastic/eui'; -import { SimpleDataSet, SimpleObject } from '../../../../common'; +import { SimpleDataSet } from '../../../../common'; export enum DirectQueryLoadingStatus { SUCCESS = 'success', @@ -121,9 +121,14 @@ export interface CachedColumn { dataType: string; } +export interface CachedTable { + name: string; + columns?: CachedColumn[]; +} + export interface CachedDatabase { name: string; - tables: SimpleObject[]; + tables: CachedTable[]; lastUpdated: string; // date string in UTC format status: CachedDataSourceStatus; } diff --git a/src/plugins/query_enhancements/public/search/sql_search_interceptor.ts b/src/plugins/query_enhancements/public/search/sql_search_interceptor.ts index de7fb5938d25..6ff3986ad32f 100644 --- a/src/plugins/query_enhancements/public/search/sql_search_interceptor.ts +++ b/src/plugins/query_enhancements/public/search/sql_search_interceptor.ts @@ -110,6 +110,10 @@ export class SQLSearchInterceptor extends SearchInterceptor { ...dataFrame.meta, queryConfig: { ...dataFrame.meta.queryConfig, + ...(this.queryService.dataSet.getDataSet() && { + dataSourceId: this.queryService.dataSet.getDataSet()?.dataSourceRef?.id, + dataSourceName: this.queryService.dataSet.getDataSet()?.dataSourceRef?.name, + }), }, }; diff --git a/src/plugins/query_enhancements/server/search/sql_async_search_strategy.ts b/src/plugins/query_enhancements/server/search/sql_async_search_strategy.ts index 8cd5014335e0..1a76dbf85dd9 100644 --- a/src/plugins/query_enhancements/server/search/sql_async_search_strategy.ts +++ b/src/plugins/query_enhancements/server/search/sql_async_search_strategy.ts @@ -38,7 +38,7 @@ export const sqlAsyncSearchStrategyProvider = ( const df = request.body?.df; request.body = { query: request.body.query.qs, - datasource: df?.meta?.queryConfig?.dataSource, + datasource: df?.meta?.queryConfig?.dataSourceName, lang: 'sql', sessionId: df?.meta?.sessionId, };