Skip to content

Commit e56f477

Browse files
Fix #19147 - Executable Test Suites (#19221)
* backend * format & tests * rename backend * migrations and ingestion * format & tests * format & tests * tests * format & tests * tests * updated ui side of changes * addressing comment * fixed failing unit test * fix test list * added e2e test, and fixed existing test --------- Co-authored-by: Shailesh Parmar <[email protected]>
1 parent 15ea84a commit e56f477

File tree

74 files changed

+1053
-494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1053
-494
lines changed
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
-- add timestamp index for test case result reindex performance
2-
ALTER TABLE data_quality_data_time_series ADD INDEX `idx_timestamp_desc` (timestamp DESC);
2+
ALTER TABLE data_quality_data_time_series ADD INDEX `idx_timestamp_desc` (timestamp DESC);
3+
4+
-- rename executable -> basic for test suites
5+
UPDATE test_suite
6+
SET json = JSON_INSERT(
7+
JSON_REMOVE(json, '$.executable'),
8+
'$.basic',
9+
JSON_EXTRACT(json, '$.executable')
10+
)
11+
WHERE JSON_EXTRACT(json, '$.executable') IS NOT NULL;
12+
13+
-- rename executableEntityReference -> basicEntityReference for test suites
14+
UPDATE test_suite
15+
SET json = JSON_INSERT(
16+
JSON_REMOVE(json, '$.executableEntityReference'),
17+
'$.basicEntityReference',
18+
JSON_EXTRACT(json, '$.executableEntityReference')
19+
)
20+
WHERE JSON_EXTRACT(json, '$.executableEntityReference') IS NOT NULL;
21+
22+
-- clean up the testSuites
23+
UPDATE test_case SET json = json_remove(json, '$.testSuites');
24+
25+
-- clean up the testSuites in the version history too
26+
UPDATE entity_extension SET json = json_remove(json, '$.testSuites') WHERE jsonSchema = 'testCase';
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
11
-- add timestamp index for test case result reindex performance
22
CREATE INDEX idx_timestamp_desc ON data_quality_data_time_series (timestamp DESC);
3+
4+
-- rename executable -> basic for test suites
5+
UPDATE test_suite
6+
SET json = jsonb_set(
7+
json::jsonb #- '{executable}',
8+
'{basic}',
9+
(json #> '{executable}')::jsonb,
10+
true
11+
)
12+
WHERE json #>> '{executable}' IS NOT NULL;
13+
14+
-- rename executableEntityReference -> basicEntityReference for test suites
15+
UPDATE test_suite
16+
SET json = jsonb_set(
17+
json::jsonb #- '{executableEntityReference}',
18+
'{basicEntityReference}',
19+
(json #> '{executableEntityReference}')::jsonb,
20+
true
21+
)
22+
WHERE json #>> '{executableEntityReference}' IS NOT NULL;
23+
24+
-- clean up the testSuites
25+
UPDATE test_case SET json = json::jsonb #- '{testSuites}';
26+
27+
-- clean up the testSuites in the version history too
28+
UPDATE entity_extension SET json = json::jsonb #- '{testSuites}' WHERE jsonSchema = 'testCase';

ingestion/src/metadata/data_quality/api/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from metadata.config.common import ConfigModel
2424
from metadata.generated.schema.api.tests.createTestSuite import CreateTestSuiteRequest
2525
from metadata.generated.schema.entity.data.table import Table
26+
from metadata.generated.schema.entity.services.databaseService import DatabaseConnection
2627
from metadata.generated.schema.tests.basic import TestCaseResult
2728
from metadata.generated.schema.tests.testCase import TestCase, TestCaseParameterValue
2829
from metadata.ingestion.models.custom_pydantic import BaseModel
@@ -63,6 +64,9 @@ class TableAndTests(BaseModel):
6364
executable_test_suite: Optional[CreateTestSuiteRequest] = Field(
6465
None, description="If no executable test suite is found, we'll create one"
6566
)
67+
service_connection: DatabaseConnection = Field(
68+
..., description="Service connection for the given table"
69+
)
6670

6771

6872
class TestCaseResults(BaseModel):

ingestion/src/metadata/data_quality/processor/test_case_runner.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from metadata.data_quality.runner.core import DataTestsRunner
2828
from metadata.generated.schema.api.tests.createTestCase import CreateTestCaseRequest
2929
from metadata.generated.schema.entity.data.table import Table
30+
from metadata.generated.schema.entity.services.databaseService import DatabaseConnection
3031
from metadata.generated.schema.entity.services.ingestionPipelines.status import (
3132
StackTraceError,
3233
)
@@ -93,7 +94,9 @@ def _run(self, record: TableAndTests) -> Either:
9394
record.table, openmetadata_test_cases
9495
)
9596

96-
test_suite_runner = self.get_test_suite_runner(record.table)
97+
test_suite_runner = self.get_test_suite_runner(
98+
record.table, record.service_connection
99+
)
97100

98101
logger.debug(
99102
f"Found {len(openmetadata_test_cases)} test cases for table {record.table.fullyQualifiedName.root}"
@@ -351,9 +354,9 @@ def filter_incompatible_test_cases(
351354
result.append(tc)
352355
return result
353356

354-
def get_test_suite_runner(self, table: Table):
357+
def get_test_suite_runner(
358+
self, table: Table, service_connection: DatabaseConnection
359+
):
355360
return BaseTestSuiteRunner(
356-
self.config,
357-
self.metadata,
358-
table,
361+
self.config, self.metadata, table, service_connection
359362
).get_data_quality_runner()

ingestion/src/metadata/data_quality/runner/base_test_suite_source.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ def __init__(
4646
config: OpenMetadataWorkflowConfig,
4747
ometa_client: OpenMetadata,
4848
entity: Table,
49+
service_connection: DatabaseConnection,
4950
):
5051
self.validator_builder_class = ValidatorBuilder
5152
self._interface = None
5253
self.entity = entity
53-
self.service_conn_config = self._copy_service_config(config, self.entity.database) # type: ignore
54+
self.service_conn_config = self._copy_service_config(service_connection, self.entity.database) # type: ignore
5455
self._interface_type: str = self.service_conn_config.type.value.lower()
5556

5657
self.source_config = TestSuitePipeline.model_validate(
@@ -67,7 +68,7 @@ def interface(self, interface):
6768
self._interface = interface
6869

6970
def _copy_service_config(
70-
self, config: OpenMetadataWorkflowConfig, database: EntityReference
71+
self, service_connection: DatabaseConnection, database: EntityReference
7172
) -> DatabaseConnection:
7273
"""Make a copy of the service config and update the database name
7374
@@ -77,9 +78,7 @@ def _copy_service_config(
7778
Returns:
7879
DatabaseService.__config__
7980
"""
80-
config_copy = deepcopy(
81-
config.source.serviceConnection.root.config # type: ignore
82-
)
81+
config_copy = deepcopy(service_connection.config) # type: ignore
8382
if hasattr(
8483
config_copy, # type: ignore
8584
"supportsDatabase",

0 commit comments

Comments
 (0)