Skip to content

Commit

Permalink
[Discover] Update async search response type (#8781)
Browse files Browse the repository at this point in the history
* update async search reponse type

Signed-off-by: Shenoy Pratik <[email protected]>

* Changeset file for PR #8781 created/updated

* remove explicit type declaration

Signed-off-by: Shenoy Pratik <[email protected]>

---------

Signed-off-by: Shenoy Pratik <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
ps48 and opensearch-changeset-bot[bot] authored Nov 1, 2024
1 parent e11b401 commit affd265
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8781.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- Update async search response type ([#8781](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8781))
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ export const pplAsyncSearchStrategyProvider = (
} as IDataFrameResponse;
} else {
request.params = { queryId: inProgressQueryId };
const queryStatusResponse: any = await pplAsyncJobsFacet.describeQuery(context, request);
const queryStatusResponse = await pplAsyncJobsFacet.describeQuery(context, request);

if (!queryStatusResponse.success) handleFacetError(queryStatusResponse);

const queryStatus = queryStatusResponse?.data?.status;
const queryStatus = queryStatusResponse.data?.status;
logger.info(`pplAsyncSearchStrategy: JOB: ${inProgressQueryId} - STATUS: ${queryStatus}`);

if (queryStatus?.toUpperCase() === 'SUCCESS') {
const dataFrame = createDataFrame({
name: query.dataset?.id,
schema: queryStatusResponse.data.schema,
schema: queryStatusResponse.data?.schema,
meta: { ...pollQueryResultsParams },
fields: getFields(queryStatusResponse),
});

dataFrame.size = queryStatusResponse.data.datarows.length;
dataFrame.size = queryStatusResponse.data?.datarows.length;

return {
type: DATA_FRAME_TYPES.POLLING,
Expand All @@ -85,7 +85,7 @@ export const pplAsyncSearchStrategyProvider = (
type: DATA_FRAME_TYPES.POLLING,
status: 'failed',
body: {
error: `JOB: ${inProgressQueryId} failed: ${queryStatusResponse.data.error}`,
error: `JOB: ${inProgressQueryId} failed: ${queryStatusResponse.data?.error}`,
},
} as IDataFrameResponse;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { SharedGlobalConfig, Logger, ILegacyClusterClient } from 'opensearch-dashboards/server';
import { ILegacyClusterClient, Logger, SharedGlobalConfig } from 'opensearch-dashboards/server';
import { Observable } from 'rxjs';
import { ISearchStrategy, SearchUsage } from '../../../data/server';
import {
createDataFrame,
DATA_FRAME_TYPES,
IDataFrameResponse,
IOpenSearchDashboardsSearchRequest,
Query,
createDataFrame,
} from '../../../data/common';
import { Facet } from '../utils';
import { ISearchStrategy, SearchUsage } from '../../../data/server';
import { buildQueryStatusConfig, getFields, handleFacetError, SEARCH_STRATEGY } from '../../common';
import { Facet } from '../utils';

export const sqlAsyncSearchStrategyProvider = (
config$: Observable<SharedGlobalConfig>,
Expand Down Expand Up @@ -58,22 +58,22 @@ export const sqlAsyncSearchStrategyProvider = (
} as IDataFrameResponse;
} else {
request.params = { queryId: inProgressQueryId };
const queryStatusResponse: any = await sqlAsyncJobsFacet.describeQuery(context, request);
const queryStatusResponse = await sqlAsyncJobsFacet.describeQuery(context, request);

if (!queryStatusResponse.success) handleFacetError(queryStatusResponse);

const queryStatus = queryStatusResponse?.data?.status;
const queryStatus = queryStatusResponse.data?.status;
logger.info(`sqlAsyncSearchStrategy: JOB: ${inProgressQueryId} - STATUS: ${queryStatus}`);

if (queryStatus?.toUpperCase() === 'SUCCESS') {
const dataFrame = createDataFrame({
name: query.dataset?.id,
schema: queryStatusResponse.data.schema,
schema: queryStatusResponse.data?.schema,
meta: { ...pollQueryResultsParams },
fields: getFields(queryStatusResponse),
});

dataFrame.size = queryStatusResponse.data.datarows.length;
dataFrame.size = queryStatusResponse.data?.datarows.length;

return {
type: DATA_FRAME_TYPES.POLLING,
Expand All @@ -85,7 +85,7 @@ export const sqlAsyncSearchStrategyProvider = (
type: DATA_FRAME_TYPES.POLLING,
status: 'failed',
body: {
error: `JOB: ${inProgressQueryId} failed: ${queryStatusResponse.data.error}`,
error: `JOB: ${inProgressQueryId} failed: ${queryStatusResponse.data?.error}`,
},
} as IDataFrameResponse;
}
Expand Down

0 comments on commit affd265

Please sign in to comment.