A data engineer is building a Python Lakeflow Spark Declarative Pipeline. It reads raw.sensors into a streaming table named sensor_readings. The team is setting a quality baseline for a new device vendor. The rule reading_value IS NOT NULL has these requirements:
- Every record, including records with a null
reading_value, must be written to the target table. - The update must continue when violations occur.
- Violation counts must be visible on the Data quality tab.
Which decorator should the engineer add to the existing @dp.table function for sensor_readings?
The requirement is to keep every record, keep the update running, and still see violation counts. Only the warn action meets all three. In Python this is @dp.expect, which is the default behaviour: rows that fail the rule still reach the target and violation metrics are captured. The drop variants remove the invalid rows, and the fail action stops the flow that encounters the violation.
- Not correct:
@dp.expect_or_fail("non_null_reading", "reading_value IS NOT NULL"). The fail action stops the affected flow as soon as a record violates the constraint. Manual intervention is then needed, and no fail metrics are recorded. - Not correct:
@dp.expect_all_or_drop({"non_null_reading": "reading_value IS NOT NULL"}). expect_all_or_drop applies the drop action to every expectation in the group. Records that fail the rule are removed from the output. - Correct:
@dp.expect("non_null_reading", "reading_value IS NOT NULL"). @dp.expect applies the default warn action. Rows that break the rule are kept in the output table, failure metrics are logged for review, and the update keeps running. - Not correct:
@dp.expect_or_drop("non_null_reading", "reading_value IS NOT NULL"). The drop action removes records that fail validation before they are written. Records with a null reading_value would therefore not reach the target table.