-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
feat(cli/datacontract): Add data quality assertion support #8968
Merged
asikowitz
merged 12 commits into
datahub-project:master
from
asikowitz:enhance-data-contract-cli
Oct 13, 2023
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
76746b2
feat(cli/datacontract): Add data quality assertion support
asikowitz b65b69a
add back description
asikowitz ef5855e
add test
asikowitz 2a53f02
Merge branch 'master' into enhance-data-contract-cli
asikowitz 6e565c0
lint
asikowitz 71b5af4
feat(ingest): incremental lineage source helper (#8941)
mayurinehate 3d48469
feat(ingest): refactor + simplify incremental lineage helper (#8976)
mayurinehate ae2caec
fix(lint): run black, isort (#8978)
anshbansal 48699a5
fix(setup): drop older table if exists (#8979)
anshbansal 8aca704
feat(ingest/tableau): Allow parsing of database name from fullName (#…
asikowitz 1f79baa
fix description
asikowitz 333901f
Merge branch 'master' into enhance-data-contract-cli
hsheth2 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
7 changes: 7 additions & 0 deletions
7
metadata-ingestion/src/datahub/api/entities/datacontract/assertion.py
This file contains 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,7 @@ | ||
from typing import Optional | ||
|
||
from datahub.configuration import ConfigModel | ||
|
||
|
||
class BaseAssertion(ConfigModel): | ||
description: Optional[str] = None |
162 changes: 162 additions & 0 deletions
162
metadata-ingestion/src/datahub/api/entities/datacontract/assertion_operator.py
This file contains 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,162 @@ | ||
from typing import Optional, Union | ||
|
||
from typing_extensions import Literal, Protocol | ||
|
||
from datahub.configuration import ConfigModel | ||
from datahub.metadata.schema_classes import ( | ||
AssertionStdOperatorClass, | ||
AssertionStdParameterClass, | ||
AssertionStdParametersClass, | ||
AssertionStdParameterTypeClass, | ||
) | ||
|
||
|
||
class Operator(Protocol): | ||
"""Specification for an assertion operator. | ||
|
||
This class exists only for documentation (not used in typing checking). | ||
""" | ||
|
||
operator: str | ||
|
||
def id(self) -> str: | ||
... | ||
|
||
def generate_parameters(self) -> AssertionStdParametersClass: | ||
... | ||
|
||
|
||
def _generate_assertion_std_parameter( | ||
value: Union[str, int, float] | ||
) -> AssertionStdParameterClass: | ||
if isinstance(value, str): | ||
return AssertionStdParameterClass( | ||
value=value, type=AssertionStdParameterTypeClass.STRING | ||
) | ||
elif isinstance(value, (int, float)): | ||
return AssertionStdParameterClass( | ||
value=str(value), type=AssertionStdParameterTypeClass.NUMBER | ||
) | ||
else: | ||
raise ValueError( | ||
f"Unsupported assertion parameter {value} of type {type(value)}" | ||
) | ||
|
||
|
||
Param = Union[str, int, float] | ||
|
||
|
||
def _generate_assertion_std_parameters( | ||
value: Optional[Param] = None, | ||
min_value: Optional[Param] = None, | ||
max_value: Optional[Param] = None, | ||
) -> AssertionStdParametersClass: | ||
return AssertionStdParametersClass( | ||
value=_generate_assertion_std_parameter(value) if value else None, | ||
minValue=_generate_assertion_std_parameter(min_value) if min_value else None, | ||
maxValue=_generate_assertion_std_parameter(max_value) if max_value else None, | ||
) | ||
|
||
|
||
class EqualToOperator(ConfigModel): | ||
type: Literal["equal_to"] | ||
value: Union[str, int, float] | ||
|
||
operator: str = AssertionStdOperatorClass.EQUAL_TO | ||
|
||
def id(self) -> str: | ||
return f"{self.type}-{self.value}" | ||
|
||
def generate_parameters(self) -> AssertionStdParametersClass: | ||
return _generate_assertion_std_parameters(value=self.value) | ||
|
||
|
||
class BetweenOperator(ConfigModel): | ||
type: Literal["between"] | ||
min: Union[int, float] | ||
max: Union[int, float] | ||
|
||
operator: str = AssertionStdOperatorClass.BETWEEN | ||
|
||
def id(self) -> str: | ||
return f"{self.type}-{self.min}-{self.max}" | ||
|
||
def generate_parameters(self) -> AssertionStdParametersClass: | ||
return _generate_assertion_std_parameters( | ||
min_value=self.min, max_value=self.max | ||
) | ||
|
||
|
||
class LessThanOperator(ConfigModel): | ||
type: Literal["less_than"] | ||
value: Union[int, float] | ||
|
||
operator: str = AssertionStdOperatorClass.LESS_THAN | ||
|
||
def id(self) -> str: | ||
return f"{self.type}-{self.value}" | ||
|
||
def generate_parameters(self) -> AssertionStdParametersClass: | ||
return _generate_assertion_std_parameters(value=self.value) | ||
|
||
|
||
class GreaterThanOperator(ConfigModel): | ||
type: Literal["greater_than"] | ||
value: Union[int, float] | ||
|
||
operator: str = AssertionStdOperatorClass.GREATER_THAN | ||
|
||
def id(self) -> str: | ||
return f"{self.type}-{self.value}" | ||
|
||
def generate_parameters(self) -> AssertionStdParametersClass: | ||
return _generate_assertion_std_parameters(value=self.value) | ||
|
||
|
||
class LessThanOrEqualToOperator(ConfigModel): | ||
type: Literal["less_than_or_equal_to"] | ||
value: Union[int, float] | ||
|
||
operator: str = AssertionStdOperatorClass.LESS_THAN_OR_EQUAL_TO | ||
|
||
def id(self) -> str: | ||
return f"{self.type}-{self.value}" | ||
|
||
def generate_parameters(self) -> AssertionStdParametersClass: | ||
return _generate_assertion_std_parameters(value=self.value) | ||
|
||
|
||
class GreaterThanOrEqualToOperator(ConfigModel): | ||
type: Literal["greater_than_or_equal_to"] | ||
value: Union[int, float] | ||
|
||
operator: str = AssertionStdOperatorClass.GREATER_THAN_OR_EQUAL_TO | ||
|
||
def id(self) -> str: | ||
return f"{self.type}-{self.value}" | ||
|
||
def generate_parameters(self) -> AssertionStdParametersClass: | ||
return _generate_assertion_std_parameters(value=self.value) | ||
|
||
|
||
class NotNullOperator(ConfigModel): | ||
type: Literal["not_null"] | ||
|
||
operator: str = AssertionStdOperatorClass.NOT_NULL | ||
|
||
def id(self) -> str: | ||
return f"{self.type}" | ||
|
||
def generate_parameters(self) -> AssertionStdParametersClass: | ||
return _generate_assertion_std_parameters() | ||
|
||
|
||
Operators = Union[ | ||
EqualToOperator, | ||
BetweenOperator, | ||
LessThanOperator, | ||
LessThanOrEqualToOperator, | ||
GreaterThanOperator, | ||
GreaterThanOrEqualToOperator, | ||
NotNullOperator, | ||
] |
This file contains 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
This file contains 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 |
---|---|---|
|
@@ -54,7 +54,7 @@ class DataContract(ConfigModel): | |
freshness: Optional[FreshnessAssertion] = pydantic.Field(default=None) | ||
|
||
# TODO: Add a validator to ensure that ids are unique | ||
data_quality: Optional[List[DataQualityAssertion]] = None | ||
data_quality: Optional[List[DataQualityAssertion]] = pydantic.Field(default=None) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. interesting - these two are equivalent right? |
||
|
||
_original_yaml_dict: Optional[dict] = None | ||
|
||
|
This file contains 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 we also support Volume Assertions + Freshness Assertions?
Or are these already supported
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.
Freshness is supported I believe, or at least a subset of it. Volume not yet