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

[discover-next][bug] add back data set navigator to control state #7492

Merged
merged 33 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8a5faff
Revert "Revert "[Discover-next] data set picker (#7426)" (#7479)"
kavilla Jul 25, 2024
a526102
fix(query assist): update reading data source id from dataset manager…
joshuali925 Jul 25, 2024
74b03e9
[Auto Suggest] DQL autosuggest with ANTLR (#7467)
paulstn Jul 25, 2024
44b2fc1
[tests][discover-next] update the tests and async nature of the datas…
kavilla Jul 25, 2024
f55c295
update snapshot
kavilla Jul 25, 2024
af2017b
[DataSet Navigator] Rewire S3 components (#7470)
sejli Jul 25, 2024
2b5881b
Fix UI and detection of external data source in query assist (#7494)
joshuali925 Jul 25, 2024
9f49ce3
pass in index patterns
kavilla Jul 25, 2024
9f68352
[Auto Suggest] Add MDS Support Along with A Few Cleanup and tests (#7…
mengweieric Jul 25, 2024
3fff70e
More styling on query enhancement UI styling (#7496)
abbyhu2000 Jul 25, 2024
27a74ab
[Auto Suggest] DQL Updates (#7498)
paulstn Jul 25, 2024
bf057f2
fix some typing issues
kavilla Jul 25, 2024
254a7f2
delete manual changelogs
kavilla Jul 25, 2024
b33c5b4
fixing sessionId support
sejli Jul 26, 2024
b575ca6
remove height
abbyhu2000 Jul 26, 2024
f66ef3b
Revert "[Auto Suggest] DQL Updates (#7498)"
kavilla Jul 26, 2024
65b9171
Revert "[Auto Suggest] Add MDS Support Along with A Few Cleanup and t…
kavilla Jul 26, 2024
4d1ea50
Revert "[Auto Suggest] DQL autosuggest with ANTLR (#7467)"
kavilla Jul 26, 2024
a77b0db
fixing typing issue
sejli Jul 26, 2024
b887914
remove unused export
sejli Jul 26, 2024
666bae4
fix texts and some state mgmt
kavilla Jul 26, 2024
4a58eda
Merge remote-tracking branch 'lnse/s3-sessionid' into feature/discove…
kavilla Jul 26, 2024
d5f5686
fix file
kavilla Jul 26, 2024
593541d
update snapshot
kavilla Jul 26, 2024
f37f782
Merge remote-tracking branch 'abby/fix_style_top_nav' into feature/di…
kavilla Jul 26, 2024
729f0e3
more clean up
kavilla Jul 26, 2024
b09c906
default to false
kavilla Jul 26, 2024
ca2b837
only push the set with enhancements
kavilla Jul 26, 2024
0964ec9
fix two tests
kavilla Jul 26, 2024
fef6156
render hell
kavilla Jul 26, 2024
861af9b
test update
kavilla Jul 26, 2024
2f5ed13
passing in settings
kavilla Jul 26, 2024
6ff7e26
add changelog
kavilla Jul 26, 2024
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/plugins/data/common/data_frames/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export * from './_df_cache';
export enum DATA_FRAME_TYPES {
DEFAULT = 'data_frame',
POLLING = 'data_frame_polling',
ERROR = 'data_frame_error',
}

export interface DataFrameService {
Expand Down Expand Up @@ -46,6 +47,12 @@ export interface DataFrameBucketAgg extends DataFrameAgg {
key: string;
}

export interface DataFrameQueryConfig {
dataSourceId?: string;
dataSourceName?: string;
timeFieldName?: string;
}

/**
* This configuration is used to define how the aggregation should be performed.
*/
Expand Down
44 changes: 32 additions & 12 deletions src/plugins/data/common/data_frames/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
IDataFrameWithAggs,
IDataFrameResponse,
PartialDataFrame,
DataFrameQueryConfig,
} from './types';
import { IFieldType } from './fields';
import { IndexPatternFieldMap, IndexPatternSpec } from '../index_patterns';
Expand Down Expand Up @@ -165,16 +166,6 @@
}
const data = body as IDataFrame;
const hits: any[] = [];
for (let index = 0; index < data.size; index++) {
const hit: { [key: string]: any } = {};
data.fields.forEach((field) => {
hit[field.name] = field.values[index];
});
hits.push({
_index: data.name,
_source: hit,
});
}
const searchResponse: SearchResponse<any> = {
took: response.took,
timed_out: false,
Expand All @@ -187,10 +178,24 @@
hits: {
total: 0,
max_score: 0,
hits,
hits: [],
},
};

if (data && data.fields && data.fields.length > 0) {
for (let index = 0; index < data.size; index++) {
const hit: { [key: string]: any } = {};
data.fields.forEach((field) => {
hit[field.name] = field.values[index];

Check warning on line 189 in src/plugins/data/common/data_frames/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/data_frames/utils.ts#L186-L189

Added lines #L186 - L189 were not covered by tests
});
hits.push({

Check warning on line 191 in src/plugins/data/common/data_frames/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/data_frames/utils.ts#L191

Added line #L191 was not covered by tests
_index: data.name,
_source: hit,
});
}
}
searchResponse.hits.hits = hits;

Check warning on line 197 in src/plugins/data/common/data_frames/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/data_frames/utils.ts#L197

Added line #L197 was not covered by tests

if (data.hasOwnProperty('aggs')) {
const dataWithAggs = data as IDataFrameWithAggs;
if (!dataWithAggs.aggs) {
Expand Down Expand Up @@ -282,9 +287,19 @@
*/
export const getTimeField = (
data: IDataFrame,
queryConfig?: DataFrameQueryConfig,
aggConfig?: DataFrameAggConfig
): Partial<IFieldType> | undefined => {
if (queryConfig?.timeFieldName) {
return {

Check warning on line 294 in src/plugins/data/common/data_frames/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/data_frames/utils.ts#L294

Added line #L294 was not covered by tests
name: queryConfig.timeFieldName,
type: 'date',
};
}
const fields = data.schema || data.fields;
if (!fields) {
throw Error('Invalid time field');

Check warning on line 301 in src/plugins/data/common/data_frames/utils.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/data_frames/utils.ts#L301

Added line #L301 was not covered by tests
}
return aggConfig && aggConfig.date_histogram && aggConfig.date_histogram.field
? fields.find((field) => field.name === aggConfig?.date_histogram?.field)
: fields.find((field) => field.type === 'date');
Expand Down Expand Up @@ -468,7 +483,12 @@
return {
id: id ?? DATA_FRAME_TYPES.DEFAULT,
title: dataFrame.name,
timeFieldName: getTimeField(dataFrame)?.name,
timeFieldName: getTimeField(dataFrame, dataFrame.meta?.queryConfig)?.name,
dataSourceRef: {
id: dataFrame.meta?.queryConfig?.dataSourceId,
name: dataFrame.meta?.queryConfig?.dataSourceName,
type: dataFrame.meta?.queryConfig?.dataSourceType,
},
type: !id ? DATA_FRAME_TYPES.DEFAULT : undefined,
fields: fields.reduce(flattenFields, {} as IndexPatternFieldMap),
};
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/data/common/search/opensearch_search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ export interface ISearchOptions {
* Use this option to enable support for long numerals.
*/
withLongNumeralsSupport?: boolean;
/**
* Use this option to enable support for async.
*/
isAsync?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we put this somewhere else?

}

export type ISearchRequestParams<T = Record<string, any>> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
import {
DATA_FRAME_TYPES,
IDataFrame,
IDataFrameError,
IDataFrameResponse,
convertResult,
createDataFrame,
Expand Down Expand Up @@ -430,7 +431,7 @@
private async fetchExternalSearch(searchRequest: SearchRequest, options: ISearchOptions) {
const { search, getConfig, onResponse } = this.dependencies;

const currentDataframe = this.getDataFrame();

Check warning on line 434 in src/plugins/data/common/search/search_source/search_source.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/search/search_source/search_source.ts#L434

Added line #L434 was not covered by tests
if (!currentDataframe || currentDataframe.name !== searchRequest.index?.id) {
await this.createDataFrame(searchRequest);
}
Expand All @@ -447,6 +448,10 @@
await this.setDataFrame(dataFrameResponse.body as IDataFrame);
return onResponse(searchRequest, convertResult(response as IDataFrameResponse));
}
if ((response as IDataFrameResponse).type === DATA_FRAME_TYPES.ERROR) {
const dataFrameError = response as IDataFrameError;
throw new RequestFailure(null, dataFrameError);

Check warning on line 453 in src/plugins/data/common/search/search_source/search_source.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/search/search_source/search_source.ts#L452-L453

Added lines #L452 - L453 were not covered by tests
}
// TODO: MQL else if data_frame_polling then poll for the data frame updating the df fields only
}
return onResponse(searchRequest, response.rawResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
import { SqlErrorListener } from './sql_error_listerner';
import { findCursorTokenIndex } from '../shared/cursor';
import { openSearchSqlAutocompleteData } from './opensearch_sql_autocomplete';
import { getUiSettings } from '../../services';
import { SQL_SYMBOLS } from './constants';
import { QuerySuggestionGetFnArgs } from '../../autocomplete';
import { QuerySuggestion, QuerySuggestionGetFnArgs } from '../../autocomplete';
import { fetchColumnValues, fetchTableSchemas } from '../shared/utils';

export interface SuggestionParams {
Expand All @@ -46,8 +45,8 @@
query,
services,
}: QuerySuggestionGetFnArgs): Promise<QuerySuggestion[]> => {
const { api } = services.uiSettings;
const dataSetManager = services.data.query.dataSet;

Check warning on line 49 in src/plugins/data/public/antlr/opensearch_sql/code_completion.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/antlr/opensearch_sql/code_completion.ts#L48-L49

Added lines #L48 - L49 were not covered by tests
const suggestions = getOpenSearchSqlAutoCompleteSuggestions(query, {
line: position?.lineNumber || selectionStart,
column: position?.column || selectionEnd,
Expand All @@ -59,12 +58,12 @@
// Fetch columns and values
if ('suggestColumns' in suggestions && (suggestions.suggestColumns?.tables?.length ?? 0) > 0) {
const tableNames = suggestions.suggestColumns?.tables?.map((table) => table.name) ?? [];
const schemas = await fetchTableSchemas(tableNames, api, connectionService);
const schemas = await fetchTableSchemas(tableNames, api, services);

Check warning on line 61 in src/plugins/data/public/antlr/opensearch_sql/code_completion.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/antlr/opensearch_sql/code_completion.ts#L61

Added line #L61 was not covered by tests

schemas.forEach((schema) => {
if (schema.body?.fields?.length > 0) {
const columns = schema.body.fields.find((col: any) => col.name === 'COLUMN_NAME');
const fieldTypes = schema.body.fields.find((col: any) => col.name === 'DATA_TYPE');

Check warning on line 66 in src/plugins/data/public/antlr/opensearch_sql/code_completion.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/antlr/opensearch_sql/code_completion.ts#L65-L66

Added lines #L65 - L66 were not covered by tests
if (columns && fieldTypes) {
finalSuggestions.push(
...columns.values.map((col: string, index: number) => ({
Expand All @@ -86,7 +85,7 @@
tableNames,
suggestions.suggestValuesForColumn as string,
api,
connectionService
services
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might need to remove these lines from here, since the other autocomplete prs were removed from this branch. this change was added in this commit, would only need to revert the changes done on this file: bf057f2#diff-f67c8b1b68c9ae8eeb8ea7d7dea38e59d32b7738dec7c9db5763cf74b96aa92fR46

);
values.forEach((value) => {
if (value.body?.fields?.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export interface QuerySuggestionGetFnArgs {
signal?: AbortSignal;
boolFilter?: any;
position?: monaco.Position;
connectionService?: any; // will need to add type when ConnectionService is properly exposed from queryEnhancements
services?: any; // will need to add type when ConnectionService is properly exposed from queryEnhancements
}

/** @public **/
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ export {
// for BWC, keeping the old name
IUiStart as DataPublicPluginStartUi,
DataSetNavigator,
setAsyncSessionId,
getAsyncSessionId,
setAsyncSessionIdByObj,
} from './ui';

/**
Expand All @@ -462,6 +465,8 @@ export {
QueryState,
getDefaultQuery,
FilterManager,
DataSetManager,
DataSetContract,
SavedQuery,
SavedQueryService,
SavedQueryTimeFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
import { DataSetManager } from './dataset_manager';
import { coreMock } from '../../../../../core/public/mocks';
import { SimpleDataSet } from '../../../common';

describe('DataSetManager', () => {
let service: DataSetManager;

beforeEach(() => {
service = new DataSetManager(coreMock.createSetup().uiSettings);
const uiSettingsMock = coreMock.createSetup().uiSettings;
uiSettingsMock.get.mockReturnValue(true);
service = new DataSetManager(uiSettingsMock);
});

test('getUpdates$ emits initially and after data set changes', () => {
Expand All @@ -20,15 +21,15 @@ describe('DataSetManager', () => {
obs$.subscribe((v) => {
emittedValues.push(v);
});
expect(emittedValues).toHaveLength(1);
expect(emittedValues[1]).toEqual(undefined);
expect(emittedValues).toHaveLength(0);
expect(emittedValues[0]).toEqual(undefined);

const newDataSet: SimpleDataSet = { id: 'test_dataset', title: 'Test Dataset' };
service.setDataSet(newDataSet);
expect(emittedValues).toHaveLength(2);
expect(emittedValues[1]).toEqual(newDataSet);
expect(emittedValues).toHaveLength(1);
expect(emittedValues[0]).toEqual(newDataSet);

service.setDataSet({ ...newDataSet });
expect(emittedValues).toHaveLength(3);
expect(emittedValues).toHaveLength(2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,32 @@

import { BehaviorSubject } from 'rxjs';
import { CoreStart } from 'opensearch-dashboards/public';
import { skip } from 'rxjs/operators';
import {
IndexPatternsService,
SIMPLE_DATA_SET_TYPES,
SimpleDataSet,
SimpleDataSource,
UI_SETTINGS,
} from '../../../common';
import { IndexPatternsContract } from '../../index_patterns';

export class DataSetManager {
private dataSet$: BehaviorSubject<SimpleDataSet | undefined>;
private indexPatterns?: IndexPatternsService;
private indexPatterns?: IndexPatternsContract;
private defaultDataSet?: SimpleDataSet;

constructor(private readonly uiSettings: CoreStart['uiSettings']) {
this.dataSet$ = new BehaviorSubject<SimpleDataSet | undefined>(undefined);
}

public init = async (indexPatterns: IndexPatternsService) => {
public init = async (indexPatterns: IndexPatternsContract) => {
this.indexPatterns = indexPatterns;
this.defaultDataSet = await this.fetchDefaultDataSet();
return this.defaultDataSet;
};

public getUpdates$ = () => {
return this.dataSet$.asObservable();
return this.dataSet$.asObservable().pipe(skip(1));
};

public getDataSet = () => {
Expand All @@ -39,17 +42,18 @@
* @param {Query} query
*/
public setDataSet = (dataSet: SimpleDataSet | undefined) => {
if (!this.uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED)) return;
this.dataSet$.next(dataSet);
};

public getDefaultDataSet = () => {
return this.defaultDataSet;
};

private fetchDefaultDataSet = async (): Promise<SimpleDataSet | undefined> => {
public fetchDefaultDataSet = async (): Promise<SimpleDataSet | undefined> => {
const defaultIndexPatternId = this.uiSettings.get('defaultIndex');
if (!defaultIndexPatternId) {
return undefined;

Check warning on line 56 in src/plugins/data/public/query/dataset_manager/dataset_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/dataset_manager/dataset_manager.ts#L56

Added line #L56 was not covered by tests
}

const indexPattern = await this.indexPatterns?.get(defaultIndexPatternId);
Expand All @@ -58,10 +62,10 @@
}

if (!indexPattern.id) {
return undefined;

Check warning on line 65 in src/plugins/data/public/query/dataset_manager/dataset_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/dataset_manager/dataset_manager.ts#L65

Added line #L65 was not covered by tests
}

return {

Check warning on line 68 in src/plugins/data/public/query/dataset_manager/dataset_manager.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/dataset_manager/dataset_manager.ts#L68

Added line #L68 was not covered by tests
id: indexPattern.id,
title: indexPattern.title,
type: SIMPLE_DATA_SET_TYPES.INDEX_PATTERN,
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/public/query/query_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import { TimefilterService, TimefilterSetup } from './timefilter';
import { createSavedQueryService } from './saved_query/saved_query_service';
import { createQueryStateObservable } from './state_sync/create_global_query_observable';
import { QueryStringManager, QueryStringContract } from './query_string';
import { DataSetManager, DataSetContract } from './dataset_manager';
import { DataSetManager } from './dataset_manager';
import { buildOpenSearchQuery, getOpenSearchQueryConfig, IndexPatternsService } from '../../common';
import { getUiSettings } from '../services';
import { IndexPattern } from '..';
Expand All @@ -63,7 +63,7 @@ export class QueryService {
filterManager!: FilterManager;
timefilter!: TimefilterSetup;
queryStringManager!: QueryStringContract;
dataSetManager!: DataSetContract;
dataSetManager!: DataSetManager;

state$!: ReturnType<typeof createQueryStateObservable>;

Expand Down
Loading
Loading