Repository navigation
Conversation
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
|
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 If you're an external contributor, no action is needed; a maintainer will review your pull request. |
|
An authorized user can trigger integration tests manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
|
An authorized user can trigger integration tests manually by following the instructions below: Trigger: Inputs:
Checks will be approved automatically on success. |
Changes
An alert's
file_pathcan now point to a.sqlfile. The file providesquery_text, and every other alert field (evaluation, schedule, custom_summary, ...) stays in the bundle YAML:This lives in
LoadDBAlertFiles, next to the existing.dbalert.jsonhandling, and reuses its bundle-root path anchoring (pulled into a small helper). Setting bothfile_path(.sql) andquery_textis 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 thefile_pathdescription inannotations.ymland 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 aBUNDLE_VAR_*env var.I reused
file_pathbecause it already means "load this alert from a local file" and is resolved and anchored to the bundle root. A separate field likequery_file_pathwould also work if you prefer that.Tests
resources/alerts/with_sql_file(validate, deploy,get-alert, no drift on re-plan, editing the.sqlfile shows an update and redeploys the new query) andresources/alerts/with_sql_file_query_text_error.load_dbalert_files_test.gofor the YAML fields being kept, a.SQLextension, 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(onlydeploy/spark-jar-taskandtemplates/pydabs/check-formattingfail locally, the same as onmainin my environment), golangci-lint on the changed packages, the schema generator (no further diff) andpytest databricks_testsinpython/.Written with AI assistance (Claude); I reviewed and tested it locally.