Skip to content

Support .sql files in file_path for alerts - #7330

Open
Mohith26 wants to merge 2 commits into
databricks:mainfrom
Mohith26:alerts-sql-file-path
Open

Mohith26 wants to merge 2 commits into
databricks:mainfrom
Mohith26:alerts-sql-file-path

Conversation

@Mohith26

@Mohith26 Mohith26 commented Nov 4, 2026

Copy link
Copy Markdown

Changes

An alert's file_path can now point to a .sql file. The file provides query_text, and every other alert field (evaluation, schedule, custom_summary, ...) stays in the bundle YAML:

resources:
  alerts:
    failed_runs:
      display_name: Failed pipeline runs
      warehouse_id: ${var.warehouse_id}
      file_path: ./sql/failed_runs.sql
      evaluation: ...
      schedule: ...

This lives in LoadDBAlertFiles, next to the existing .dbalert.json handling, and reuses its bundle-root path anchoring (pulled into a small helper). Setting both file_path (.sql) and query_text is an error, as is an empty file. Like .dbalert.json, the file is read after variable resolution, so ${...} references in it are rejected with a clear error instead of being sent to the backend verbatim. I also filled in the file_path description in annotations.yml and regenerated the JSON schema and PyDABs model.

Why

Fixes #5620. Alert queries are usually multi-line SQL, and inline YAML is hard to review and lint. Today query_text: ${file(...)} validates but deploys the literal string, and the only workaround is passing file contents through a BUNDLE_VAR_* env var.

I reused file_path because it already means "load this alert from a local file" and is resolved and anchored to the bundle root. A separate field like query_file_path would also work if you prefer that.

Tests

  • New acceptance tests: resources/alerts/with_sql_file (validate, deploy, get-alert, no drift on re-plan, editing the .sql file shows an update and redeploys the new query) and resources/alerts/with_sql_file_query_text_error.
  • Unit tests in load_dbalert_files_test.go for the YAML fields being kept, a .SQL extension, and the error cases (query_text set, missing file, empty file, variable reference).
  • go test ./bundle/config/... ./bundle/internal/schema/..., go test ./acceptance -run TestAccept/bundle -short (only deploy/spark-jar-task and templates/pydabs/check-formatting fail locally, the same as on main in my environment), golangci-lint on the changed packages, the schema generator (no further diff) and pytest databricks_tests in python/.

Written with AI assistance (Claude); I reviewed and tested it locally.

Let an alert's file_path point to a .sql file that provides query_text,
while all other alert fields stay in the bundle configuration. This keeps
multi-line alert queries in a real SQL file that can be reviewed and linted.

Fixes databricks#5620
@Mohith26
Mohith26 requested review from a team as code owners November 4, 2026 03:58
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Thanks for the contribution! This pull request was opened from a fork.

If you're a member of the Databricks organization, please request access to the cli-contrib team and open your pull request from a branch in this repository instead of a fork — fork PRs don't run integration tests automatically and have reduced CI access.

If you're an external contributor, no action is needed; a maintainer will review your pull request.

@github-actions github-actions Bot added the DABs DABs related issues label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

An authorized user can trigger integration tests manually by following the instructions below:

Trigger:
go/deco-tests-run/cli

Inputs:

  • PR number: 7330
  • Commit SHA: 87e52b61e40d7635c5dc372c1f6e7d6737c7aaa3

Checks will be approved automatically on success.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

An authorized user can trigger integration tests manually by following the instructions below:

Trigger:
go/deco-tests-run/cli

Inputs:

  • PR number: 7330
  • Commit SHA: f6b9cbc717b4a1a7255cc4fdf38440d0b6dd3154

Checks will be approved automatically on success.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DABs DABs related issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support referencing an external .sql file for query_text in resources.alerts

1 participant