-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Feature/dimensionality column min to be between #24116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
2491946
Initial implementation for Dimensionality on Data Quality Tests
IceS2 a6c5db0
Merge branch 'main' into feature/dimensionality-for-data-quality
IceS2 7285db4
Fix ColumnValuesToBeUnique and create TestCaseResult API
IceS2 64cbe81
Refactor dimension result
IceS2 f6e6c6a
Merge branch 'main' into feature/dimensionality-for-data-quality
IceS2 f3bab32
Initial E2E Implementation without Impact Score
IceS2 3883047
Merge branch 'main' into feature/dimensionality-for-data-quality
IceS2 c403feb
Dimensionality Thin Slice
IceS2 afbd8da
Update generated TypeScript types
github-actions[bot] 604870e
Merge branch 'main' into feature/dimensionality-for-data-quality
IceS2 60321af
Update generated TypeScript types
github-actions[bot] 03ede24
Removed useless method to use the one we already had
IceS2 6ea9c2d
Fix Pandas Dimensionality checks
IceS2 b94c1d3
Remove useless comments
IceS2 9d811ba
Merge branch 'main' into feature/dimensionality-for-data-quality
IceS2 69c28fa
Merge branch 'main' into feature/dimensionality-for-data-quality
IceS2 926f845
Implement PR comments, fix Tests
IceS2 15a33b7
Merge branch 'feature/dimensionality-for-data-quality' of github.com:…
IceS2 00776b0
Merge branch 'main' into feature/dimensionality-for-data-quality
IceS2 3eb5e91
Improve the code a bit
IceS2 dbae901
Merge branch 'main' into feature/dimensionality-for-data-quality
IceS2 bfbac4d
Fix imports
IceS2 517b53c
Merge branch 'main' into feature/dimensionality-for-data-quality
IceS2 0b33546
Implement Dimensionality for ColumnMeanToBeBetween
IceS2 25f96f6
Merge branch 'main' into feature/dimensionality-column-mean-to-be-bet…
IceS2 aa257fd
Removed useless comments and improved minor things
IceS2 812cb57
Implement UnitTests
IceS2 b4fffc4
Merge branch 'main' into feature/dimensionality-column-mean-to-be-bet…
IceS2 8487b56
Fixes
IceS2 89e0e28
Merge branch 'feature/dimensionality-column-mean-to-be-between' of gi…
IceS2 5fac5e9
Moved import pandas to type checking
IceS2 70108e5
Fix Min/Max being optional
IceS2 e8922e1
Fix Unittests
IceS2 8dcf12c
small fixes
IceS2 5e0a7ad
Fix Unittests
IceS2 426e32e
Fix Issue with counting total rows on mean
IceS2 dc0b48f
Improve code
IceS2 0f2bf63
Merge branch 'main' into feature/dimensionality-column-max-to-be-between
IceS2 2a221a2
Fix Merge
IceS2 80d4f4e
Removed unused type
IceS2 1bebe26
Merge branch 'main' into feature/dimensionality-column-max-to-be-between
IceS2 284fb45
Refactor to reduce code repetition and complexity
IceS2 6fdcfdb
Merge branch 'main' into feature/dimensionality-column-min-to-be-between
IceS2 91bae70
Fix conflict
IceS2 7a1be5e
Rename method
IceS2 2ff148b
Refactor some metrics
IceS2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
ingestion/src/metadata/data_quality/validations/checkers/base_checker.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # 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. | ||
|
|
||
| """ | ||
| Base Checker abstract class. | ||
| Should be extended to implement different validation checkers that are used to define if a given data quality test passes or fails. | ||
| """ | ||
| from abc import ABC, abstractmethod | ||
| from typing import Any, Callable | ||
|
|
||
|
|
||
| class BaseValidationChecker(ABC): | ||
| """Base Checker Abstract Class""" | ||
|
|
||
| @abstractmethod | ||
| def check_pandas(self, value: Any) -> bool: | ||
| """Check if value violates condition. Used for Pandas Data Quality""" | ||
|
|
||
| @abstractmethod | ||
| def get_sqa_failed_rows_builder( | ||
| self, metric_col_name: str, total_count_col_name: str | ||
| ) -> Callable: | ||
| """Build SQLAlchemy Failed Rows expression""" | ||
66 changes: 66 additions & 0 deletions
66
ingestion/src/metadata/data_quality/validations/checkers/between_bounds_checker.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # 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. | ||
|
|
||
| """ | ||
| BetweenBoundsChecker implements the checker for any metric that should be between two bounds | ||
| """ | ||
| import math | ||
| from typing import Any, Callable | ||
|
|
||
| from metadata.data_quality.validations.checkers.base_checker import ( | ||
| BaseValidationChecker, | ||
| ) | ||
|
|
||
|
|
||
| class BetweenBoundsChecker(BaseValidationChecker): | ||
| """Checks if value is outside [min_bound, max_bound]""" | ||
|
|
||
| def __init__(self, min_bound: float, max_bound: float): | ||
| self.min_bound = min_bound | ||
| self.max_bound = max_bound | ||
|
|
||
| def check_pandas(self, value: Any) -> bool: | ||
| """Check if value is outside [min_bound, max_bound]. Used on Pandas Data Quality.""" | ||
| import pandas as pd | ||
|
|
||
| if value is None or pd.isna(value): | ||
| return False | ||
|
|
||
| return not (self.min_bound <= value <= self.max_bound) | ||
|
|
||
| def get_sqa_failed_rows_builder( | ||
| self, metric_col_name: str, total_count_col_name: str | ||
| ) -> Callable: | ||
| """Builds SQA Failed Rows Expression. If metric is outside bounds, failed rows count = total rows count. Else, failed rows count = 0.""" | ||
| from sqlalchemy import case, literal, or_ | ||
|
|
||
| def build_sqa_failed_rows_expression(cte): | ||
| conditions = [] | ||
| metric_col = getattr(cte.c, metric_col_name) | ||
| total_count_col = getattr(cte.c, total_count_col_name) | ||
|
|
||
| if not math.isinf(self.min_bound): | ||
| conditions.append(metric_col < self.min_bound) | ||
| if not math.isinf(self.max_bound): | ||
| conditions.append(metric_col > self.max_bound) | ||
|
|
||
| if not conditions: | ||
| return literal(0) | ||
|
|
||
| violation = or_(*conditions) if len(conditions) > 1 else conditions[0] | ||
|
|
||
| return case( | ||
| (metric_col.is_(None), literal(0)), | ||
| (violation, total_count_col), | ||
| else_=literal(0), | ||
| ) | ||
|
|
||
| return build_sqa_failed_rows_expression |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in
BaseTestValidatoror are you thinking to just use it for that new Between object?