Using multiple different data assets under a single expectation suite

Is it possible for me use multiple data assets under a single expectation suite? Lets say I have an SQL datasource pg_1 and 2 query data assets under that source, query_1 and query_2. I also have 2 separate expectations I want to test, one using query_1 as a data asset, and the other using query_2 . Ideally, I want these to be in the same expectation suite some_suite . Is it possible to assign multiple data assets to a suite with validation definitions, or am I meant to group expectations in suites by data assets? If so, how would I do it, and could I see an example?

Hi there, welcome to our community! Yes, you can apply a single expectation suite to multiple data assets. You can run your tests by creating different validation definitions (one for each data asset) and assigning them to the same expectation suite.

Each validation definition specifies the data asset to validate with the expectation suite, allowing you to keep both expectations under some_suite while targeting separate data assets (query_1 and query_2).

high-level example:

validation_def_1 = context.validation_definitions.add(
    gx.ValidationDefinition(
        name="validation_for_query_1",
        data=batch_definition_for_query_1,
        suite=some_suite
    )
)

validation_def_2 = context.validation_definitions.add(
    gx.ValidationDefinition(
        name="validation_for_query_2",
        data=batch_definition_for_query_2,
        suite=some_suite
    )
)

For better organization, you can define a Checkpoint to run validations across multiple assets:

cp = context.checkpoints.add(
    gx.Checkpoint(
        name="multi_asset_checkpoint",
        validation_definitions=[validation_def_1, validation_def_2],
        actions=[gx.checkpoint.actions.UpdateDataDocsAction(name="update_docs")]
    )
)

cp.run()
1 Like