Run a Checkpoint
Running a Checkpoint will cause it to validate all of its Validation Definitions. It will then execute its Actions based on the results returned from those Validation Definitions. Finally, the Validation Results will be returned by the Checkpoint.
At runtime, a Checkpoint can take in a batch_parameters
dictionary that selects the Batch to validate from each Validation Definition. A Checkpoint will also accept an expectation_parameters
dictionary that provides values for the parameters of the any Expectations that have been configured to accept parameters at runtime.
Prerequisites
- Python version 3.9 to 3.12.
- An installation of GX Core.
- A preconfigured Data Context.
- A preconfigured Checkpoint.
Procedure
If you want to use the API to run a validation for GX-managed Expectations in a GX Cloud deployment, you can use the GX Cloud UI to generate the necessary code. For the Data Asset of interest, go to the Expectations tab and click Use code snippet near the Validate button.
- Instructions
- Sample code
In this procedure your Data Context is assumed to be stored in the variable context
and your Checkpoint is assumed to be stored in the variable checkpoint
.
-
Optional. Define Batch parameters.
Batch parameters are used to specify a Batch of data for retrieval from a Batch Definition. Batch parameters are provided as a dictionary to the
batch_parameters
argument of a Checkpoint'srun(...)
method.The Batch parameters accepted by a Validation Definition are determined by its Batch Definition.
Batch parameters apply to every Validation Definition in the Checkpoint. Therefore, the Validation Definitions grouped in a Checkpoint should have Batch Definitions that accept the same Batch filtering criteria.
For more information and examples of how to configure a Batch Definition to accept Batch Parameters and how to format a
batch_parameters
dictionary, see Connect to data using SQL: Create a Batch Definition.If Batch parameters are not set, each Validation Definition will run on the default Batch determined by its Batch Definition.
-
Optional. Define Expectation Parameters.
To pass parameters to Expectations at runtime the Expectation must be configured to find parameter values through a dictionary lookup. This is done when the Expectation is created.
You then pass a dictionary to the
expectation_parameters
argument of a Checkpoint'srun
method. The contents of this dictionary consist of keys that were defined for parameters when the Checkpoint's Expectations were created, paired with the values that should be used for the corresponding parmeters when the Checkpoint runs.Below is an example of an
ExpectColumnMaxToBeBetween
Expectation that is set to accept parameters at runtime:Pythongx.expectations.ExpectColumnMaxToBeBetween(
column="fare",
min_value={"$PARAMETER": "expect_fare_max_to_be_above"},
max_value={"$PARAMETER": "expect_fare_max_to_be_below"},
)And this is an
expectation_parameters
dictionary that provides those parameters:Pythonexpectation_parameters = {
"expect_fare_max_to_be_above": 5.00,
"expect_fare_max_to_be_below": 1000.00,
}If none of the Expectations in a Validation Definition are configured to accept runtime Expectation parameters, the
expectation_parameters
argument can be omitted from the Checkpoint'srun(...)
method.For more information on configuring an Expectation to accept runtime parameters, how to set the lookup key for an Expectation's parameters, and additional examples of how to format an
expectation_parameters
dictionary see the runtime guidance under Create an Expectation. -
Run the Checkpoint.
A Checkpoint is executed through its
run(...)
method. Pass the Batch and Expectation parameters to thebatch_parameters
andexpectation_parameters
arguments of the Checkpoint'srun(...)
method:Pythonvalidation_results = checkpoint.run(
batch_parameters=batch_parameters, expectation_parameters=expectation_parameters
)After the Checkpoint runs it will pass the Validation Results that are generated to its Actions and execute them. Finally, the Validation Results will be returned by the
run(...)
method.
import great_expectations as gx
context = gx.get_context()
checkpoint = context.checkpoints.get("my_checkpoint")
batch_parameters = {"month": "01", "year": "2019"}
expectation_parameters = {
"expect_fare_max_to_be_above": 5.00,
"expect_fare_max_to_be_below": 1000.00,
}
validation_results = checkpoint.run(
batch_parameters=batch_parameters, expectation_parameters=expectation_parameters
)