Practice Exam

Question 58 of 75

Implement Incremental Loading with Conditional Source Update

You work for MDFT Pro, a well-known training agency that manages student course enrollments. Mark, a Data Engineer at MDFT Pro, maintains a Fabric lakehouse named StudentEnrollmentLakehouse that contains a table named ActiveEnrollments_Target with the following columns:

The data source system contains a table named ActiveEnrollments_Source with the same columns, which tracks currently active enrollments. In a notebook named EnrollmentCleanupNotebook, Mark loads ActiveEnrollments_Source to a DataFrame named sourceDF and ActiveEnrollments_Target to a DataFrame named targetDF. Mark needs to implement an incremental loading pattern that identifies and marks stale enrollment records. The solution must meet the following requirement: Set the value of Status in ActiveEnrollments_Target to “inactive” for all records that were last modified more than seven days ago AND that do NOT exist in ActiveEnrollments_Source (indicating students who have withdrawn or completed their courses).

How should Mark complete the merge statement?

(targetDF
    .merge(sourceDF, "sourceDF.Key = targetDF.Key")
    .________________ (
        condition = "targetDF.LastModified < (current_date() - INTERVAL '7' DAY)",
        set = {"targetDF.Status": "'inactive'"}
    )
.execute()
)

Choose the correct answer from the options below.

Explanations for each answer:

Learn more about upserting into Delta Lake tables using merge:
Delta Lake Merge Operations
Next Question
Discuss this question on social media: