In Deequ, how do a `VerificationSuite`'s Error-level and Warning-level checks decide the run's status, and does `run()` fail the Spark job?
answer
- two levels in, three statuses out
- the worst status wins
- constraints become Spark jobs over metrics
- a result to inspect, not an exception
- SPARK_VERSION before importing PyDeequ
basics
~20 sA failing Check reports Error or Warning according to its CheckLevel, and the VerificationResult status is the worst status across checks. run() only returns that result, so the job must test the status and fail itself.
solid answer
~40 sDeequ turns each `Check`'s constraints (`isComplete`, `isUnique`, `hasCompleteness("ad_slot", _ >= 0.99)`, `isContainedIn`, and so on) into Spark jobs that compute metrics, then applies the assertions to those metrics. A `Check` built with `CheckLevel.Error` ends as `CheckStatus.Error` if any of its constraints fails; one built with `CheckLevel.Warning` ends as `CheckStatus.Warning`; otherwise `Success`. The `VerificationResult.status` is the maximum over all checks in the order `Success < Warning < Error`, so one failed Error-level check makes the run `Error` and a failed Warning-level check alone makes it `Warning`. `run()` returns that result and throws nothing for bad data, so the training step must branch on the status, raise on `Error`, and log the failing constraints. In PyDeequ the status is a string, `"Success"`, `"Warning"` or `"Error"`.
code
python · 23 linesimport os
os.environ["SPARK_VERSION"] = "3.5" # PyDeequ 1.7.0 raises at import without it
from pyspark.sql import SparkSession
import pydeequ
from pydeequ.checks import Check, CheckLevel
from pydeequ.verification import VerificationSuite, VerificationResult
spark = (SparkSession.builder
.config("spark.jars.packages", pydeequ.deequ_maven_coord)
.config("spark.jars.excludes", pydeequ.f2j_maven_coord)
.getOrCreate())
features = spark.read.parquet(features_path)
blocking = (Check(spark, CheckLevel.Error, "ctr features: blocking")
.isComplete("impression_id").isUnique("impression_id")
.hasCompleteness("ad_slot", lambda c: c >= 0.99))
advisory = Check(spark, CheckLevel.Warning, "ctr features: advisory").isNonNegative("dwell_ms")
result = VerificationSuite(spark).onData(features).addCheck(blocking).addCheck(advisory).run()
if result.status == "Error":
VerificationResult.checkResultsAsDataFrame(spark, result).show(truncate=False)
raise SystemExit("Deequ Error-level check failed; training stops")go deeper
Recall that a Deequ check is created with a level, Error or Warning, and that the suite returns a result whose status you must read.
Explain how a failing constraint becomes a check status by level, why the overall status is the worst one, and how to write the gate that raises on Error.
Decide which constraints block and which warn, keep them in separate checks for that reason, and make the failing constraint messages land where the on-call engineer will read them.
Set the policy for who may move a constraint between blocking and advisory, and how suggested constraints are reviewed before they can stop a retrain.
## How a VerificationSuite runs Deequ, a library built on **Apache Spark**, treats data checks as **unit tests for data**. You describe expectations as `Check` objects, add them to a `VerificationSuite`, and call `run()`. Deequ translates the constraints into Spark jobs that compute **metrics** over the DataFrame (completeness, uniqueness, size, quantiles), applies your assertion functions to those metrics, and returns a `VerificationResult`. ```scala val result = VerificationSuite() .onData(features) .addCheck( Check(CheckLevel.Error, "ctr features: blocking") .isComplete("impression_id") .isUnique("impression_id") .hasCompleteness("ad_slot", _ >= 0.99) .isContainedIn("device_type", Array("mobile", "desktop", "tablet"))) .run() ``` ## Check levels and statuses Every `Check` is created with a `CheckLevel`, `Error` or `Warning`, and every evaluated check gets a `CheckStatus` of `Success`, `Warning` or `Error`. | Constraints in the check | Check built with `CheckLevel.Error` | Check built with `CheckLevel.Warning` | |---|---|---| | all pass | `Success` | `Success` | | at least one fails | `Error` | `Warning` | The suite's overall `VerificationResult.status` is the **maximum** of the check statuses in the order `Success < Warning < Error`, and `Success` when the suite has no checks. So the level is a property of the whole `Check`: put a constraint in an Error-level check and any failure of it blocks; put it in a Warning-level check and it can only ever warn. ## Constraints worth writing for a feature table | Constraint | Asserts | |---|---| | `isComplete("col")` | the column is never NULL | | `hasCompleteness("col", _ >= 0.99)` | the non-NULL fraction satisfies the assertion | | `isUnique("col")` | no duplicate values | | `isContainedIn("col", Array(...))` | only the listed values occur | | `isNonNegative("col")` | no negative values | | `hasSize(_ >= n)` | the row count satisfies the assertion | | `satisfies(condition, name)` | a Spark SQL condition holds, for every row by default | `isComplete` is the strict form; `hasCompleteness` with an assertion is how you tolerate a known share of nulls. A failed constraint's message carries the metric value it saw, which is what you print when the gate trips. ## Turning the result into a gate `run()` returns the result whatever the data looks like; the Deequ README's own example branches on `verificationResult.status == CheckStatus.Success`. So the training step: 1. builds blocking checks at `CheckLevel.Error` and advisory ones at `CheckLevel.Warning`; 2. runs the suite on the feature DataFrame before the trainer reads it; 3. on `Error`, prints the failing constraints and raises, so the orchestrator marks the task failed and training never starts; 4. on `Warning`, logs the failing constraints and lets training continue. The per-constraint detail comes from `checkResults` in Scala, or `VerificationResult.checkResultsAsDataFrame(spark, result)`, which gives one row per constraint with its check, check level, check status, constraint status and message. ## When the data breaks the analysis itself A vanished column does not crash the suite either. If a metric cannot be computed, for instance because `ad_slot` is missing from the DataFrame, the metric for `hasCompleteness("ad_slot", ...)` cannot be computed; Deequ records the analysis failure as a **failed constraint** whose message carries the exception text, and the check's level turns that into `Error` or `Warning` like any other failure. One exception the source makes is a constraint whose `where` filter removed every row: an empty result there counts as `Success`, because no matching row could violate it. A gate that reads the status therefore covers missing columns too, provided the constraint sits in an Error-level check. ## PyDeequ specifics - PyDeequ 1.7.0 reads the `SPARK_VERSION` environment variable **at import time** and raises a `RuntimeError` when it is unset. Supported values are `3.5` and `4.1`, mapped to the Deequ jars `2.0.21-spark-3.5` and `2.0.18-spark-4.1`; clusters on Spark 3.1 to 3.4 need PyDeequ 1.6.0. - The Spark session must load the jar: `.config("spark.jars.packages", pydeequ.deequ_maven_coord)`. - `Check(spark, CheckLevel.Error, "...")` takes the session first, and `result.status` is a string: `"Success"`, `"Warning"` or `"Error"`. - Scala Deequ itself is at the `3.0.2-spark-3.5` tag in git, with `3.0.3-spark-3.5` the latest release on Maven Central; PyDeequ pins its own, older Deequ jars, so a Scala example and a PyDeequ job may not run the same Deequ version. ## Where suggested constraints fit `ConstraintSuggestionRunner().onData(df).addConstraintRules(Rules.DEFAULT).run()` profiles the data and proposes constraints, each with its code (`codeForConstraint`). The Deequ docs warn that the suggestions assume the data shown is static and correct, so they are a draft to review and to place in an Error-level or Warning-level check deliberately.
- Can ConstraintSuggestionRunner write these checks for you?It drafts them. `ConstraintSuggestionRunner` profiles the data, applies heuristic rules such as `Rules.DEFAULT`, and returns suggestions with their code. The docs say the rules assume the data shown is static and correct, so review each one; `useTrainTestSplitWithTestsetRatio(0.1)` evaluates suggestions on a held-out 10% before you adopt them.
- Why does `import pydeequ` fail on a freshly built cluster image?PyDeequ 1.7.0 resolves its Deequ jar from the `SPARK_VERSION` environment variable at import and raises a `RuntimeError` when it is missing or unsupported. Set it to `3.5` or `4.1` before importing; a Spark 3.1 to 3.4 cluster needs PyDeequ 1.6.0 instead.
- How do you find which rows broke an `isComplete` check?Call `VerificationResult.rowLevelResultsAsDataFrame(spark, result, df)` in PyDeequ: each check produces one Boolean column, pass or fail per row, with its constraints ANDed. Only row-level-capable constraints such as `isComplete`, `isContainedIn` and `isUnique` produce columns; dataset-level ones such as size do not.
- VerificationSuite.run() throws an exception when an Error-level check fails
- A failed Warning-level check makes the overall Deequ status Error
- isComplete tolerates a small share of nulls
- PyDeequ detects the Spark version from the running session on its own
- Constraint suggestions can go straight into the gate because Deequ profiled the data
Assumes PyDeequ 1.7.0 (SPARK_VERSION 3.5 or 4.1, Deequ 2.0.21 / 2.0.18 jars) and Scala Deequ at the 3.0.2-spark-3.5 tag; check levels and status ordering are the same in both.