DATABRICKS-DATA-ENGINEER-ASSOCIATE practice question 20 of 25

Identify the impact of ON VIOLATION DROP ROW and ON VIOLATION FAIL UPDATE for a constraint violation. A data engineer has created an ETL pipeline using Delta Live table to manage their company travel reimbursement detail, they want to ensure that the if the location details has not been provided by the employee, the pipeline needs to be terminated. How can the scenario be implemented?

Full set: 177 questions
Answer options
A: CONSTRAINT valid_location EXPECT (location = NULL)
B: CONSTRAINT valid_location EXPECT (location != NULL) ON VIOLATION FAIL UPDATE Correct answer
C: CONSTRAINT valid_location EXPECT (location != NULL) ON DROP ROW
D: CONSTRAINT valid_location EXPECT (location != NULL) ON VIOLATION FAIL
Correct Answer:
B. CONSTRAINT valid_location EXPECT (location != NULL) ON VIOLATION FAIL UPDATE
Explanation

The goal is to terminate the pipeline if the location column is NULL. The CONSTRAINT clause in Delta Live Tables (DLT) is used to enforce data quality. The EXPECT condition (location != NULL) correctly identifies records where the location is provided. The ON VIOLATION FAIL UPDATE action instructs DLT to stop the entire pipeline update immediately upon encountering a record that violates this expectation (i.e., where location is NULL). This directly implements the requirement to terminate the pipeline on invalid data.

Why Incorrect

A. CONSTRAINT validlocation EXPECT (location = NULL) This checks for records where the location is NULL, which is the opposite of the desired validation. It also lacks an ON VIOLATION clause, defaulting to DROP ROW, which doesn't terminate the pipeline.
C. CONSTRAINT validlocation EXPECT (location != NULL) ON DROP ROW While the EXPECT clause is correct, ON DROP ROW (or its full syntax ON VIOLATION DROP ROW) will silently discard the invalid record and allow the pipeline to continue processing. This does not meet the requirement to terminate.
D. CONSTRAINT validlocation EXPECT (location != NULL) ON VIOLATION FAIL This option is syntactically incorrect. The valid keyword to fail a pipeline update due to a constraint violation is FAIL UPDATE, not just FAIL. ---

References

1. Databricks Documentation

"Manage data quality with Delta Live Tables":

Section: "Declare a data quality constraint"

Content: This section details the syntax for defining constraints: CONSTRAINT EXPECT () [ ON VIOLATION { FAIL UPDATE | DROP ROW } ]. It explicitly states that FAIL UPDATE causes the pipeline update to fail when a record violates the constraint. It also clarifies that DROP ROW is the default behavior

which only discards the record. This directly supports option B as the correct method to terminate a pipeline and refutes option C. It also shows that option D is syntactically invalid.

URL: https://docs.databricks.com/en/delta-live-tables/data-quality.html (The specific content is found under the "Declare a data quality constraint" heading).

Scroll to Top