Skip to content

Commit

Permalink
Extended Dataset type config to provide search options like strategy (#…
Browse files Browse the repository at this point in the history
…8113) (#8131)

* added function to provide search strategy; updated interceptors to use the strategy



* minor refactor



* refactored code



---------


(cherry picked from commit b438c2e)

Signed-off-by: Amardeepsingh Siglani <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent b081a26 commit 5607c5c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/plugins/data/common/datasets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,7 @@ export interface DatasetField {
displayName?: string;
// TODO: osdFieldType?
}

export interface DatasetSearchOptions {
strategy?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
import { EuiIconProps } from '@elastic/eui';
import { Dataset, DatasetField, DataStructure } from '../../../../common';
import { Dataset, DatasetField, DatasetSearchOptions, DataStructure } from '../../../../common';
import { IDataPluginServices } from '../../../types';

/**
Expand Down Expand Up @@ -44,4 +44,9 @@ export interface DatasetTypeConfig {
* @returns {Promise<string[]>} A promise that resolves to an array of supported language ids.
*/
supportedLanguages: (dataset: Dataset) => string[];
/**
* Retrieves the search options to be used for running the query on the data connection associated
* with this Dataset
*/
getSearchOptions?: () => DatasetSearchOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class PPLSearchInterceptor extends SearchInterceptor {
const { id, ...searchRequest } = request;
const context: EnhancedFetchContext = {
http: this.deps.http,
path: trimEnd(API.PPL_SEARCH),
path: trimEnd(`${API.SEARCH}/${strategy}`),
signal,
};

Expand All @@ -55,7 +55,18 @@ export class PPLSearchInterceptor extends SearchInterceptor {
}

public search(request: IOpenSearchDashboardsSearchRequest, options: ISearchOptions) {
return this.runSearch(request, options.abortSignal, SEARCH_STRATEGY.PPL);
const dataset = this.queryService.queryString.getQuery().dataset;
const datasetType = dataset?.type;
let strategy = SEARCH_STRATEGY.PPL;

if (datasetType) {
const datasetTypeConfig = this.queryService.queryString
.getDatasetService()
.getType(datasetType);
strategy = datasetTypeConfig?.getSearchOptions?.().strategy ?? strategy;
}

return this.runSearch(request, options.abortSignal, strategy);
}

private buildQuery() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class SQLSearchInterceptor extends SearchInterceptor {
const isAsync = strategy === SEARCH_STRATEGY.SQL_ASYNC;
const context: EnhancedFetchContext = {
http: this.deps.http,
path: trimEnd(isAsync ? API.SQL_ASYNC_SEARCH : API.SQL_SEARCH),
path: trimEnd(`${API.SEARCH}/${strategy}`),
signal,
};

Expand All @@ -54,7 +54,16 @@ export class SQLSearchInterceptor extends SearchInterceptor {

public search(request: IOpenSearchDashboardsSearchRequest, options: ISearchOptions) {
const dataset = this.queryService.queryString.getQuery().dataset;
const strategy = dataset?.type === DATASET.S3 ? SEARCH_STRATEGY.SQL_ASYNC : SEARCH_STRATEGY.SQL;
const datasetType = dataset?.type;
let strategy = datasetType === DATASET.S3 ? SEARCH_STRATEGY.SQL_ASYNC : SEARCH_STRATEGY.SQL;

if (datasetType) {
const datasetTypeConfig = this.queryService.queryString
.getDatasetService()
.getType(datasetType);
strategy = datasetTypeConfig?.getSearchOptions?.().strategy ?? strategy;
}

return this.runSearch(request, options.abortSignal, strategy);
}
}

0 comments on commit 5607c5c

Please sign in to comment.