Validation with views - Dlt pipeline expectations

lucami
Contributor

I have a question about how expectations work when applied to views inside a Delta Live Tables (DLT) pipeline. For instance, suppose we define this view inside a pipeline to stop the pipeline if we spot some duplicates:

@Dlt.view(
    name=view_name,
)
@dlt.expect_or_fail(expectation, "duplicate = 1")
def generate_report():
    return (
        dlt.read(table)
        .groupBy(keys)
        .agg(count("*").alias("duplicate"))
    )

What is happening behind the scenes? Is the expectation validated as a "temporary table" (computed but not stored in the catalog), or is it validated only if the view is used by a table defined in the pipeline?