Skip to content
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

[FEATURE] V1 Validation scaffolding #9508

Merged
merged 10 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions great_expectations/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@
from .id_dict import IDDict
from .run_identifier import RunIdentifier, RunIdentifierSchema
from .urn import ge_urn
from .validation import Validation

__all__ = [
"Domain",
"ExpectationSuite",
"ExpectationSuiteSchema",
"expectationSuiteSchema",
"ExpectationSuiteValidationResult",
"ExpectationSuiteValidationResultSchema",
"ExpectationValidationResult",
"ExpectationValidationResultSchema",
"expectationSuiteValidationResultSchema",
"expectationValidationResultSchema",
"get_metric_kwargs_id",
"IDDict",
"RunIdentifier",
"RunIdentifierSchema",
"Validation",
"expectationSuiteSchema",
"expectationSuiteValidationResultSchema",
"expectationValidationResultSchema",
"ge_urn",
"get_metric_kwargs_id",
]

logger = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions great_expectations/core/factory/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .checkpoint_factory import CheckpointFactory
from .suite_factory import SuiteFactory
from .validation_factory import ValidationFactory
56 changes: 56 additions & 0 deletions great_expectations/core/factory/validation_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from great_expectations._docs_decorators import public_api
from great_expectations.compatibility.typing_extensions import override
from great_expectations.core.factory.factory import Factory

if TYPE_CHECKING:
from great_expectations.core.validation import Validation


# TODO: Add analytics as needed
class ValidationFactory(Factory[Validation]):
def __init__(self, store) -> None:
# TODO: Update type hints when new ValidationStore is implemented
self._store = store
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think I'm blocked on this. We have an existing ValidationsStore but those are for results?

I think we need to do the following:

  • Rename the old store to ValidationResultsStore
  • Create a new ValidationsStore (or ValidationStore our inconsistent plurality should be resolved)
  • Plug in the new one here and have CRUD start working

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on the store now: #9515


@public_api
@override
def add(self, validation: Validation) -> Validation:
"""Add a Validation to the collection.

Parameters:
validation: Validation to add

Raises:
DataContextError if Validation already exists
"""
raise NotImplementedError

@public_api
@override
def delete(self, validation: Validation) -> Validation:
"""Delete a Validation from the collection.

Parameters:
validation: Validation to delete

Raises:
DataContextError if Validation doesn't exist
"""
raise NotImplementedError

@public_api
@override
def get(self, name: str) -> Validation:
"""Get a Validation from the collection by name.

Parameters:
name: Name of Validation to get

Raises:
DataContextError when Validation is not found.
"""
raise NotImplementedError
45 changes: 45 additions & 0 deletions great_expectations/core/validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from great_expectations.core.batch_config import BatchConfig
from great_expectations.core.expectation_suite import ExpectationSuite
from great_expectations.datasource.fluent.interfaces import DataAsset


class Validation:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this to be a Pydantic model? Went back and forth on it but figured its a pretty lightweight object so we can just add it if we need (probably when persistence comes into question?)

"""
Responsible for running a suite against data and returning a validation result.

Args:
name: The name of the validation.
data: An asset or batch config to validate.
suite: A grouping of expectations to validate against the data.

"""

def __init__(
self,
name: str,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not part of the spec but we need an identifier if we want persistence

data: DataAsset | BatchConfig,
suite: ExpectationSuite,
) -> None:
self._name = name
self._data = data
self._suite = suite

@property
def name(self) -> str:
return self._name

@property
def data(self) -> BatchConfig:
return self._data

@property
def suite(self) -> ExpectationSuite:
return self._suite

def run(self):
raise NotImplementedError
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@
_RuntimeEnvironmentConfigurationProvider,
)
from great_expectations.core.expectation_validation_result import get_metric_kwargs_id
from great_expectations.core.factory import CheckpointFactory, SuiteFactory
from great_expectations.core.factory import (
CheckpointFactory,
SuiteFactory,
ValidationFactory,
)
from great_expectations.core.id_dict import BatchKwargs
from great_expectations.core.serializer import (
AbstractConfigSerializer,
Expand Down Expand Up @@ -329,6 +333,9 @@ def _init_factories(self) -> None:
context=self,
)

# TODO: Update to follow existing pattern once new ValidationStore is implemented
self._validations: ValidationFactory | None = None

def _init_analytics(self) -> None:
init_analytics(
data_context_id=uuid.UUID(self._data_context_id),
Expand Down Expand Up @@ -555,6 +562,14 @@ def checkpoints(self) -> CheckpointFactory:
)
return self._checkpoints

@property
def validations(self) -> ValidationFactory:
if not self._validations:
raise gx_exceptions.DataContextError(
"DataContext requires a configured ValidationStore to persist Validations."
)
return self._validations

@property
def expectations_store_name(self) -> Optional[str]:
return self.variables.expectations_store_name
Expand Down