Skip to content

Commit

Permalink
need to still fix the aggregations
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Aug 25, 2024
1 parent 19a00be commit fef3163
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 51 deletions.
2 changes: 1 addition & 1 deletion src/plugins/data/common/data_frames/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ export const updateDataFrameMeta = ({
getAggQsFn: GetDataFrameAggQsFn;
}) => {
dataFrame.meta = {
...dataFrame.meta,
...dataFrame?.meta,
aggs: aggConfig,
aggsQs: {
[aggConfig.id]: getAggQsFn({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
*/

import { CoreStart, SavedObjectsClientContract } from 'opensearch-dashboards/public';
import { Dataset, DataStructure, IndexPatternSpec, DEFAULT_DATA } from '../../../../common';
import {
Dataset,
DataStructure,
IndexPatternSpec,
DEFAULT_DATA,
IFieldType,
} from '../../../../common';
import { getIndexPatterns } from '../../../services';
import { DatasetTypeConfig } from './types';
import { indexPatternTypeConfig, indexTypeConfig } from './lib';
Expand Down Expand Up @@ -49,7 +55,12 @@ export class DatasetService {
const type = this.getType(dataset.type);
if (dataset) {
const spec = {
...dataset,
id: dataset.id,
title: dataset.title,
timeFieldName: {
name: dataset.timeFieldName,
type: 'date',
} as Partial<IFieldType>,
fields: await type?.fetchFields(dataset),
dataSourceRef: dataset.dataSource
? {
Expand All @@ -59,7 +70,7 @@ export class DatasetService {
}
: undefined,
} as IndexPatternSpec;
const temporaryIndexPattern = await getIndexPatterns().create(spec, true);
const temporaryIndexPattern = await getIndexPatterns().create(spec);
getIndexPatterns().saveToCache(dataset.id, temporaryIndexPattern);
}
}
Expand Down
10 changes: 0 additions & 10 deletions src/plugins/data/public/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import {
IDataFrame,
IDataFrameResponse,
createDataFrameCache,
dataFrameToSpec,
} from '../../common/data_frames';
import { getQueryService, getUiService } from '../services';
import { UI_SETTINGS } from '../../common';
Expand Down Expand Up @@ -159,16 +158,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
const dfService: DataFrameService = {
get: () => this.dfCache.get(),
set: async (dataFrame: IDataFrame) => {
if (this.dfCache.get() && this.dfCache.get()?.name !== dataFrame.name) {
indexPatterns.clearCache(this.dfCache.get()!.name, false);
}
this.dfCache.set(dataFrame);
const existingIndexPattern = await indexPatterns.get(dataFrame.name!, true);
const dataset = await indexPatterns.create(
dataFrameToSpec(dataFrame, existingIndexPattern?.id),
!existingIndexPattern?.id
);
indexPatterns.saveToCache(dataset.id!, dataset);
},
clear: () => {
if (this.dfCache.get() === undefined) return;
Expand Down
10 changes: 0 additions & 10 deletions src/plugins/data/server/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ import {
IDataFrame,
IDataFrameResponse,
createDataFrameCache,
dataFrameToSpec,
} from '../../common';

type StrategyMap = Record<string, ISearchStrategy<any, any>>;
Expand Down Expand Up @@ -215,16 +214,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
const dfService: DataFrameService = {
get: () => this.dfCache.get(),
set: async (dataFrame: IDataFrame) => {
if (this.dfCache.get() && this.dfCache.get()?.name !== dataFrame.name) {
scopedIndexPatterns.clearCache(this.dfCache.get()!.name, false);
}
this.dfCache.set(dataFrame);
const existingIndexPattern = await scopedIndexPatterns.get(dataFrame.name!, true);
const dataset = await scopedIndexPatterns.create(
dataFrameToSpec(dataFrame, existingIndexPattern?.id),
!existingIndexPattern?.id
);
scopedIndexPatterns.saveToCache(dataset.id!, dataset);
},
clear: () => {
if (this.dfCache.get() === undefined) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,10 @@ export const updateSearchSource = async ({
const { uiSettings, data } = services;
const queryDataset = data.query.queryString.getQuery().dataset;

let dataset =
const dataset =
indexPattern.id === queryDataset?.id
? await data.indexPatterns.get(queryDataset?.id!, true)
: indexPattern;
const dataFrame = searchSource?.getDataFrame();
if (
searchSource &&
dataFrame &&
dataFrame.name &&
dataFrame.name !== '' &&
dataset.title !== dataFrame.name
) {
dataset = data.indexPatterns.getByTitle(dataFrame.name, true) ?? dataset;
searchSource.setField('index', dataset);
}

const sortForSearchSource = getSortForSearchSource(
sort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,14 @@ export class PPLSearchInterceptor extends SearchInterceptor {
const dataFrame = getRawDataFrame(searchRequest);
const query = this.queryService.queryString.getQuery();
const timeField = query.dataset?.timeFieldName;
const aggConfig = dataFrame.meta?.aggConfig;
const aggConfig = dataFrame?.meta?.aggConfig;
if (timeField && aggConfig) {
const timeFilter = getTimeFilter(timeField);
const newQuery = insertTimeFilter(query.query as string, timeFilter);
updateDataFrameMeta({
dataFrame,
query: { ...query, query: newQuery },
aggConfig: dataFrame.meta?.aggConfig,
aggConfig: dataFrame?.meta?.aggConfig,
timeField,
timeFilter,
getAggQsFn: getAggQsFn.bind(this),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ export class SQLSearchInterceptor extends SearchInterceptor {
};

const dataFrame = getRawDataFrame(searchRequest);
if (!dataFrame) {
return throwError(this.handleSearchError('DataFrame is not defined', request, signal!));
}
const query = this.queryService.queryString.getQuery();

const dataSourceRef = query.dataset
Expand All @@ -85,9 +82,9 @@ export class SQLSearchInterceptor extends SearchInterceptor {
: {};

dataFrame.meta = {
...dataFrame.meta,
...dataFrame?.meta,
queryConfig: {
...dataFrame.meta.queryConfig,
...dataFrame?.meta.queryConfig,
...dataSourceRef,
},
sessionId: dataSourceRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ export const pplSearchStrategyProvider = (

try {
const query: Query = request.body.query;
const {
df: { meta },
} = request.body;
const { df } = request.body;

const rawResponse: any = await pplFacet.describeQuery(context, request);

Expand All @@ -84,16 +82,16 @@ export const pplSearchStrategyProvider = (
const dataFrame = createDataFrame({
name: query.dataset?.id,
schema: rawResponse.data.schema,
meta,
meta: df?.meta,
fields: getFields(rawResponse),
});

dataFrame.size = rawResponse.data.datarows.length;

if (usage) usage.trackSuccess(rawResponse.took);

if (dataFrame.meta?.aggsQs) {
for (const [key, aggQueryString] of Object.entries(dataFrame.meta.aggsQs)) {
if (dataFrame?.meta?.aggsQs) {
for (const [key, aggQueryString] of Object.entries(dataFrame?.meta?.aggsQs)) {
const aggRequest = parseRequest(aggQueryString as string);
request.body.query = aggRequest.aggs;
const rawAggs: any = await pplFacet.describeQuery(context, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const sqlAsyncSearchStrategyProvider = (
};
const dataFrame = createDataFrame(partial);
dataFrame.meta = {
...dataFrame.meta,
...dataFrame?.meta,
query: query.query,
queryId,
sessionId,
Expand Down Expand Up @@ -95,7 +95,7 @@ export const sqlAsyncSearchStrategyProvider = (
dataFrame.size = asyncResponse?.data?.datarows?.length || 0;

dataFrame.meta = {
...dataFrame.meta,
...dataFrame?.meta,
status,
queryId,
error: status === 'FAILED' && asyncResponse.data?.error,
Expand Down

0 comments on commit fef3163

Please sign in to comment.