Skip to content

Commit

Permalink
[DOCS] Adds guidance around Checkpoints in 1.0 (#9675)
Browse files Browse the repository at this point in the history
Co-authored-by: Rob Gray <104205257+kwcanuck@users.noreply.github.com>
  • Loading branch information
Rachel-Reverie and kwcanuck committed Mar 29, 2024
1 parent ab02092 commit eff37b8
Show file tree
Hide file tree
Showing 10 changed files with 428 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
This example script demonstrates how to create a Checkpoint and add it
to a Data Context.
The <snippet> tags are used to insert the corresponding code into
GX documentation, and you can disregard them.
"""

# <snippet name="/core/validate_data/checkpoints/_examples/create_a_checkpoint.py full script">
# highlight-start
# <snippet name="/core/validate_data/checkpoints/_examples/create_a_checkpoint.py import statements">
import great_expectations as gx
from great_expectations.core import Checkpoint
# </snippet>
# highlight-end

context = gx.get_context()

validation_definition_name = "my_existing_validation_definition"
validation_definition = context.validation_definitions.get(name=validation_definition_name)

validation_definitions = [validation_definition]
# <snippet name="/core/validate_data/checkpoints/_examples/create_a_checkpoint.py determine actions">
actions = [gx.UpdateDataDocs(...), gx.SlackNotification(...)]
# </snippet>
# <snippet name="/core/validate_data/checkpoints/_examples/create_a_checkpoint.py create checkpoint">
checkpoint_name = "my_checkpoint"

# highlight-start
checkpoint = Checkpoint(
name=checkpoint_name,
validations=validation_definitions,
actions=actions
)
# highlight-end
# </snippet>

# highlight-start
# <snippet name="/core/validate_data/checkpoints/_examples/create_a_checkpoint.py add checkpoint">
context.checkpoints.add(checkpoint)
# </snippet>
# highlight-end
# </snippet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
This example script demonstrates how to retrieve an existing Checkpoint
from a Data Context and then delete it from the Data Context configuration.
The <snippet> tags are used to insert the corresponding code into
GX documentation, and you can disregard them.
"""

# <snippet name="/core/validate_data/checkpoints/_examples/delete_a_checkpoint.py full example script">
import great_expectations as gx

context = gx.get_context()

# <snippet name="/core/validate_data/checkpoints/_examples/delete_a_checkpoint.py delete checkpoint">
checkpoint_name = "my_checkpoint"
# highlight-start
context.checkpoints.delete(name=checkpoint_name)
# highlight-end
# </snippet>
# </snippet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
This example script demonstrates how to retrieve an existing Checkpoint
from a Data Context by name.
The <snippet> tags are used to insert the corresponding code into
GX documentation, and you can disregard them.
"""

# <snippet name="/core/validate_data/checkpoints/_examples/get_checkpoint_by_name.py full example script">
import great_expectations as gx

context = gx.get_context()

# <snippet name="/core/validate_data/checkpoints/_examples/get_checkpoint_by_name.py get checkpoint by name">
checkpoint_name = "my_checkpoint"
# highlight-start
checkpoint = context.checkpoints.get(name=checkpoint_name)
# highlight-end
# </snippet>
# </snippet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
This example script demonstrates how to filter the list of Checkpoints in a
Data Context on attributes.
The <snippet> tags are used to insert the corresponding code into
GX documentation, and you can disregard them.
"""

# <snippet name="/core/validate_data/checkpoints/_examples/get_checkpoints_by_attributes.py full example code">
import great_expectations as gx
from great_expectations.checkpoints import SlackNotificationAction

context = gx.get_context()

# <snippet name="/core/validate_data/checkpoints/_examples/get_checkpoints_by_attributes.py filter checkpoints list on actions">
# highlight-start
checkpoints_with_slack_alerts = [checkpoint.name for checkpoint in context.checkpoints
if any(isinstance(action, SlackNotificationAction) for action in checkpoint.actions)]

# highlight-end
print(checkpoints_with_slack_alerts)
# </snippet>
# </snippet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
This example script demonstrates how to list the Checkpoints available
in a Data Context and use attributes to filter the list.
The <snippet> tags are used to insert the corresponding code into
GX documentation, and you can disregard them.
"""

# <snippet name="/core/validate_data/checkpoints/_examples/list_available_checkpoints.py full example code">
import great_expectations as gx

context = gx.get_context()

# highlight-start
# <snippet name="/core/validate_data/checkpoints/_examples/list_available_checkpoints.py print checkpoint names">
checkpoint_names = [checkpoint.name for checkpoint in context.checkpoints]
print(checkpoint_names)
# </snippet>
# highlight-end
# </snippet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
This example script demonstrates how to run a Checkpoint, how
to determine what Batch Parameters and Suite Parameters to pass into the
run command, and how to review the returned results.
The <snippet> tags are used to insert the corresponding code into
GX documentation, and you can disregard them.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
This example script demonstrates how to update a Checkpoint's Validation Definitions
and Actions list, and persist those changes to the Data Context.
The <snippet> tags are used to insert the corresponding code into
GX documentation, and you can disregard them.
"""

# <snippet name="/core/validate_data/checkpoints/_examples/update_a_checkpoint.py full example script">
import great_expectations as gx

context = gx.get_context()

checkpoint_name = "my_checkpoint"
checkpoint = context.checkpoints.get(name=checkpoint_name)

# <snippet name="/core/validate_data/checkpoints/_examples/update_a_checkpoint.py full update values">
new_validations_list = [context.validation_definitions.get(name="new_validation")]
new_actions_list = [gx.UpdateDataDocs(...)]

# highlight-start
checkpoint.validations = new_validations_list
checkpoint.actions = new_actions_list
# highlight-end
# </snippet>

# highlight-start
# <snippet name="/core/validate_data/checkpoints/_examples/update_a_checkpoint.py full save updates">
checkpoint.save()
# </snippet>
# highlight-end
# </snippet>

0 comments on commit eff37b8

Please sign in to comment.