Skip to content

Commit

Permalink
wired up but the dataset is off
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Aug 24, 2024
1 parent 6766938 commit 8e13655
Show file tree
Hide file tree
Showing 52 changed files with 610 additions and 733 deletions.
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
10 changes: 5 additions & 5 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,14 +380,14 @@ 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;
Expand All @@ -398,7 +398,7 @@ export const updateDataFrameMeta = ({
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
3 changes: 1 addition & 2 deletions src/plugins/data/common/datasets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export interface DataStructure {
/** Optional array of data structures of ancestors */
path?: DataStructure[];
hasNext?: boolean;
groupName?: string;
columnHeader?: string;
/** Optional metadata for the data structure */
meta?: DataStructureMeta;
}
Expand Down Expand Up @@ -152,7 +152,6 @@ export interface DataStructureDataTypeMeta {
type: DATA_STRUCTURE_META_TYPES.TYPE;
icon: EuiIconProps;
tooltip: string;
isLeaf?: boolean;
}

/**
Expand Down
7 changes: 0 additions & 7 deletions src/plugins/data/common/search/search_source/search_source.ts
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
26 changes: 13 additions & 13 deletions src/plugins/data/public/antlr/shared/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { from } from 'rxjs';
import { distinctUntilChanged, startWith, switchMap } from 'rxjs/operators';
import { DatasetContract } from '../../query';
import { QueryStringContract } from '../../query';

export interface IDataSourceRequestHandlerParams {
dataSourceId: string;
Expand All @@ -14,22 +14,22 @@ export interface IDataSourceRequestHandlerParams {

// Function to get raw suggestion data
export const getRawSuggestionData$ = (
datasetManager: DatasetContract,
queryString: QueryStringContract,
dataSourceRequestHandler: ({
dataSourceId,
title,
}: IDataSourceRequestHandlerParams) => Promise<any>,
defaultRequestHandler: () => Promise<any>
) =>
datasetManager.getUpdates$().pipe(
startWith(datasetManager.getDataset()),
queryString.getUpdates$().pipe(
startWith(queryString.getQuery()),
distinctUntilChanged(),
switchMap((dataset) => {
if (!dataset) {
switchMap((query) => {
if (!query) {
return from(defaultRequestHandler());
}
const dataSourceId = dataset?.dataSource?.id;
const title = dataset?.dataSource?.title;
const dataSourceId = query.dataset?.dataSource?.id;
const title = query.dataset?.dataSource?.title;
return from(dataSourceRequestHandler({ dataSourceId, title }));
})
);
Expand All @@ -52,11 +52,11 @@ export const fetchData = (
tables: string[],
queryFormatter: (table: string, dataSourceId?: string, title?: string) => any,
api: any,
datasetManager: DatasetContract
queryString: QueryStringContract
) => {
return new Promise((resolve, reject) => {
getRawSuggestionData$(
datasetManager,
queryString,
({ dataSourceId, title }) => {
const requests = tables.map(async (table) => {
const body = JSON.stringify(queryFormatter(table, dataSourceId, title));
Expand All @@ -82,11 +82,11 @@ export const fetchData = (
};

// Specific fetch function for table schemas
export const fetchTableSchemas = (tables: string[], api: any, datasetManager: DatasetContract) => {
export const fetchTableSchemas = (tables: string[], api: any, queryString: QueryStringContract) => {
return fetchData(
tables,
(table, dataSourceId, title) => ({
query: { qs: `DESCRIBE TABLES LIKE ${table}`, format: 'jdbc' },
query: { query: `DESCRIBE TABLES LIKE ${table}`, format: 'jdbc' },
df: {
meta: {
queryConfig: {
Expand All @@ -97,6 +97,6 @@ export const fetchTableSchemas = (tables: string[], api: any, datasetManager: Da
},
}),
api,
datasetManager
queryString
);
};
2 changes: 2 additions & 0 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ export {
QueryState,
getDefaultQuery,
FilterManager,
QueryStringContract,
QueryStringManager,
DatasetTypeConfig,
DatasetService,
DatasetServiceContract,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/query/query_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class QueryService {
uiSettings,
indexPatterns,
}: QueryServiceStartDependencies): IQueryStart {
this.queryStringManager.getDatasetManager().init(indexPatterns);
this.queryStringManager.initDataset();
return {
addToQueryLog: createAddToQueryLog({
storage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,66 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { DatasetContract } from '.';
import { Dataset, DataStructure, CachedDataStructure } from '../../../../common';
import { DatasetHandlerConfig } from './types';
// import { DatasetContract } from '.';
// import { Dataset, DataStructure, CachedDataStructure } from '../../../../common';
// import { DatasetTypeConfig } from './types';

const createSetupContractMock = () => {
const datasetManagerMock: jest.Mocked<DatasetContract> = {
init: jest.fn(),
getDataset: jest.fn(),
setDataset: jest.fn(),
getUpdates$: jest.fn(),
getDefaultDataset: jest.fn(),
fetchDefaultDataset: jest.fn(),
initWithIndexPattern: jest.fn(),
registerDatasetHandler: jest.fn(),
fetchOptions: jest.fn(),
getCachedDataStructure: jest.fn(),
clearDataStructureCache: jest.fn(),
};
return datasetManagerMock;
};
// const createSetupContractMock = () => {
// const datasetManagerMock: jest.Mocked<DatasetContract> = {
// init: jest.fn(),
// getDataset: jest.fn(),
// setDataset: jest.fn(),
// getUpdates$: jest.fn(),
// getDefaultDataset: jest.fn(),
// fetchDefaultDataset: jest.fn(),
// init: jest.fn(),
// registerDatasetHandler: jest.fn(),
// fetchOptions: jest.fn(),
// getCachedDataStructure: jest.fn(),
// clearDataStructureCache: jest.fn(),
// };
// return datasetManagerMock;
// };

export const datasetManagerMock = {
createSetupContract: createSetupContractMock,
createStartContract: createSetupContractMock,
};
// export const datasetManagerMock = {
// createSetupContract: createSetupContractMock,
// createStartContract: createSetupContractMock,
// };

// Additional mock for DatasetHandlerConfig
export const createDatasetHandlerConfigMock = (): jest.Mocked<DatasetHandlerConfig> => ({
toDataset: jest.fn(),
toDataStructure: jest.fn(),
fetchOptions: jest.fn(),
isLeaf: jest.fn(),
});
// // Additional mock for DatasetHandlerConfig
// export const createDatasetHandlerConfigMock = (): jest.Mocked<DatasetTypeConfig> => ({
// toDataset: jest.fn(),
// toDataStructure: jest.fn(),
// fetchOptions: jest.fn(),
// isLeaf: jest.fn(),
// });

// Mock for Dataset
export const createDatasetMock = (): jest.Mocked<Dataset> => ({
id: 'mock-dataset-id',
title: 'Mock Dataset',
type: 'mock-type',
dataSource: {
id: 'mock-datasource-id',
title: 'Mock DataSource',
type: 'mock-datasource-type',
},
});
// // Mock for Dataset
// export const createDatasetMock = (): jest.Mocked<Dataset> => ({
// id: 'mock-dataset-id',
// title: 'Mock Dataset',
// type: 'mock-type',
// dataSource: {
// id: 'mock-datasource-id',
// title: 'Mock DataSource',
// type: 'mock-datasource-type',
// },
// });

// Mock for DataStructure
export const createDataStructureMock = (): jest.Mocked<DataStructure> => ({
id: 'mock-datastructure-id',
title: 'Mock DataStructure',
type: 'mock-type',
parent: undefined,
children: [],
});
// // Mock for DataStructure
// export const createDataStructureMock = (): jest.Mocked<DataStructure> => ({
// id: 'mock-datastructure-id',
// title: 'Mock DataStructure',
// type: 'mock-type',
// parent: undefined,
// children: [],
// });

// Mock for CachedDataStructure
export const createCachedDataStructureMock = (): jest.Mocked<CachedDataStructure> => ({
id: 'mock-cached-datastructure-id',
title: 'Mock Cached DataStructure',
type: 'mock-type',
parent: 'mock-parent-id',
children: ['mock-child-id-1', 'mock-child-id-2'],
});
// // Mock for CachedDataStructure
// export const createCachedDataStructureMock = (): jest.Mocked<CachedDataStructure> => ({
// id: 'mock-cached-datastructure-id',
// title: 'Mock Cached DataStructure',
// type: 'mock-type',
// parent: 'mock-parent-id',
// children: ['mock-child-id-1', 'mock-child-id-2'],
// });
Loading

0 comments on commit 8e13655

Please sign in to comment.