Databricks DE · Topic 10.3

SQL Alerts, Scheduled Queries & AI/BI Dashboards

Turn queries into automation and visuals: schedule queries on Quartz cron, alert when a threshold trips, and build AI/BI dashboards with Genie authoring + subscriptions — all versionable as bundle code.

scheduled query (Quartz cron)alert = query + conditionAI/BI Dashboardsas code (DABs)

The one-liner

A scheduled query runs on Quartz cron; a SQL Alert = scheduled query + a condition → notify (email/Slack); an AI/BI Dashboard = datasets + visuals on a canvas with Genie NL authoring, refresh & subscriptions — and all three deploy as Asset Bundle resources.
🚨 Analogy: a scheduled query is an automatic meter reading; an alert is a smoke detector (evaluates on a cadence, only beeps when a threshold trips); a dashboard is the car's gauge cluster — refreshed live.

Alert simulator — drag today's order count

▸ condition: alert when orders_today = 0 (pipeline failure)

320

How it works — deep dive

1 · Scheduled queries — Quartz cron on a warehouse

Mechanism: attach a schedule to a saved query; at each fire time it runs on a SQL Warehouse as the owner. Databricks uses 6-field Quartz cron (sec min hour day month dow), not 5-field Unix cron. Trade-off: cadence = freshness and cost.

# Quartz cron is 6 fields. "every day at 06:00":
schedule:
  quartz_cron_schedule: "0 0 6 * * ?"   # sec min hour day month dow
  timezone_id: America/New_York

2 · SQL Alerts — condition on a query result → notify

Mechanism: an alert points at a query, defines an evaluation (a comparison on a result column vs a threshold), and on a schedule checks it — if met, sends to notification destinations. Trade-off: evaluates only when scheduled (cadence = detection lag); condition-only, not arbitrary logic.

-- The alert's backing query returns ONE row/column to compare.
-- Condition (set in the alert): WHEN orders_today = 0 → notify on-call.
SELECT count(*) AS orders_today
FROM prod.sales.orders
WHERE order_date = current_date();

3 · Alerts & schedules as code — Asset Bundle

Mechanism: the alert bundle resource (SQL alert v2) declares the query, evaluation, schedule, and warehouse — versioned and promoted by CI/CD. Trade-off: the bundle is the source of truth; UI edits get reverted on the next deploy.

# databricks.yml — verified keys (alert v2 resource)
resources:
  alerts:
    orders_zero_alert:
      display_name: orders_zero_alert
      query_text: "SELECT count(*) AS orders_today FROM prod.sales.orders WHERE order_date = current_date()"
      evaluation:
        comparison_operator: EQUAL      # EQUAL / GREATER_THAN / LESS_THAN …
        source: { name: orders_today }  # result column to compare
        threshold: { value: { double_value: 0 } }
      schedule:
        quartz_cron_schedule: "0 0 6 * * ?"
        timezone_id: America/New_York
      warehouse_id: ${var.warehouse_id}

4 · AI/BI Dashboards — datasets, visuals, filters, subscriptions

Mechanism: datasets (queries) feed the canvas; visualizations + parameters/filters cross-filter widgets; author by hand or with Genie (NL), then publish with scheduled refresh + email/Slack subscriptions. Trade-off: runs on a warehouse (cold-start latency); refresh runs as the publisher — mind permissions/cost. Successor to retired legacy/Redash dashboards.

-- A dashboard DATASET is a query, usually parameterized so filters work:
SELECT region, sum(amount) AS revenue
FROM prod.sales.orders
WHERE order_date BETWEEN :start_date AND :end_date
GROUP BY region ORDER BY revenue DESC;

5 · Dashboards as code — bundle the .lvdash.json

Mechanism: an AI/BI Dashboard serializes to *.lvdash.json; the dashboard bundle resource references that file + a warehouse. databricks bundle generate dashboard exports an existing one. Trade-off: the JSON is generated — edit in the UI then re-export, don't hand-edit.

# databricks.yml — verified keys (dashboard resource)
resources:
  dashboards:
    revenue_overview:
      display_name: "Revenue Overview"
      file_path: ../src/revenue_overview.lvdash.json
      warehouse_id: ${var.warehouse_id}

# export an existing dashboard, then deploy:
# databricks bundle generate dashboard --existing-path "/Workspace/.../Revenue Overview"
# databricks bundle deploy -t prod

Three tools — click each

Scheduled query — run a saved query on a 6-field Quartz cron on a chosen SQL Warehouse, no manual Run. Runs as the owner.
SQL Alert — a scheduled query + a condition (e.g. = 0, > threshold); when met, sends to notification destinations (email/Slack/webhook). Fires only when the schedule runs.
AI/BI Dashboard — datasets + visualizations on an interactive canvas; build charts via Genie NL; global/page/widget filters; publish with scheduled refresh + email/Slack subscriptions. (Legacy/Redash dashboards are retired.)

Why it matters

🌅 Real-world use case: a scheduled query computes daily order counts; a SQL Alert emails on-call if today's count is 0; an AI/BI Dashboard shows revenue by region with a daily Slack subscription — all defined in a bundle and promoted by CI/CD.

Uses, edge cases & limitations

Common gotchas