-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'm/zelda-1183/zelda-1188/adding-databricks-types' of htt…
…ps://github.com/great-expectations/great_expectations into m/zelda-1183/zelda-1188/adding-databricks-types * 'm/zelda-1183/zelda-1188/adding-databricks-types' of https://github.com/great-expectations/great_expectations: [MAINTENANCE] Allow `CheckpointResult` and `ActionContext` to be importable from top-level checkpoint module (#10788) [DOCS] Custom Actions (#10772) [DOCS] Remove unnecessary escape character in Expectation for Gallery (#10780) [MAINTENANCE] Deprecate `DataContext.add_or_update_datasource` (#10784)
- Loading branch information
Showing
17 changed files
with
168 additions
and
30 deletions.
There are no files selected for viewing
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
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
53 changes: 53 additions & 0 deletions
53
...docusaurus/docs/core/trigger_actions_based_on_results/_examples/create_a_custom_action.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,53 @@ | ||
""" | ||
This is an example script for how to create a custom Action. | ||
To test, run: | ||
pytest --docs-tests -k "docs_example_create_a_custom_action" tests/integration/test_script_runner.py | ||
""" | ||
|
||
# EXAMPLE SCRIPT STARTS HERE: | ||
|
||
# <snippet name="docs/docusaurus/docs/core/trigger_actions_based_on_results/_examples/create_a_custom_action.py - full code example"> | ||
|
||
from typing import Literal | ||
|
||
from typing_extensions import override | ||
|
||
from great_expectations.checkpoint import ( | ||
ActionContext, | ||
CheckpointResult, | ||
ValidationAction, | ||
) | ||
|
||
|
||
# 1. Extend the `ValidationAction` class. | ||
# <snippet name="docs/docusaurus/docs/core/trigger_actions_based_on_results/_examples/create_a_custom_action.py - extend class"> | ||
class MyCustomAction(ValidationAction): | ||
# </snippet> | ||
|
||
# 2. Set the `type` attribute to a unique string that identifies the Action. | ||
# <snippet name="docs/docusaurus/docs/core/trigger_actions_based_on_results/_examples/create_a_custom_action.py - set type"> | ||
type: Literal["my_custom_action"] = "my_custom_action" | ||
# </snippet> | ||
|
||
# 3. Override the `run()` method to perform the desired task. | ||
# <snippet name="docs/docusaurus/docs/core/trigger_actions_based_on_results/_examples/create_a_custom_action.py - override run"> | ||
@override | ||
def run( | ||
self, | ||
checkpoint_result: CheckpointResult, | ||
action_context: ActionContext, # Contains results from prior Actions in the same Checkpoint run. | ||
) -> dict: | ||
# Domain-specific logic | ||
self._do_my_custom_action(checkpoint_result) | ||
# Return information about the Action | ||
return {"some": "info"} | ||
|
||
def _do_my_custom_action(self, checkpoint_result: CheckpointResult): | ||
# Perform custom logic based on the validation results. | ||
... | ||
|
||
# </snippet> | ||
|
||
|
||
# </snippet> |
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
65 changes: 65 additions & 0 deletions
65
...docusaurus/docs/core/trigger_actions_based_on_results/create_a_custom_action.md
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,65 @@ | ||
--- | ||
title: Create a custom Action | ||
description: Run custom logic based on Validation Results to integrate with 3rd-party tools and business workflows. | ||
--- | ||
import TabItem from '@theme/TabItem'; | ||
import Tabs from '@theme/Tabs'; | ||
|
||
import PrereqPythonInstalled from '../_core_components/prerequisites/_python_installation.md'; | ||
import PrereqGxInstalled from '../_core_components/prerequisites/_gx_installation.md'; | ||
|
||
Great Expectations provides [Actions for common workflows](/application_integration_support.md#integrations) such as sending emails and updating Data Docs. If these don't meet your needs, you can create a custom Action to integrate with different tools or apply custom business logic based on Validation Results. Example use cases for custom Actions include: | ||
- Opening tickets in an issue tracker when Validation runs fail. | ||
- Triggering different webhooks depending on which Expectations fail. | ||
- Running follow-up ETL jobs to fill in missing values. | ||
|
||
A custom Action can do anything that can be done with Python code. | ||
|
||
To create a custom Action, you subclass the `ValidationAction` class, overriding the `type` attribute with a unique name and the `run()` method with custom logic. | ||
|
||
|
||
## Prerequisites | ||
|
||
- <PrereqPythonInstalled/>. | ||
- <PrereqGxInstalled/>. | ||
|
||
## Procedure | ||
|
||
<Tabs | ||
queryString="procedure" | ||
defaultValue="instructions" | ||
values={[ | ||
{value: 'instructions', label: 'Instructions'}, | ||
{value: 'sample_code', label: 'Sample code'} | ||
]} | ||
> | ||
<TabItem value="instructions" label="Instructions"> | ||
|
||
1. Create a new custom Action class that inherits the `ValidationAction` class. | ||
|
||
```python title="Python" name="docs/docusaurus/docs/core/trigger_actions_based_on_results/_examples/create_a_custom_action.py - extend class" | ||
``` | ||
|
||
2. Set a unique name for `type`. | ||
|
||
```python title="Python" name="docs/docusaurus/docs/core/trigger_actions_based_on_results/_examples/create_a_custom_action.py - set type" | ||
``` | ||
|
||
3. Override the `run()` method with the logic for the Action. | ||
|
||
```python title="Python" name="docs/docusaurus/docs/core/trigger_actions_based_on_results/_examples/create_a_custom_action.py - override run" | ||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem value="sample_code" label="Sample code"> | ||
|
||
```python title="Python" name="docs/docusaurus/docs/core/trigger_actions_based_on_results/_examples/create_a_custom_action.py - full code example" | ||
``` | ||
|
||
</TabItem> | ||
|
||
</Tabs> | ||
|
||
Now you can use your custom Action like you would any built-in Action. [Create a Checkpoint with Actions](/core/trigger_actions_based_on_results/create_a_checkpoint_with_actions.md) to start automating responses to Validation Results. |
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
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
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
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
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