-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathtableColumnCountToBeBetween.py
More file actions
69 lines (56 loc) · 2.46 KB
/
tableColumnCountToBeBetween.py
File metadata and controls
69 lines (56 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright 2025 Collate
# Licensed under the Collate Community License, Version 1.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# https://github.com/open-metadata/OpenMetadata/blob/main/ingestion/LICENSE
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Validator for table column count to be between test case
"""
import traceback
from abc import abstractmethod
from metadata.data_quality.validations.base_test_handler import BaseTestValidator
from metadata.generated.schema.tests.basic import (
TestCaseResult,
TestCaseStatus,
TestResultValue,
)
from metadata.utils.logger import test_suite_logger
logger = test_suite_logger()
COLUMN_COUNT = "columnCount"
class BaseTableColumnCountToBeBetweenValidator(BaseTestValidator):
"""Validator for table column count to be between test case"""
def _run_validation(self) -> TestCaseResult:
"""Execute the specific test validation logic
This method contains the core validation logic that was previously
in the run_validation method.
Returns:
TestCaseResult: The test case result for the overall validation
"""
try:
count = self._run_results()
except Exception as exc:
msg = f"Error computing {self.test_case.fullyQualifiedName}: {exc}" # type: ignore
logger.debug(traceback.format_exc())
logger.error(msg)
return self.get_test_case_result_object(
self.execution_date,
TestCaseStatus.Aborted,
msg,
[TestResultValue(name=COLUMN_COUNT, value=None)],
)
min_bound = self.get_min_bound("minColValue")
max_bound = self.get_max_bound("maxColValue")
return self.get_test_case_result_object(
self.execution_date,
self.get_test_case_status(min_bound <= count <= max_bound),
f"Found columnCount={count} column vs. the expected min={min_bound} and max={max_bound}].",
[TestResultValue(name=COLUMN_COUNT, value=str(count))],
)
@abstractmethod
def _run_results(self):
raise NotImplementedError