Skip to content

A scenario for a data engineer · Junior and up

An order for minus three items

Penny · Finance
Wednesday, 11:20

Three jobs write to the orders Delta table on Databricks. One of them let through an order with a quantity of minus three, and the finance report built on the table came out wrong.

What do you do?

Tap the one you would do. The answer opens below.

Show the best call

Fix the bad rows, then add a CHECK constraint to the table: quantity must be zero or more.

The table itself now holds every writer to the rule. The next bad write fails with an error, before anyone reads it.

Why

A CHECK constraint is a rule kept on a Delta table. A write that breaks it fails as a whole, whichever job it comes from. Databricks checks the rows already in the table when you add the constraint, so the bad ones have to be fixed first. NOT NULL is enforced the same way.

Read it in the Databricks docs (opens in a new tab)

The other two

Works, at a price. Add a filter for negative quantities to each of the three jobs.
It works for these three jobs. The rule now lives in three places, and a fourth job will not have it.
A poor call. Correct the rows by hand whenever finance reports one.
Finance becomes your data quality check, and they find out after the report has gone out.

Go deeper on brickster.ai

More scenarios

Had one like this at work? Send it to us: the best tickets come from real incidents.

Added on . Checked against the Databricks documentation on . brickster.ai is independent and is not affiliated with Databricks.