From ef41382cb19b6830bcdb884e656210e84e6ddce6 Mon Sep 17 00:00:00 2001 From: Teddy Date: Wed, 31 Aug 2022 21:35:33 +0200 Subject: [PATCH] Fixes #7094 by fixing minior bugs in table tests (#7095) --- .../data/tests/tableRowCountToBeBetween.json | 8 ++++---- .../src/metadata/test_suite/validations/core.py | 2 +- .../validations/table/table_custom_sql_query.py | 17 ++++++++++++++--- .../tests/unit/test_suite/test_validations.py | 4 ++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/catalog-rest-service/src/main/resources/json/data/tests/tableRowCountToBeBetween.json b/catalog-rest-service/src/main/resources/json/data/tests/tableRowCountToBeBetween.json index c788344bd56..bfac45e8441 100644 --- a/catalog-rest-service/src/main/resources/json/data/tests/tableRowCountToBeBetween.json +++ b/catalog-rest-service/src/main/resources/json/data/tests/tableRowCountToBeBetween.json @@ -6,14 +6,14 @@ "testPlatforms": ["OpenMetadata", "GreatExpectations"], "parameterDefinition": [ { - "name": "minColValue", - "displayName": "minColValue", + "name": "minValue", + "displayName": "minValue", "description": "Expected number of columns should be greater than or equal to {minValue}. If minValue is not included, maxValue is treated as upperBound and there will be no minimum number of column", "dataType": "INT" }, { - "name": "maxColValue", - "displayName": "maxColValue", + "name": "maxValue", + "displayName": "maxValue", "description": "Expected number of columns should be less than or equal to {maxValue}. If maxValue is not included, minValue is treated as lowerBound and there will be no maximum number of column", "dataType": "INT" } diff --git a/ingestion/src/metadata/test_suite/validations/core.py b/ingestion/src/metadata/test_suite/validations/core.py index 50c6d776e12..dfc0fa0a866 100644 --- a/ingestion/src/metadata/test_suite/validations/core.py +++ b/ingestion/src/metadata/test_suite/validations/core.py @@ -103,7 +103,7 @@ validation_enum_registry.add("TableColumnCountToBeBetween")( ) validation_enum_registry.add("TableColumnToMatchSet")(table_column_to_match_set) validation_enum_registry.add("TableColumnNameToExist")(table_column_name_to_exist) -validation_enum_registry.add("TableCustomSQLQuery")(table_custom_sql_query) +validation_enum_registry.add("tableCustomSQLQuery")(table_custom_sql_query) # # Column Tests validation_enum_registry.add("columnValuesToBeBetween")(column_values_to_be_between) diff --git a/ingestion/src/metadata/test_suite/validations/table/table_custom_sql_query.py b/ingestion/src/metadata/test_suite/validations/table/table_custom_sql_query.py index 46e1789b7b5..c61aa3fd510 100644 --- a/ingestion/src/metadata/test_suite/validations/table/table_custom_sql_query.py +++ b/ingestion/src/metadata/test_suite/validations/table/table_custom_sql_query.py @@ -72,12 +72,23 @@ def table_custom_sql_query( testResultValue=[TestResultValue(name="resultRowCount", value=None)], ) - status = TestCaseStatus.Success if not rows else TestCaseStatus.Failed - result = f"Found {len(rows)} row(s). Test query is expected to return 0 row." + if not rows: + status = TestCaseStatus.Success + result_value = 0 + elif len(rows) == 1: + status = TestCaseStatus.Success if rows[0].count == 0 else TestCaseStatus.Failed + result_value = rows[0].count + else: + status = TestCaseStatus.Failed + result_value = len(rows) + + result = f"Found {result_value} row(s). Test query is expected to return 0 row." return TestCaseResult( timestamp=execution_date, testCaseStatus=status, result=result, - testResultValue=[TestResultValue(name="resultRowCount", value=str(len(rows)))], + testResultValue=[ + TestResultValue(name="resultRowCount", value=str(result_value)) + ], ) diff --git a/ingestion/tests/unit/test_suite/test_validations.py b/ingestion/tests/unit/test_suite/test_validations.py index fe094cced2e..3b63139fe14 100644 --- a/ingestion/tests/unit/test_suite/test_validations.py +++ b/ingestion/tests/unit/test_suite/test_validations.py @@ -614,7 +614,7 @@ class testSuiteValidation(unittest.TestCase): ], ) - res = validation_enum_registry.registry["TableCustomSQLQuery"]( + res = validation_enum_registry.registry["tableCustomSQLQuery"]( test_case=test_case, execution_date=EXECUTION_DATE.timestamp(), runner=self.runner, @@ -636,7 +636,7 @@ class testSuiteValidation(unittest.TestCase): ], ) - res = validation_enum_registry.registry["TableCustomSQLQuery"]( + res = validation_enum_registry.registry["tableCustomSQLQuery"]( test_case=test_case, execution_date=EXECUTION_DATE.timestamp(), runner=self.runner,