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] update interfaces and selector #7835

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0c3bf0f
dataset handler and move manager
kavilla Aug 19, 2024
b106aaa
Adds new Data selector
ashwin-pc Aug 20, 2024
07bad36
start wiring into the selector
kavilla Aug 21, 2024
0ac103e
still working on the data structure and field
kavilla Aug 22, 2024
63998b6
still not working. the leaf logic isnt right i believe
kavilla Aug 23, 2024
390c614
indices
kavilla Aug 24, 2024
35c4c49
pushing datasets
kavilla Aug 24, 2024
653d1d2
fix index pattern
kavilla Aug 24, 2024
1a02726
fixes with column
kavilla Aug 24, 2024
3e367d7
working creation step
kavilla Aug 24, 2024
42f53f4
get dataset from state in use index pattern
kavilla Aug 24, 2024
c8ab6d1
dataset selector working
kavilla Aug 24, 2024
e5f22a6
update ppl interceptor
kavilla Aug 24, 2024
42dab80
add dataset service
kavilla Aug 24, 2024
6766938
language service
kavilla Aug 24, 2024
8e13655
wired up but the dataset is off
kavilla Aug 24, 2024
906d4a2
Address review comments
kavilla Aug 25, 2024
8fce6b1
ppl query
kavilla Aug 25, 2024
89e238c
dql and lucene working again
kavilla Aug 25, 2024
2323d10
fix issue that would deselect dataset
kavilla Aug 25, 2024
910db55
language switches and sets the query correctly
kavilla Aug 25, 2024
97af277
upating query
kavilla Aug 25, 2024
a445672
fix the styling a little
kavilla Aug 25, 2024
7dc216f
little bit width
kavilla Aug 25, 2024
42a6efd
submit on update
kavilla Aug 25, 2024
733a723
fix sql
kavilla Aug 25, 2024
19a00be
ppl working better
kavilla Aug 25, 2024
fef3163
need to still fix the aggregations
kavilla Aug 25, 2024
5a6186a
gotta fix the aggs and still need to update dql lucene dataset
kavilla Aug 25, 2024
18751e4
use patch
kavilla Aug 25, 2024
182792d
Metadata slice
kavilla Aug 26, 2024
b6f55d1
index pattern updates
kavilla Aug 26, 2024
2ed09f7
types and datasource prepend
kavilla Aug 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
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
3 changes: 1 addition & 2 deletions packages/osd-stylelint-config/config/global_selectors.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
"src/plugins/discover/public/application/view_components/canvas/discover_canvas.scss",
"src/plugins/discover/public/application/components/sidebar/discover_sidebar.scss",
"src/plugins/data/public/ui/query_string_input/_query_bar.scss",
"src/plugins/data/public/ui/query_editor/_query_editor.scss",
"src/plugins/data/public/ui/dataset_navigator/_dataset_navigator.scss"
"src/plugins/data/public/ui/query_editor/_query_editor.scss"
]
}
}
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
39 changes: 36 additions & 3 deletions src/plugins/data/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* GitHub history for details.
*/

import { DATA_STRUCTURE_META_TYPES, DataStructure } from './types';

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
Expand All @@ -28,10 +30,41 @@
* under the License.
*/

export const DEFAULT_DATA = {
STRUCTURES: {
ROOT: {
id: 'ROOT',
title: 'Data',
type: 'ROOT',
meta: {
type: DATA_STRUCTURE_META_TYPES.FEATURE,
icon: 'folderOpen',
tooltip: 'Root Data Structure',
},
} as DataStructure,
},

SET_TYPES: {
INDEX_PATTERN: 'INDEX_PATTERN',
INDEX: 'INDEXES',
},

SOURCE_TYPES: {
OPENSEARCH: 'OPENSEARCH',
LEGACY: 'LEGACY',
},
};

export const DEFAULT_QUERY_LANGUAGE = 'kuery';

export const DEFAULT_QUERY = {
LANGUAGE: 'kuery',
DATASET_TYPE: 'INDEX_PATTERN',
ENGINE_TYPE: 'OPENSEARCH',
LANGUAGE: DEFAULT_QUERY_LANGUAGE,
DATASET: {
TYPE: DEFAULT_DATA.SET_TYPES.INDEX_PATTERN,
DATASOURCE: {
TYPE: DEFAULT_DATA.SOURCE_TYPES.OPENSEARCH,
},
},
};

export const UI_SETTINGS = {
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
46 changes: 46 additions & 0 deletions src/plugins/data/common/datasets/_structure_cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { DataStructure, CachedDataStructure } from './types';

export interface DataStructureCache {
get: (id: string) => CachedDataStructure | undefined;
set: (id: string, value: CachedDataStructure) => CachedDataStructure;
clear: (id: string) => void;
clearAll: () => void;
}

export function createDataStructureCache(): DataStructureCache {
const cache: Record<string, CachedDataStructure> = {};

const dataStructureCache: DataStructureCache = {
get: (id: string) => {
return cache[id];
},
set: (id: string, value: CachedDataStructure) => {
cache[id] = value;
return value;
},
clear: (id: string) => {
delete cache[id];
},
// TODO: call this on log out
clearAll: () => {
Object.keys(cache).forEach((key) => delete cache[key]);
},
};

return dataStructureCache;
}

export function toCachedDataStructure(dataStructure: DataStructure): CachedDataStructure {
return {
id: dataStructure.id,
title: dataStructure.title,
type: dataStructure.type,
parent: dataStructure.parent?.id || '',
children: dataStructure.children?.map((child) => child.id) || [],
};
}
76 changes: 52 additions & 24 deletions src/plugins/data/common/datasets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { EuiIconProps } from '@elastic/eui';
export * from './_structure_cache';

/**
* Describes a data source with its properties.
*/
Expand Down Expand Up @@ -116,42 +119,55 @@ export interface DataStructure {
parent?: DataStructure;
/** Optional array of child data structures */
children?: DataStructure[];
hasNext?: boolean;
columnHeader?: string;
/** Optional metadata for the data structure */
meta?: DataStructureMeta;
}

/**
* Metadata for a data structure, used for additional properties like icons or tooltips.
*/
export interface DataStructureMeta {
type: DATA_STRUCTURE_META_TYPES;
}

/**
* DataStructureMeta types
*/
export enum DATA_STRUCTURE_META_TYPES {
FEATURE = 'FEATURE',
TYPE = 'TYPE',
CUSTOM = 'CUSTOM',
}

/**
* Metadata for a data structure, used for additional properties like icons or tooltips.
*/
export interface DataStructureFeatureMeta extends DataStructureMeta {
export interface DataStructureFeatureMeta {
type: DATA_STRUCTURE_META_TYPES.FEATURE;
icon: string;
icon?: string;
tooltip?: string;
}

/**
* Metadata for dataset type
*/
export interface DataStructureDataTypeMeta {
type: DATA_STRUCTURE_META_TYPES.TYPE;
icon: EuiIconProps;
tooltip: string;
}

/**
* Metadata for a data structure with CUSTOM type, allowing any additional fields.
*/
export interface DataStructureCustomMeta extends DataStructureMeta {
export interface DataStructureCustomMeta {
type: DATA_STRUCTURE_META_TYPES.CUSTOM;
[key: string]: any;
}

/**
* Union type for DataStructureMeta
*/
export type DataStructureMeta =
| DataStructureFeatureMeta
| DataStructureDataTypeMeta
| DataStructureCustomMeta;

/**
* Represents a cached version of DataStructure with string references instead of object references.
*
Expand All @@ -168,13 +184,24 @@ export interface DataStructureCustomMeta extends DataStructureMeta {
* ]
* };
*/
export interface CachedDataStructure extends Omit<DataStructure, 'parent' | 'children' | 'meta'> {
export interface CachedDataStructure extends Omit<DataStructure, 'parent' | 'children'> {
/** ID of the parent data structure */
parent: string;
/** Array of child data structure IDs */
children: string[];
}

export interface BaseDataset {
/** Unique identifier for the dataset, for non-index pattern based datasets, we will append the data source ID if present */
id: string;
/** Human-readable name of the dataset that is used to query */
title: string;
/** The type of the dataset, registered by other classes */
type: string;
/** Optional reference to the data source */
dataSource?: DataSource;
}

/**
* Defines the structure of a dataset, including its type and reference to a data source.
* NOTE: For non-index pattern datasets we will append the data source ID to the front of
Expand All @@ -189,10 +216,10 @@ export interface CachedDataStructure extends Omit<DataStructure, 'parent' | 'chi
* 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 All @@ -209,15 +236,16 @@ export interface CachedDataStructure extends Omit<DataStructure, 'parent' | 'chi
* },
* };
*/
export interface Dataset {
/** Unique identifier for the dataset, for non-index pattern based datasets, we will append the data source ID if present */
id: string;
/** Human-readable name of the dataset that is used to query */
title: string;
/** The type of the dataset, registered by other classes */
type: string;
export interface Dataset extends BaseDataset {
/** Optional name of the field used for time-based operations */
timeFieldName?: string;
/** Optional reference to the data source */
dataSource?: DataSource;
/** Optional language to default to from the language selector */
language?: string;
}

export interface DatasetField {
name: string;
type: string;
displayName?: string;
// TODO: osdFieldType?
}
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
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.dataSetManager;
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
Loading
Loading