From 37430d4b03889712eccee9daf04446d3c1cfd492 Mon Sep 17 00:00:00 2001 From: Shailesh Parmar Date: Mon, 9 Dec 2024 21:08:46 +0530 Subject: [PATCH] minor: added entity type support in dq dashboard API --- .../DataQuality/DataQualityPage.interface.ts | 7 +- .../src/rest/dataQualityDashboardAPI.test.ts | 80 +++++++++++++++++++ .../ui/src/rest/dataQualityDashboardAPI.ts | 4 +- 3 files changed, 88 insertions(+), 3 deletions(-) diff --git a/openmetadata-ui/src/main/resources/ui/src/pages/DataQuality/DataQualityPage.interface.ts b/openmetadata-ui/src/main/resources/ui/src/pages/DataQuality/DataQualityPage.interface.ts index 9f8201b3320c..17ed29461b78 100644 --- a/openmetadata-ui/src/main/resources/ui/src/pages/DataQuality/DataQualityPage.interface.ts +++ b/openmetadata-ui/src/main/resources/ui/src/pages/DataQuality/DataQualityPage.interface.ts @@ -1,5 +1,3 @@ -import { TestSummary } from '../../generated/tests/testCase'; - /* * Copyright 2023 Collate. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,6 +10,10 @@ import { TestSummary } from '../../generated/tests/testCase'; * See the License for the specific language governing permissions and * limitations under the License. */ + +import { EntityType } from '../../enums/entity.enum'; +import { TestSummary } from '../../generated/tests/testCase'; + export enum DataQualityPageTabs { TEST_SUITES = 'test-suites', TABLES = 'tables', @@ -32,4 +34,5 @@ export type DataQualityDashboardChartFilters = { startTs?: number; endTs?: number; entityFQN?: string; + entityType?: EntityType; }; diff --git a/openmetadata-ui/src/main/resources/ui/src/rest/dataQualityDashboardAPI.test.ts b/openmetadata-ui/src/main/resources/ui/src/rest/dataQualityDashboardAPI.test.ts index e2375f6d9851..818f41fa7524 100644 --- a/openmetadata-ui/src/main/resources/ui/src/rest/dataQualityDashboardAPI.test.ts +++ b/openmetadata-ui/src/main/resources/ui/src/rest/dataQualityDashboardAPI.test.ts @@ -12,6 +12,7 @@ */ /* eslint-disable max-len */ import { IncidentTimeMetricsType } from '../components/DataQuality/DataQuality.interface'; +import { EntityType } from '../enums/entity.enum'; import { TestCaseStatus } from '../generated/tests/testCase'; import { TestCaseResolutionStatusTypes } from '../generated/tests/testCaseResolutionStatus'; import { @@ -1209,5 +1210,84 @@ describe('dataQualityDashboardAPI', () => { 'bucketName=byDay:aggType=date_histogram:field=timestamp&calendar_interval=day,bucketName=newIncidents:aggType=cardinality:field=testCase.fullyQualifiedName', }); }); + + it('should call getDataQualityReport with provided entityType', async () => { + const status = TestCaseStatus.Success; + const filters = { + entityType: EntityType.TABLE, + entityFQN: 'entityFQN', + startTs: 1729073964962, + endTs: 1729678764965, + }; + + await fetchTestCaseStatusMetricsByDays(status, filters); + + expect(getDataQualityReport).toHaveBeenCalledWith({ + q: JSON.stringify({ + query: { + bool: { + must: [ + { term: { testCaseStatus: status } }, + { + range: { + timestamp: { + lte: filters.endTs, + gte: filters.startTs, + }, + }, + }, + { + term: { + 'table.fullyQualifiedName.keyword': 'entityFQN', + }, + }, + ], + }, + }, + }), + index: 'testCaseResult', + aggregationQuery: + 'bucketName=byDay:aggType=date_histogram:field=timestamp&calendar_interval=day,bucketName=newIncidents:aggType=cardinality:field=testCase.fullyQualifiedName', + }); + }); + + it('should call getDataQualityReport with normal entity fqn if entityType not provided', async () => { + const status = TestCaseStatus.Success; + const filters = { + entityFQN: 'entityFQN', + startTs: 1729073964962, + endTs: 1729678764965, + }; + + await fetchTestCaseStatusMetricsByDays(status, filters); + + expect(getDataQualityReport).toHaveBeenCalledWith({ + q: JSON.stringify({ + query: { + bool: { + must: [ + { term: { testCaseStatus: status } }, + { + range: { + timestamp: { + lte: filters.endTs, + gte: filters.startTs, + }, + }, + }, + { + term: { + 'testCase.entityFQN': 'entityFQN', + }, + }, + ], + }, + }, + }), + index: 'testCaseResult', + aggregationQuery: + 'bucketName=byDay:aggType=date_histogram:field=timestamp&calendar_interval=day,bucketName=newIncidents:aggType=cardinality:field=testCase.fullyQualifiedName', + }); + }); }); }); diff --git a/openmetadata-ui/src/main/resources/ui/src/rest/dataQualityDashboardAPI.ts b/openmetadata-ui/src/main/resources/ui/src/rest/dataQualityDashboardAPI.ts index 00c33debb421..530e0cfef760 100644 --- a/openmetadata-ui/src/main/resources/ui/src/rest/dataQualityDashboardAPI.ts +++ b/openmetadata-ui/src/main/resources/ui/src/rest/dataQualityDashboardAPI.ts @@ -317,7 +317,9 @@ export const fetchTestCaseStatusMetricsByDays = ( if (filters?.entityFQN) { mustFilter.push({ term: { - 'testCase.entityFQN': filters.entityFQN, + [filters.entityType + ? `${filters.entityType}.fullyQualifiedName.keyword` + : 'testCase.entityFQN']: filters.entityFQN, }, }); }