Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Extended Dataset type config to provide search options like strategy #8131

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading