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

Language with dataset service #70

Open
wants to merge 21 commits into
base: kavilla/dataset-manager
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"start": "scripts/use_node scripts/opensearch_dashboards --dev",
"start:docker": "scripts/use_node scripts/opensearch_dashboards --dev --opensearch.hosts=$OPENSEARCH_HOSTS --opensearch.ignoreVersionMismatch=true --server.host=$SERVER_HOST",
"start:security": "scripts/use_node scripts/opensearch_dashboards --dev --security",
"start:enhancements": "scripts/use_node scripts/opensearch_dashboards --dev --uiSettings.overrides['query:enhancements:enabled']=true --uiSettings.overrides['home:useNewHomePage']=true --uiSettings.overrides['state:storeInSessionStorage']=true",
"start:enhancements": "scripts/use_node scripts/opensearch_dashboards --dev --uiSettings.overrides['query:enhancements:enabled']=true --uiSettings.overrides['home:useNewHomePage']=true",
"debug": "scripts/use_node --nolazy --inspect scripts/opensearch_dashboards --dev",
"debug-break": "scripts/use_node --nolazy --inspect-brk scripts/opensearch_dashboards --dev",
"lint": "yarn run lint:es && yarn run lint:style",
Expand Down
6 changes: 3 additions & 3 deletions src/core/public/saved_objects/saved_objects_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,14 +457,14 @@ export class SavedObjectsClient {
* { id: 'foo', type: 'index-pattern' }
* ])
*/
public bulkGet = (objects: Array<{ id: string; type: string }> = []) => {
public bulkGet = <T = unknown>(objects: Array<{ id: string; type: string }> = []) => {
const filteredObjects = objects.map((obj) => pick(obj, ['id', 'type']));
return this.performBulkGet(filteredObjects).then((resp) => {
resp.saved_objects = resp.saved_objects.map((d) => this.createSavedObject(d));
return renameKeys<
PromiseType<ReturnType<SavedObjectsApi['bulkGet']>>,
SavedObjectsBatchResponse
>({ saved_objects: 'savedObjects' }, resp) as SavedObjectsBatchResponse;
SavedObjectsBatchResponse<T>
>({ saved_objects: 'savedObjects' }, resp) as SavedObjectsBatchResponse<T>;
});
};

Expand Down
99 changes: 0 additions & 99 deletions src/plugins/data/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,105 +42,6 @@ export const DEFAULT_DATA = {
tooltip: 'Root Data Structure',
},
} as DataStructure,

NULL: {
id: 'NULL',
title: 'Empty',
type: 'NULL',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'empty',
tooltip: 'Empty Data Structure',
},
} as DataStructure,

CATEGORY: {
id: 'CATEGORY',
title: 'Categories',
type: 'CATEGORY',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'listAdd',
tooltip: 'Data Categories',
},
} as DataStructure,

DATA_SOURCE: {
id: 'DATA_SOURCE',
title: 'Clusters',
type: 'DATA_SOURCE',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'cluster',
tooltip: 'Data Clusters',
},
} as DataStructure,

CONNECTION: {
id: 'CONNECTION',
title: 'Connections',
type: 'CONNECTION',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'link',
tooltip: 'Data Connections',
},
} as DataStructure,

INDEX: {
id: 'INDEX',
title: 'Indexes',
type: 'INDEX',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'indexOpen',
tooltip: 'Data Indexes',
},
} as DataStructure,

FIELD: {
id: 'FIELD',
title: 'Fields',
type: 'FIELD',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'field',
tooltip: 'Data Fields',
},
} as DataStructure,

TIME_FIELD: {
id: 'TIME_FIELD',
title: 'Time fields',
type: 'TIME_FIELD',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'clock',
tooltip: 'Time Fields',
},
} as DataStructure,

DATASET: {
id: 'DATASET',
title: 'Datasets',
type: 'DATASET',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'document',
tooltip: 'Datasets',
},
} as DataStructure,

DATASET_CATEGORY: {
id: 'DATASET_CATEGORY',
title: 'Datasets',
type: 'DATASET_CATEGORY',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'documents',
tooltip: 'Dataset Categories',
},
} as DataStructure,
},

SET_TYPES: {
Expand Down
12 changes: 6 additions & 6 deletions src/plugins/data/common/data_frames/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { IFieldType } from './fields';
import { IndexPatternFieldMap, IndexPatternSpec } from '../index_patterns';
import { IOpenSearchDashboardsSearchRequest } from '../search';
import { GetAggTypeFn, GetDataFrameAggQsFn, TimeRange } from '../types';
import { GetAggTypeFn, GetDataFrameAggQsFn, Query, TimeRange } from '../types';

/**
* Returns the raw data frame from the search request.
Expand Down Expand Up @@ -380,25 +380,25 @@ export const createDataFrame = (partial: PartialDataFrame): IDataFrame | IDataFr
*/
export const updateDataFrameMeta = ({
dataFrame,
qs,
query,
aggConfig,
timeField,
timeFilter,
getAggQsFn,
}: {
dataFrame: IDataFrame;
qs: string;
query: Query;
aggConfig: DataFrameAggConfig;
timeField: any;
timeFilter: string;
getAggQsFn: GetDataFrameAggQsFn;
}) => {
dataFrame.meta = {
...dataFrame.meta,
...dataFrame?.meta,
aggs: aggConfig,
aggsQs: {
[aggConfig.id]: getAggQsFn({
qs,
query,
aggConfig,
timeField,
timeFilter,
Expand All @@ -411,7 +411,7 @@ export const updateDataFrameMeta = ({
for (const [key, subAgg] of Object.entries(subAggs)) {
const subAggConfig: Record<string, any> = { [key]: subAgg };
dataFrame.meta.aggsQs[subAgg.id] = getAggQsFn({
qs,
query,
aggConfig: subAggConfig as DataFrameAggConfig,
timeField,
timeFilter,
Expand Down
14 changes: 5 additions & 9 deletions src/plugins/data/common/datasets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ export interface DataStructure {
parent?: DataStructure;
/** Optional array of child data structures */
children?: DataStructure[];
/** Optional array of data structures of ancestors */
path?: DataStructure[];
isLeaf?: boolean;
hasNext?: boolean;
columnHeader?: string;
/** Optional metadata for the data structure */
meta?: DataStructureMeta;
Expand Down Expand Up @@ -152,7 +150,6 @@ export interface DataStructureDataTypeMeta {
type: DATA_STRUCTURE_META_TYPES.TYPE;
icon: EuiIconProps;
tooltip: string;
isLeaf?: boolean;
}

/**
Expand Down Expand Up @@ -203,7 +200,6 @@ export interface BaseDataset {
type: string;
/** Optional reference to the data source */
dataSource?: DataSource;
fields?: DatasetField[];
}

/**
Expand All @@ -220,10 +216,10 @@ export interface BaseDataset {
* type: "INDEX_PATTERN",
* timeFieldName: "@timestamp",
* dataSource: {
* id: "main-cluster",
* title: "Main OpenSearch Cluster",
* type: "OPENSEARCH"
* },
* id: "2e1b1b80-9c4d-11ee-8c90-0242ac120001",
* title: "Cluster1",
* type: "OpenSearch"
* }
* };
*
* @example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class IndexPatternsService {

this.savedObjectsCache = await Promise.all(
this.savedObjectsCache.map(async (obj) => {
// TODO: This behaviour will cause the index pattern title to be resolved differently depending on how its fetched since the get method in this service will not append the datasource title
if (obj.type === 'index-pattern') {
const result = { ...obj };
result.attributes.title = await getIndexPatternTitle(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,16 +320,9 @@ export class SearchSource {
* @return {undefined|IDataFrame}
*/
async createDataFrame(searchRequest: SearchRequest) {
const rawQueryString = this.getRawQueryStringFromRequest(searchRequest);
const dataFrame = createDataFrame({
name: searchRequest.index.title || searchRequest.index,
fields: [],
...(rawQueryString && {
meta: {
queryConfig: { qs: rawQueryString },
...(searchRequest.dataSourceId && { dataSource: searchRequest.dataSourceId }),
},
}),
});
await this.setDataFrame(dataFrame);
return this.getDataFrame();
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/data/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/

import { DataFrameAggConfig, IDataFrame } from './data_frames';
import { Query } from './query';
import { BucketAggType, MetricAggType } from './search';

export * from './query/types';
Expand All @@ -50,12 +51,12 @@ export * from './datasets/types';
export type GetConfigFn = <T = any>(key: string, defaultOverride?: T) => T;
export type GetDataFrameFn = () => IDataFrame | undefined;
export type GetDataFrameAggQsFn = ({
qs,
query,
aggConfig,
timeField,
timeFilter,
}: {
qs: string;
query: Query;
aggConfig: DataFrameAggConfig;
timeField: any;
timeFilter: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const getSuggestions = async ({
services,
}: QuerySuggestionGetFnArgs): Promise<QuerySuggestion[]> => {
const { api } = services.uiSettings;
const datasetManager = services.data.query.queryString.getDatasetManager();
const queryString = services.data.query.queryString;
const { lineNumber, column } = position || {};
const suggestions = getOpenSearchSqlAutoCompleteSuggestions(query, {
line: lineNumber || selectionStart,
Expand All @@ -60,7 +60,7 @@ export const getSuggestions = async ({
// Fetch columns and values
if (suggestions.suggestColumns?.tables?.length) {
const tableNames = suggestions.suggestColumns.tables.map((table) => table.name);
const schemas = await fetchTableSchemas(tableNames, api, datasetManager);
const schemas = await fetchTableSchemas(tableNames, api, queryString);

(schemas as IDataFrameResponse[]).forEach((schema: IDataFrameResponse) => {
if ('body' in schema && schema.body && 'fields' in schema.body) {
Expand Down
16 changes: 9 additions & 7 deletions src/plugins/data/public/antlr/shared/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { of } from 'rxjs';
import { fetchData } from './utils';
import { DatasetManager } from '../../query';
import { QueryStringManager } from '../../query';

describe('fetchData', () => {
it('should fetch data using the dataSourceRequestHandler', async () => {
Expand All @@ -26,18 +26,20 @@ describe('fetchData', () => {
fetch: jest.fn().mockResolvedValue('fetchedData'),
},
};
const mockDatasetManager: Partial<DatasetManager> = {
const mockQueryString: Partial<QueryStringManager> = {
getUpdates$: jest
.fn()
.mockReturnValue(of({ dataSourceRef: { id: 'testId', name: 'testTitle' } })),
getDataset: jest.fn().mockReturnValue({ dataSourceRef: { id: 'testId', name: 'testTitle' } }),
getDatasetService: jest
.fn()
.mockReturnValue({ dataSourceRef: { id: 'testId', name: 'testTitle' } }),
};

const result = await fetchData(
mockTables,
mockQueryFormatter,
mockApi,
mockDatasetManager as DatasetManager
mockQueryString as QueryStringManager
);
expect(result).toEqual(['fetchedData', 'fetchedData']);
expect(mockQueryFormatter).toHaveBeenCalledWith('table1', 'testId', 'testTitle');
Expand All @@ -59,16 +61,16 @@ describe('fetchData', () => {
fetch: jest.fn().mockResolvedValue('fetchedData'),
},
};
const mockDatasetManager: Partial<DatasetManager> = {
const mockQueryString: Partial<QueryStringManager> = {
getUpdates$: jest.fn().mockReturnValue(of(undefined)),
getDataset: jest.fn().mockReturnValue(undefined),
getDatasetService: jest.fn().mockReturnValue(undefined),
};

const result = await fetchData(
mockTables,
mockQueryFormatter,
mockApi,
mockDatasetManager as DatasetManager
mockQueryString as QueryStringManager
);
expect(result).toEqual(['fetchedData', 'fetchedData']);
expect(mockQueryFormatter).toHaveBeenCalledWith('table1');
Expand Down
Loading
Loading