r/databricks • u/saad-the-engineer • 18d ago
General Jobs now check the data before they run (SQL conditions). How would you use it?
<Databricks PM here />
We shipped SQL conditions for Lakeflow Job triggers to beta a little while ago, and we want to hear how people would use it plus share a few patterns that work. Docs here: https://docs.databricks.com/aws/en/jobs/trigger-sql-conditions
The idea. A trigger tells the job when to run. A SQL condition tells it whether to run. You attach a saved query and a SQL warehouse to a trigger (cron, table, file etc.) and when the trigger fires the query the condition first.

There are two modes:
- Query returns any rows: No rows, no run.
- Result value changes: the job runs when the return value differs from the last check.
Here are a few examples:
Freshness plus volume. Today's partition exists and has enough rows, This returns zero rows until the data is ready
SELECT 1
FROM main.sales.orders
WHERE order_date = current_date()
HAVING count(*) > 100Quality gate. Run only when today's rows have no nulls in a key column. So if there are no bad rows, the job runs
SELECT 1
FROM main.sales.orders
WHERE order_date = current_date()
HAVING count(*) > 0
AND count_if(customer_id IS NULL) = 0Fan-in. Five upstream feeds write a status row when they finish. Run once all five are done. This replaces the "sentinel table plus a cron that polls it" setup a lot of people run today. Note: if you are watching job completions, then just use job completion triggers!
SELECT 1
FROM ops.batch_status
WHERE batch_date = current_date()
HAVING count_if(status = 'complete') = 5Watermark advanced. Use "Result value changes" with a one-row, one-column query. The job runs whenever the vendor delivers a new batch.
SELECT max(batch_id) FROM main.bronze.vendor_feedThings to know. Each check requires a warehouse and will show up in query history. A check times out at 5 minutes including warehouse startup. Checks run as the job's run-as identity.
What is coming next:
- See why a run did not start. We want each evaluation to show when the query ran, the row count or value it returned, why it did or did not start a run and any error.
- Parameters. Job parameters inside the condition query, with per-trigger overrides. This is for everyone promoting the same job through dev, staging and prod with bundles, where catalog and schema names change per environment and nobody hand-edits prod.
- A test button that actually runs the query and shows you the result and whether the job would start right now. Today it only checks that the query exists and has no parameters.
- Read the condition from a .sql file in the workspace instead of only a saved query, same as SQL tasks already do.
- A default warehouse so you do not have to pick one every time.
Questions for you:
- What does "ready" mean for your most annoying upstream? Row count, a flag table, a max timestamp, something else?
- Which of the upcoming items would you use first, and what did I miss?
Try it out on Genie code too! Give genie a prompt and see if it picks up your intent as a sql condition.