Add Databricks SQL warehouse lifecycle operators - #70088

Merged
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle
Aug 17, 2026
Merged

Add Databricks SQL warehouse lifecycle operators#70088
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle

Conversation

@Vamsi-klu

@Vamsi-kluVamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This adds first-class operators for starting and stopping existing Databricks SQL warehouses, including optional polling until the requested lifecycle state is reached.

related: #21377

Problem

Airflow's Databricks provider can execute SQL against a warehouse, but it has no first-class way to manage an existing warehouse's start/stop lifecycle. Dag authors currently need custom REST calls around their SQL tasks.

What changed

  • Add DatabricksHook methods for retrieving, starting, and stopping a warehouse through the Databricks SQL Warehouses API.
  • Add a validated WarehouseState model for the six documented lifecycle states.
  • Add DatabricksStartWarehouseOperator and DatabricksStopWarehouseOperator with idempotent pre-checks, optional waiting, monotonic deadlines, and explicit terminal-state errors.
  • Register the operators in provider metadata and add a how-to guide plus a system-test example with unconditional stop cleanup.

Warehouse IDs are embedded in the documented REST paths; no request-body workaround or new dependency is introduced. The implementation follows the Databricks SQL Warehouses API.

Scope

This is the Phase 1 scope proposed on #21377: get/state/start/stop plus synchronous waiting. Create/delete, edit, warehouse-by-name resolution, async hooks, and deferrable operators remain outside this PR so the initial contribution stays reviewable and independently useful.

Behavior and compatibility

  • Starting an already RUNNING warehouse and stopping an already STOPPED warehouse are no-ops.
  • Existing STARTING/STOPPING transitions are reused instead of issuing duplicate requests.
  • A start accepted while the warehouse still reports STOPPING continues polling; Databricks API transition rejections propagate unchanged.
  • Waiting uses time.monotonic(), starts no new poll after the configured deadline, and still honors a target or deletion state returned by a poll that began before the deadline.
  • The new operator validates templated warehouse IDs at execution time and remains import-compatible across supported Airflow versions through common.compat.sdk.

Validation

  • breeze run pytest providers/databricks/tests/unit/databricks/operators/test_databricks_warehouse.py -xvs — 23 passed.
  • breeze testing providers-tests --test-type "Providers[databricks]" — 842 passed, 12 skipped.
  • breeze testing providers-tests --test-type "Providers[amazon,common.compat,common.sql,databricks,google,openlineage]" — 11,858 passed, 185 skipped.
  • breeze run mypy providers/databricks/src/airflow/providers/databricks/exceptions.py providers/databricks/src/airflow/providers/databricks/hooks/databricks.py providers/databricks/src/airflow/providers/databricks/operators/databricks_warehouse.py — success, no issues.
  • Explicit nine-file prek pre-commit checks — passed.
  • Explicit nine-file prek manual checks — passed, including the providers mypy hook.
  • breeze build-docs --docs-only --clean-build databricks — documentation build successful; the generated guide contains both lifecycle examples.
  • breeze run pytest providers/databricks/tests/system/databricks/example_databricks_sql_warehouse.py --collect-only -q — 1 system test collected.
  • breeze ci selective-check --commit-ref HEAD — selected provider unit/compatibility tests, provider mypy, docs, Python scans, and the system-test path; no UI tests selected.

Reviewer evidence

This PR has no UI surface, so before/after screenshots and browser validation are not applicable. The REST boundary is covered with autospecced request assertions, operator behavior is covered with a specced hook, and the system example is import-validated. No Databricks workspace credentials were used or required for these deterministic lifecycle tests.

The narrow Phase 1 scope was posted on the issue before implementation: #21377 (comment)


Was generative AI tooling used to co-author this PR?
  • Yes — Codex (GPT-5)

Generated-by: Codex (GPT-5) following the guidelines

@Vamsi-klu

Vamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
ContributorAuthor

Local validation evidence for the Databricks SQL warehouse lifecycle implementation:

  • Focused operator suite: 21 passed.
  • Full Databricks provider suite: 838 passed, 12 skipped.
  • Selective six-provider dependency matrix: 11,858 passed, 185 skipped.
  • Changed-source mypy: Success: no issues found in 3 source files.
  • Explicit pre-commit and manual prek checks: passed; the manual run included the providers mypy hook.
  • Databricks docs build: successful; generated output contains both start and stop examples.
  • System-test example: one test_run collected successfully.
  • Selective-check analysis selected the expected provider unit/compatibility, provider mypy, docs, Python scan, and system-test jobs; it selected no UI work.

The tests assert the exact Databricks Warehouses API paths, idempotent start/stop behavior, transition-in-progress behavior, terminal failure states, templated-ID validation, and strict monotonic timeout handling.

There are no UI changes in this PR, so screenshots would not add reviewer signal. No Databricks credentials were used: REST calls are mocked at the hook boundary, while the system-test Dag is import-validated. Live workspace execution can be added later if a reviewer specifically requests it.


Drafted-by: Codex (GPT-5)

@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal@moomindani Can i get some feedack/Stamp for the PR please? Thanks!

@Vamsi-klu
Vamsi-klu marked this pull request as ready for review July 19, 2026 07:01
@potiukpotiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 20, 2026

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — nice, self-contained contribution.

Conventions I checked and found consistent: _DatabricksWarehouseBaseOperator sharing start/stop mirrors GCP's _DataprocStartStopClusterBaseOperator; WarehouseState follows the existing RunState / SQLStatementState shape in the hook; and wait_for_termination / polling_period_seconds / databricks_retry_* match DatabricksSQLStatementsOperator — note these differ from AWS's wait_for_completion, but matching the provider is the right precedence. time.monotonic(), spec/autospec mocks, and the all_done cleanup task in the system example are all correct.

I validated the lifecycle behaviour against a real workspace (2X-Small serverless warehouse, auto_stop_mins=10) rather than only reading the code:

ProbeObserved
POST /start from STOPPED, then tight-poll GET3/3 trials flipped STOPPED -> STARTING within 0.45-0.46s
POST /stop from RUNNINGreached STOPPED in ~2s
Start requested while stoppingSTARTING at t=3s, RUNNING at t=8s, no API rejection

Two things I'd like maintainer input on, then some small cleanups.

1. STOPPED as a start-path failure state is racy. The first poll after start_warehouse() runs with no time.sleep() in between, so a single lagging GET fails the task even though the start succeeded. Sub-second in my probes, but structural — details and a reproduction inline.

2. Shipping these without a deferrable mode is the part I'd most like a second opinion on. I know the PR body scopes deferrable out of Phase 1, and I understand wanting to keep the first contribution reviewable. But start/stop are multi-minute waits that hold a worker slot for their whole duration, which is the canonical case for deferrable operators — and the comparable operators elsewhere all have one:

  • AWS RedshiftResumeClusterOperator / RedshiftPauseClusterOperatordeferrable + dedicated triggers
  • GCP DataprocStartClusterOperator / DataprocStopClusterOperatordeferrable
  • This provider's own DatabricksRunNowOperator, DatabricksSQLStatementsOperator, and sensors — all deferrable

So these two operators would be the only blocking-poll operators in the Databricks provider. My concern is less "please add it now" and more that deferring it has a compatibility cost: once released, wait_for_termination and timeout are public API, and retrofitting deferrable around them is awkward — DatabricksSQLStatementsOperator needs its "wait_timeout": "0s" trick precisely to make one set of parameters serve both paths. Doing it up front is cheaper than reconciling it later.

The groundwork is mostly there: the hook already has _a_do_api_call, and the existing a_get_cluster_state / a_get_sql_statement_state are only a handful of lines each, so a_get_warehouse_state plus a DatabricksWarehouseStateTrigger alongside the two existing triggers looks like a modest addition rather than a redesign.

I'm not blocking on this — it is a scope judgement that belongs to the committers, not to me, and "merge Phase 1 now, add deferrable in Phase 2" is a legitimate answer if the parameter surface is settled deliberately. I'd just rather it be an explicit decision than an omission noticed after release.

Also ran locally:

  • pytest test_databricks_warehouse.py test_databricks.py — 149 passed.
  • prek --stage pre-commit — the only two failures are Update providers build files and Validate provider.yaml files, both from Docker not running on my machine, not from your diff.

Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6a5489 to c6f018dCompareJuly 27, 2026 05:26
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@moomindani, thanks for the thorough review and for validating the lifecycle behavior against a real workspace.

I pushed c6f018d and addressed all four inline comments:

  • Start polling now treats a STOPPED response immediately after the start request as potentially stale and continues until RUNNING, deletion, or timeout. The regression test covers STOPPED pre-check → start request → stale STOPPED poll → RUNNING.
  • The shared polling path now uses WarehouseState.is_deleted as the source of truth for terminal deletion states.
  • Hook construction is inlined into the cached _hook property.
  • The unused ENV_ID assignment is removed from the system-test example.

I also corrected the PR description's timeout wording: no new poll starts after the deadline, while a target or deletion state returned by an already-started poll is still honored.

On deferrable execution: I agree it would be valuable, but I am deliberately keeping it in Phase 2 rather than broadening this Phase 1 PR. That scope was recorded on #21377 and in the PR description before implementation. Since the warehouse start/stop endpoints return immediately, a future deferrable path can remain additive while preserving wait_for_termination, polling_period_seconds, and timeout. That follow-up will need the async state hook, serialized trigger and timeout behavior, operator completion path, and compatibility tests. If a committer considers deferrable execution a pre-merge requirement, I can revisit the scope here.

Validation on the rebased branch:

  • Full Databricks provider suite: 842 passed, 12 skipped.
  • Focused operator and warehouse-hook suites: 35 passed.
  • System-test example: 1 test collected.
  • Provider mypy: Success: no issues found.
  • Branch-level pre-commit and manual prek checks: passed.

Drafted-by: Codex (GPT-5); reviewed by @Vamsi-klu before posting

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified c6f018d by running it rather than reading the summary — all four are correctly addressed.

The race fix is the right shape: dropping the failure_states parameter and keying terminal detection off state.is_deleted fixes finding 1 and 2 in one move. I re-ran my original reproduction and the behaviour is now:

ScenarioBeforeNow
STOPPED (pre-check) → stale STOPPEDRUNNINGerrorreaches RUNNING
Warehouse never leaves STOPPEDerror (misleading)timeout, last state: STOPPED
DELETING mid-waiterrorerror (unchanged)

That is exactly the trade I hoped for — a genuine never-starts now surfaces as a timeout with the last observed state in the message, which is more diagnosable than the old immediate failure.

The test updates are what I'd have asked for: parametrizing test_starts_then_waits_until_running over ["STARTING", "STOPPED"] pins the regression, and re-pointing the start leg of test_execute_raises_on_failure_state from STOPPED to DELETING keeps the terminal-state assertion meaningful instead of just deleting it. 150 passed locally. prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff. Diff against current main is your 9 files only.

On deferrable: that's a reasonable answer, and recording it explicitly is all I was after. My concern was an unexamined omission, not the choice itself — you've now stated the Phase 2 plan and the parameter-compatibility reasoning, so a committer can weigh it deliberately. No objection from me to merging Phase 1 as scoped.

Nothing further from my side.


Drafted-by: Claude Code (Opus 5)

@eladkal

Copy link
Copy Markdown
Contributor

So @moomindani if I get it right you are approving the change?

A slow final status request can finish after the deadline even when it confirms the requested state. Treating that observation as a timeout can fail an otherwise successful Dag.
A warehouse can still report STOPPED immediately after the start request because the API response is eventually consistent. Keep polling until RUNNING or deletion/timeout so valid starts do not fail spuriously.
@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6f018d to a486797CompareJuly 31, 2026 06:51
@Vamsi-klu

Vamsi-klu commented Jul 31, 2026

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal All four findings are addressed and retested per your review. @moomindani the review is marked COMMENTED. Can i get maintainer approval please? Thanks!

@eladkal
eladkal self-requested a review August 6, 2026 05:48

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there is an open point around defer support. What is the plan here?

Comment threadproviders/databricks/src/airflow/providers/databricks/hooks/databricks.py Outdated
Comment threadproviders/databricks/docs/operators/sql_warehouse.rst Outdated

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladkal sorry for the slow reply to your question from Jul 27 — yes, as far as my own review goes I have no remaining objections. All four findings I raised were addressed, and I re-verified on a486797 rather than re-reading the summary: stale STOPPED after start now reaches RUNNING, a warehouse that never leaves STOPPED times out with the last observed state, and 150 tests pass. The warehouse code is byte-identical to the c6f018d I checked earlier.

I am deliberately not marking this approved, though, because your four points from Aug 6 are still open and three of them need code changes. I checked them and they all hold:

  • File naming (warehouse.py) — amazon uses athena.py / ec2.py, google uses bigquery.py; none repeat the provider name, so the existing databricks_*.py files are the deviation.
  • Unused hook methods — confirmed. WarehouseState.to_json / from_json have no production caller; only test_databricks.py:1619 round-trips them against themselves. (is_deleted is now used by _wait_for_state, so that one is fine.)
  • Docs — agreed, drop the system-test framing at sql_warehouse.rst:49 and just describe what the trigger rule does.

Separately: the branch is 186 commits behind main. Diffed against main it looks like this PR reverts #70130 and #69442 — that is a stale-base artifact, not a real revert (against the merge base it is only the 9 files of this PR). Worth rebasing so CI runs on current main and that diff stops misleading reviewers.


Drafted-by: Claude Code (Opus 5)

Vamsi-kluand others added 2 commits August 8, 2026 04:50
…rehouse-lifecycle
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Rename the operator module to warehouse.py to follow provider naming
conventions, drop the unused WarehouseState.to_json/from_json helpers
that have no production caller until the deferrable trigger lands, and
describe the all_done trigger rule behavior in the docs without
referring to system tests.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal pushed 727bfc3, which covers all four of your points: the module is renamed to warehouse.py, the unused WarehouseState serializers are gone, and the docs no longer mention system tests.

On defer support, my plan was to add it as a follow-up rather than fold it in here. Phase 2 adds a_get_warehouse_state to the hook plus a DatabricksWarehouseStateTrigger next to the two triggers the provider already has, keeping wait_for_termination, polling_period_seconds and timeout exactly as they are, so deferrable lands as an additive change rather than a parameter redesign. @moomindani reviewed that reasoning and had no objection to merging phase 1 as scoped. If you would rather see deferrable in this PR before it merges, say so and I will extend it here instead.

@moomindani I also merged latest main in the same push, so the diff no longer looks like it reverts #70130 and #69442.

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on 727bfc3. All four of @eladkal's points are addressed and my own earlier findings still hold — verified by running it, not by re-reading the summary.

@eladkal's points:

  • Renameoperators/warehouse.py and tests/.../test_warehouse.py, with the module path updated in both provider.yaml and get_provider_info.py. No stale references to the old name anywhere in the provider.
  • Unused serializersWarehouseState.to_json / from_json are gone. is_deleted is kept, which is right: it is the terminal-state check in _wait_for_state.
  • Docs — the system-test framing is gone from sql_warehouse.rst.

My findings, re-checked: stale STOPPED right after start still reaches RUNNING; a warehouse that never leaves STOPPED still surfaces as a timeout with the last observed state; DELETING mid-wait is still fatal. 149 tests pass locally, CI is 56/56 green, and prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff.

One correction to something I said on my previous pass, in case it caused any confusion: I reported that diffing against main made this PR look like it reverted #70130 and #69442. That was my local main being stale, not a problem with your branch. Against the correct merge base this PR is 9 files, +831/-1 — only its own work. Apologies for the noise.

The branch is now behind main again (56 commits) simply because main moved since your push; a rebase before merge is worth it for CI freshness, but the misleading-diff problem I raised earlier is resolved.

On deferrable: your Phase 2 plan is recorded and @eladkal has the question in front of him, so that is a scope call for the committers. No objection from me to merging Phase 1 as scoped.


Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from 2f6b872 to 727bfc3CompareAugust 15, 2026 06:10
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal, quick status. cc @moomindani

All four points from your Aug 6 review are in 727bfc3, and those threads are resolved. moomindani approved on Aug 12 after checking the lifecycle against a real workspace.

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here. Happy to rebase onto latest main if you want a fresh CI run.

@eladkal

Copy link
Copy Markdown
Contributor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM will merge after last open item is fixed

Comment threadproviders/databricks/docs/operators/warehouse.rst
Match the operator module name so the how-to page follows the
same provider naming convention as warehouse.py.
Co-authored-by: nrvamsi13 <nrvamsi13@gmail.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

@eladkal

Copy link
Copy Markdown
Contributor

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

yes

@eladkal
eladkal merged commit 263fafc into apache:mainAug 17, 2026
158 of 159 checks passed
@Vamsi-klu

Vamsi-klu commented Aug 18, 2026

Copy link
Copy Markdown
ContributorAuthor

Follow-up for the agreed deferrable warehouse path: #71752

@Vamsi-klu
Vamsi-klu deleted the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
@Vamsi-klu
Vamsi-klu restored the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
cursorBot pushed a commit to Vamsi-klu/airflow that referenced this pull request Aug 24, 2026
Start and stop waits from apache#70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
eladkal pushed a commit that referenced this pull request Aug 26, 2026
* Add deferrable mode to Databricks SQL warehouse operators
Start and stop waits from #70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Honor Databricks warehouse deferrable timeout across triggerer restarts
A duration recomputed inside the trigger started a fresh wait after every triggerer restart or HA rebalance, so a warehouse that never reached its target could stay deferred well past the configured timeout.
* Fix Databricks warehouse trigger docs spellcheck
Sphinx treats the HA term as a misspelling and fails the provider docs job.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@Vamsi-klu@eladkal@moomindani@potiuk@cursoragent
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Add Databricks SQL warehouse lifecycle operators - #70088

Merged
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle
Aug 17, 2026
Merged

Add Databricks SQL warehouse lifecycle operators#70088
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle

Conversation

@Vamsi-klu

@Vamsi-kluVamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This adds first-class operators for starting and stopping existing Databricks SQL warehouses, including optional polling until the requested lifecycle state is reached.

related: #21377

Problem

Airflow's Databricks provider can execute SQL against a warehouse, but it has no first-class way to manage an existing warehouse's start/stop lifecycle. Dag authors currently need custom REST calls around their SQL tasks.

What changed

  • Add DatabricksHook methods for retrieving, starting, and stopping a warehouse through the Databricks SQL Warehouses API.
  • Add a validated WarehouseState model for the six documented lifecycle states.
  • Add DatabricksStartWarehouseOperator and DatabricksStopWarehouseOperator with idempotent pre-checks, optional waiting, monotonic deadlines, and explicit terminal-state errors.
  • Register the operators in provider metadata and add a how-to guide plus a system-test example with unconditional stop cleanup.

Warehouse IDs are embedded in the documented REST paths; no request-body workaround or new dependency is introduced. The implementation follows the Databricks SQL Warehouses API.

Scope

This is the Phase 1 scope proposed on #21377: get/state/start/stop plus synchronous waiting. Create/delete, edit, warehouse-by-name resolution, async hooks, and deferrable operators remain outside this PR so the initial contribution stays reviewable and independently useful.

Behavior and compatibility

  • Starting an already RUNNING warehouse and stopping an already STOPPED warehouse are no-ops.
  • Existing STARTING/STOPPING transitions are reused instead of issuing duplicate requests.
  • A start accepted while the warehouse still reports STOPPING continues polling; Databricks API transition rejections propagate unchanged.
  • Waiting uses time.monotonic(), starts no new poll after the configured deadline, and still honors a target or deletion state returned by a poll that began before the deadline.
  • The new operator validates templated warehouse IDs at execution time and remains import-compatible across supported Airflow versions through common.compat.sdk.

Validation

  • breeze run pytest providers/databricks/tests/unit/databricks/operators/test_databricks_warehouse.py -xvs — 23 passed.
  • breeze testing providers-tests --test-type "Providers[databricks]" — 842 passed, 12 skipped.
  • breeze testing providers-tests --test-type "Providers[amazon,common.compat,common.sql,databricks,google,openlineage]" — 11,858 passed, 185 skipped.
  • breeze run mypy providers/databricks/src/airflow/providers/databricks/exceptions.py providers/databricks/src/airflow/providers/databricks/hooks/databricks.py providers/databricks/src/airflow/providers/databricks/operators/databricks_warehouse.py — success, no issues.
  • Explicit nine-file prek pre-commit checks — passed.
  • Explicit nine-file prek manual checks — passed, including the providers mypy hook.
  • breeze build-docs --docs-only --clean-build databricks — documentation build successful; the generated guide contains both lifecycle examples.
  • breeze run pytest providers/databricks/tests/system/databricks/example_databricks_sql_warehouse.py --collect-only -q — 1 system test collected.
  • breeze ci selective-check --commit-ref HEAD — selected provider unit/compatibility tests, provider mypy, docs, Python scans, and the system-test path; no UI tests selected.

Reviewer evidence

This PR has no UI surface, so before/after screenshots and browser validation are not applicable. The REST boundary is covered with autospecced request assertions, operator behavior is covered with a specced hook, and the system example is import-validated. No Databricks workspace credentials were used or required for these deterministic lifecycle tests.

The narrow Phase 1 scope was posted on the issue before implementation: #21377 (comment)


Was generative AI tooling used to co-author this PR?
  • Yes — Codex (GPT-5)

Generated-by: Codex (GPT-5) following the guidelines

@Vamsi-klu

Vamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
ContributorAuthor

Local validation evidence for the Databricks SQL warehouse lifecycle implementation:

  • Focused operator suite: 21 passed.
  • Full Databricks provider suite: 838 passed, 12 skipped.
  • Selective six-provider dependency matrix: 11,858 passed, 185 skipped.
  • Changed-source mypy: Success: no issues found in 3 source files.
  • Explicit pre-commit and manual prek checks: passed; the manual run included the providers mypy hook.
  • Databricks docs build: successful; generated output contains both start and stop examples.
  • System-test example: one test_run collected successfully.
  • Selective-check analysis selected the expected provider unit/compatibility, provider mypy, docs, Python scan, and system-test jobs; it selected no UI work.

The tests assert the exact Databricks Warehouses API paths, idempotent start/stop behavior, transition-in-progress behavior, terminal failure states, templated-ID validation, and strict monotonic timeout handling.

There are no UI changes in this PR, so screenshots would not add reviewer signal. No Databricks credentials were used: REST calls are mocked at the hook boundary, while the system-test Dag is import-validated. Live workspace execution can be added later if a reviewer specifically requests it.


Drafted-by: Codex (GPT-5)

@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal@moomindani Can i get some feedack/Stamp for the PR please? Thanks!

@Vamsi-klu
Vamsi-klu marked this pull request as ready for review July 19, 2026 07:01
@potiukpotiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 20, 2026

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — nice, self-contained contribution.

Conventions I checked and found consistent: _DatabricksWarehouseBaseOperator sharing start/stop mirrors GCP's _DataprocStartStopClusterBaseOperator; WarehouseState follows the existing RunState / SQLStatementState shape in the hook; and wait_for_termination / polling_period_seconds / databricks_retry_* match DatabricksSQLStatementsOperator — note these differ from AWS's wait_for_completion, but matching the provider is the right precedence. time.monotonic(), spec/autospec mocks, and the all_done cleanup task in the system example are all correct.

I validated the lifecycle behaviour against a real workspace (2X-Small serverless warehouse, auto_stop_mins=10) rather than only reading the code:

ProbeObserved
POST /start from STOPPED, then tight-poll GET3/3 trials flipped STOPPED -> STARTING within 0.45-0.46s
POST /stop from RUNNINGreached STOPPED in ~2s
Start requested while stoppingSTARTING at t=3s, RUNNING at t=8s, no API rejection

Two things I'd like maintainer input on, then some small cleanups.

1. STOPPED as a start-path failure state is racy. The first poll after start_warehouse() runs with no time.sleep() in between, so a single lagging GET fails the task even though the start succeeded. Sub-second in my probes, but structural — details and a reproduction inline.

2. Shipping these without a deferrable mode is the part I'd most like a second opinion on. I know the PR body scopes deferrable out of Phase 1, and I understand wanting to keep the first contribution reviewable. But start/stop are multi-minute waits that hold a worker slot for their whole duration, which is the canonical case for deferrable operators — and the comparable operators elsewhere all have one:

  • AWS RedshiftResumeClusterOperator / RedshiftPauseClusterOperatordeferrable + dedicated triggers
  • GCP DataprocStartClusterOperator / DataprocStopClusterOperatordeferrable
  • This provider's own DatabricksRunNowOperator, DatabricksSQLStatementsOperator, and sensors — all deferrable

So these two operators would be the only blocking-poll operators in the Databricks provider. My concern is less "please add it now" and more that deferring it has a compatibility cost: once released, wait_for_termination and timeout are public API, and retrofitting deferrable around them is awkward — DatabricksSQLStatementsOperator needs its "wait_timeout": "0s" trick precisely to make one set of parameters serve both paths. Doing it up front is cheaper than reconciling it later.

The groundwork is mostly there: the hook already has _a_do_api_call, and the existing a_get_cluster_state / a_get_sql_statement_state are only a handful of lines each, so a_get_warehouse_state plus a DatabricksWarehouseStateTrigger alongside the two existing triggers looks like a modest addition rather than a redesign.

I'm not blocking on this — it is a scope judgement that belongs to the committers, not to me, and "merge Phase 1 now, add deferrable in Phase 2" is a legitimate answer if the parameter surface is settled deliberately. I'd just rather it be an explicit decision than an omission noticed after release.

Also ran locally:

  • pytest test_databricks_warehouse.py test_databricks.py — 149 passed.
  • prek --stage pre-commit — the only two failures are Update providers build files and Validate provider.yaml files, both from Docker not running on my machine, not from your diff.

Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6a5489 to c6f018dCompareJuly 27, 2026 05:26
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@moomindani, thanks for the thorough review and for validating the lifecycle behavior against a real workspace.

I pushed c6f018d and addressed all four inline comments:

  • Start polling now treats a STOPPED response immediately after the start request as potentially stale and continues until RUNNING, deletion, or timeout. The regression test covers STOPPED pre-check → start request → stale STOPPED poll → RUNNING.
  • The shared polling path now uses WarehouseState.is_deleted as the source of truth for terminal deletion states.
  • Hook construction is inlined into the cached _hook property.
  • The unused ENV_ID assignment is removed from the system-test example.

I also corrected the PR description's timeout wording: no new poll starts after the deadline, while a target or deletion state returned by an already-started poll is still honored.

On deferrable execution: I agree it would be valuable, but I am deliberately keeping it in Phase 2 rather than broadening this Phase 1 PR. That scope was recorded on #21377 and in the PR description before implementation. Since the warehouse start/stop endpoints return immediately, a future deferrable path can remain additive while preserving wait_for_termination, polling_period_seconds, and timeout. That follow-up will need the async state hook, serialized trigger and timeout behavior, operator completion path, and compatibility tests. If a committer considers deferrable execution a pre-merge requirement, I can revisit the scope here.

Validation on the rebased branch:

  • Full Databricks provider suite: 842 passed, 12 skipped.
  • Focused operator and warehouse-hook suites: 35 passed.
  • System-test example: 1 test collected.
  • Provider mypy: Success: no issues found.
  • Branch-level pre-commit and manual prek checks: passed.

Drafted-by: Codex (GPT-5); reviewed by @Vamsi-klu before posting

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified c6f018d by running it rather than reading the summary — all four are correctly addressed.

The race fix is the right shape: dropping the failure_states parameter and keying terminal detection off state.is_deleted fixes finding 1 and 2 in one move. I re-ran my original reproduction and the behaviour is now:

ScenarioBeforeNow
STOPPED (pre-check) → stale STOPPEDRUNNINGerrorreaches RUNNING
Warehouse never leaves STOPPEDerror (misleading)timeout, last state: STOPPED
DELETING mid-waiterrorerror (unchanged)

That is exactly the trade I hoped for — a genuine never-starts now surfaces as a timeout with the last observed state in the message, which is more diagnosable than the old immediate failure.

The test updates are what I'd have asked for: parametrizing test_starts_then_waits_until_running over ["STARTING", "STOPPED"] pins the regression, and re-pointing the start leg of test_execute_raises_on_failure_state from STOPPED to DELETING keeps the terminal-state assertion meaningful instead of just deleting it. 150 passed locally. prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff. Diff against current main is your 9 files only.

On deferrable: that's a reasonable answer, and recording it explicitly is all I was after. My concern was an unexamined omission, not the choice itself — you've now stated the Phase 2 plan and the parameter-compatibility reasoning, so a committer can weigh it deliberately. No objection from me to merging Phase 1 as scoped.

Nothing further from my side.


Drafted-by: Claude Code (Opus 5)

@eladkal

Copy link
Copy Markdown
Contributor

So @moomindani if I get it right you are approving the change?

A slow final status request can finish after the deadline even when it confirms the requested state. Treating that observation as a timeout can fail an otherwise successful Dag.
A warehouse can still report STOPPED immediately after the start request because the API response is eventually consistent. Keep polling until RUNNING or deletion/timeout so valid starts do not fail spuriously.
@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6f018d to a486797CompareJuly 31, 2026 06:51
@Vamsi-klu

Vamsi-klu commented Jul 31, 2026

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal All four findings are addressed and retested per your review. @moomindani the review is marked COMMENTED. Can i get maintainer approval please? Thanks!

@eladkal
eladkal self-requested a review August 6, 2026 05:48

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there is an open point around defer support. What is the plan here?

Comment threadproviders/databricks/src/airflow/providers/databricks/hooks/databricks.py Outdated
Comment threadproviders/databricks/docs/operators/sql_warehouse.rst Outdated

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladkal sorry for the slow reply to your question from Jul 27 — yes, as far as my own review goes I have no remaining objections. All four findings I raised were addressed, and I re-verified on a486797 rather than re-reading the summary: stale STOPPED after start now reaches RUNNING, a warehouse that never leaves STOPPED times out with the last observed state, and 150 tests pass. The warehouse code is byte-identical to the c6f018d I checked earlier.

I am deliberately not marking this approved, though, because your four points from Aug 6 are still open and three of them need code changes. I checked them and they all hold:

  • File naming (warehouse.py) — amazon uses athena.py / ec2.py, google uses bigquery.py; none repeat the provider name, so the existing databricks_*.py files are the deviation.
  • Unused hook methods — confirmed. WarehouseState.to_json / from_json have no production caller; only test_databricks.py:1619 round-trips them against themselves. (is_deleted is now used by _wait_for_state, so that one is fine.)
  • Docs — agreed, drop the system-test framing at sql_warehouse.rst:49 and just describe what the trigger rule does.

Separately: the branch is 186 commits behind main. Diffed against main it looks like this PR reverts #70130 and #69442 — that is a stale-base artifact, not a real revert (against the merge base it is only the 9 files of this PR). Worth rebasing so CI runs on current main and that diff stops misleading reviewers.


Drafted-by: Claude Code (Opus 5)

Vamsi-kluand others added 2 commits August 8, 2026 04:50
…rehouse-lifecycle
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Rename the operator module to warehouse.py to follow provider naming
conventions, drop the unused WarehouseState.to_json/from_json helpers
that have no production caller until the deferrable trigger lands, and
describe the all_done trigger rule behavior in the docs without
referring to system tests.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal pushed 727bfc3, which covers all four of your points: the module is renamed to warehouse.py, the unused WarehouseState serializers are gone, and the docs no longer mention system tests.

On defer support, my plan was to add it as a follow-up rather than fold it in here. Phase 2 adds a_get_warehouse_state to the hook plus a DatabricksWarehouseStateTrigger next to the two triggers the provider already has, keeping wait_for_termination, polling_period_seconds and timeout exactly as they are, so deferrable lands as an additive change rather than a parameter redesign. @moomindani reviewed that reasoning and had no objection to merging phase 1 as scoped. If you would rather see deferrable in this PR before it merges, say so and I will extend it here instead.

@moomindani I also merged latest main in the same push, so the diff no longer looks like it reverts #70130 and #69442.

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on 727bfc3. All four of @eladkal's points are addressed and my own earlier findings still hold — verified by running it, not by re-reading the summary.

@eladkal's points:

  • Renameoperators/warehouse.py and tests/.../test_warehouse.py, with the module path updated in both provider.yaml and get_provider_info.py. No stale references to the old name anywhere in the provider.
  • Unused serializersWarehouseState.to_json / from_json are gone. is_deleted is kept, which is right: it is the terminal-state check in _wait_for_state.
  • Docs — the system-test framing is gone from sql_warehouse.rst.

My findings, re-checked: stale STOPPED right after start still reaches RUNNING; a warehouse that never leaves STOPPED still surfaces as a timeout with the last observed state; DELETING mid-wait is still fatal. 149 tests pass locally, CI is 56/56 green, and prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff.

One correction to something I said on my previous pass, in case it caused any confusion: I reported that diffing against main made this PR look like it reverted #70130 and #69442. That was my local main being stale, not a problem with your branch. Against the correct merge base this PR is 9 files, +831/-1 — only its own work. Apologies for the noise.

The branch is now behind main again (56 commits) simply because main moved since your push; a rebase before merge is worth it for CI freshness, but the misleading-diff problem I raised earlier is resolved.

On deferrable: your Phase 2 plan is recorded and @eladkal has the question in front of him, so that is a scope call for the committers. No objection from me to merging Phase 1 as scoped.


Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from 2f6b872 to 727bfc3CompareAugust 15, 2026 06:10
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal, quick status. cc @moomindani

All four points from your Aug 6 review are in 727bfc3, and those threads are resolved. moomindani approved on Aug 12 after checking the lifecycle against a real workspace.

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here. Happy to rebase onto latest main if you want a fresh CI run.

@eladkal

Copy link
Copy Markdown
Contributor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM will merge after last open item is fixed

Comment threadproviders/databricks/docs/operators/warehouse.rst
Match the operator module name so the how-to page follows the
same provider naming convention as warehouse.py.
Co-authored-by: nrvamsi13 <nrvamsi13@gmail.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

@eladkal

Copy link
Copy Markdown
Contributor

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

yes

@eladkal
eladkal merged commit 263fafc into apache:mainAug 17, 2026
158 of 159 checks passed
@Vamsi-klu

Vamsi-klu commented Aug 18, 2026

Copy link
Copy Markdown
ContributorAuthor

Follow-up for the agreed deferrable warehouse path: #71752

@Vamsi-klu
Vamsi-klu deleted the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
@Vamsi-klu
Vamsi-klu restored the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
cursorBot pushed a commit to Vamsi-klu/airflow that referenced this pull request Aug 24, 2026
Start and stop waits from apache#70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
eladkal pushed a commit that referenced this pull request Aug 26, 2026
* Add deferrable mode to Databricks SQL warehouse operators
Start and stop waits from #70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Honor Databricks warehouse deferrable timeout across triggerer restarts
A duration recomputed inside the trigger started a fresh wait after every triggerer restart or HA rebalance, so a warehouse that never reached its target could stay deferred well past the configured timeout.
* Fix Databricks warehouse trigger docs spellcheck
Sphinx treats the HA term as a misspelling and fails the provider docs job.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@Vamsi-klu@eladkal@moomindani@potiuk@cursoragent
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add Databricks SQL warehouse lifecycle operators - #70088

Merged
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle
Aug 17, 2026
Merged

Add Databricks SQL warehouse lifecycle operators#70088
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle

Conversation

@Vamsi-klu

@Vamsi-kluVamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This adds first-class operators for starting and stopping existing Databricks SQL warehouses, including optional polling until the requested lifecycle state is reached.

related: #21377

Problem

Airflow's Databricks provider can execute SQL against a warehouse, but it has no first-class way to manage an existing warehouse's start/stop lifecycle. Dag authors currently need custom REST calls around their SQL tasks.

What changed

  • Add DatabricksHook methods for retrieving, starting, and stopping a warehouse through the Databricks SQL Warehouses API.
  • Add a validated WarehouseState model for the six documented lifecycle states.
  • Add DatabricksStartWarehouseOperator and DatabricksStopWarehouseOperator with idempotent pre-checks, optional waiting, monotonic deadlines, and explicit terminal-state errors.
  • Register the operators in provider metadata and add a how-to guide plus a system-test example with unconditional stop cleanup.

Warehouse IDs are embedded in the documented REST paths; no request-body workaround or new dependency is introduced. The implementation follows the Databricks SQL Warehouses API.

Scope

This is the Phase 1 scope proposed on #21377: get/state/start/stop plus synchronous waiting. Create/delete, edit, warehouse-by-name resolution, async hooks, and deferrable operators remain outside this PR so the initial contribution stays reviewable and independently useful.

Behavior and compatibility

  • Starting an already RUNNING warehouse and stopping an already STOPPED warehouse are no-ops.
  • Existing STARTING/STOPPING transitions are reused instead of issuing duplicate requests.
  • A start accepted while the warehouse still reports STOPPING continues polling; Databricks API transition rejections propagate unchanged.
  • Waiting uses time.monotonic(), starts no new poll after the configured deadline, and still honors a target or deletion state returned by a poll that began before the deadline.
  • The new operator validates templated warehouse IDs at execution time and remains import-compatible across supported Airflow versions through common.compat.sdk.

Validation

  • breeze run pytest providers/databricks/tests/unit/databricks/operators/test_databricks_warehouse.py -xvs — 23 passed.
  • breeze testing providers-tests --test-type "Providers[databricks]" — 842 passed, 12 skipped.
  • breeze testing providers-tests --test-type "Providers[amazon,common.compat,common.sql,databricks,google,openlineage]" — 11,858 passed, 185 skipped.
  • breeze run mypy providers/databricks/src/airflow/providers/databricks/exceptions.py providers/databricks/src/airflow/providers/databricks/hooks/databricks.py providers/databricks/src/airflow/providers/databricks/operators/databricks_warehouse.py — success, no issues.
  • Explicit nine-file prek pre-commit checks — passed.
  • Explicit nine-file prek manual checks — passed, including the providers mypy hook.
  • breeze build-docs --docs-only --clean-build databricks — documentation build successful; the generated guide contains both lifecycle examples.
  • breeze run pytest providers/databricks/tests/system/databricks/example_databricks_sql_warehouse.py --collect-only -q — 1 system test collected.
  • breeze ci selective-check --commit-ref HEAD — selected provider unit/compatibility tests, provider mypy, docs, Python scans, and the system-test path; no UI tests selected.

Reviewer evidence

This PR has no UI surface, so before/after screenshots and browser validation are not applicable. The REST boundary is covered with autospecced request assertions, operator behavior is covered with a specced hook, and the system example is import-validated. No Databricks workspace credentials were used or required for these deterministic lifecycle tests.

The narrow Phase 1 scope was posted on the issue before implementation: #21377 (comment)


Was generative AI tooling used to co-author this PR?
  • Yes — Codex (GPT-5)

Generated-by: Codex (GPT-5) following the guidelines

@Vamsi-klu

Vamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
ContributorAuthor

Local validation evidence for the Databricks SQL warehouse lifecycle implementation:

  • Focused operator suite: 21 passed.
  • Full Databricks provider suite: 838 passed, 12 skipped.
  • Selective six-provider dependency matrix: 11,858 passed, 185 skipped.
  • Changed-source mypy: Success: no issues found in 3 source files.
  • Explicit pre-commit and manual prek checks: passed; the manual run included the providers mypy hook.
  • Databricks docs build: successful; generated output contains both start and stop examples.
  • System-test example: one test_run collected successfully.
  • Selective-check analysis selected the expected provider unit/compatibility, provider mypy, docs, Python scan, and system-test jobs; it selected no UI work.

The tests assert the exact Databricks Warehouses API paths, idempotent start/stop behavior, transition-in-progress behavior, terminal failure states, templated-ID validation, and strict monotonic timeout handling.

There are no UI changes in this PR, so screenshots would not add reviewer signal. No Databricks credentials were used: REST calls are mocked at the hook boundary, while the system-test Dag is import-validated. Live workspace execution can be added later if a reviewer specifically requests it.


Drafted-by: Codex (GPT-5)

@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal@moomindani Can i get some feedack/Stamp for the PR please? Thanks!

@Vamsi-klu
Vamsi-klu marked this pull request as ready for review July 19, 2026 07:01
@potiukpotiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 20, 2026

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — nice, self-contained contribution.

Conventions I checked and found consistent: _DatabricksWarehouseBaseOperator sharing start/stop mirrors GCP's _DataprocStartStopClusterBaseOperator; WarehouseState follows the existing RunState / SQLStatementState shape in the hook; and wait_for_termination / polling_period_seconds / databricks_retry_* match DatabricksSQLStatementsOperator — note these differ from AWS's wait_for_completion, but matching the provider is the right precedence. time.monotonic(), spec/autospec mocks, and the all_done cleanup task in the system example are all correct.

I validated the lifecycle behaviour against a real workspace (2X-Small serverless warehouse, auto_stop_mins=10) rather than only reading the code:

ProbeObserved
POST /start from STOPPED, then tight-poll GET3/3 trials flipped STOPPED -> STARTING within 0.45-0.46s
POST /stop from RUNNINGreached STOPPED in ~2s
Start requested while stoppingSTARTING at t=3s, RUNNING at t=8s, no API rejection

Two things I'd like maintainer input on, then some small cleanups.

1. STOPPED as a start-path failure state is racy. The first poll after start_warehouse() runs with no time.sleep() in between, so a single lagging GET fails the task even though the start succeeded. Sub-second in my probes, but structural — details and a reproduction inline.

2. Shipping these without a deferrable mode is the part I'd most like a second opinion on. I know the PR body scopes deferrable out of Phase 1, and I understand wanting to keep the first contribution reviewable. But start/stop are multi-minute waits that hold a worker slot for their whole duration, which is the canonical case for deferrable operators — and the comparable operators elsewhere all have one:

  • AWS RedshiftResumeClusterOperator / RedshiftPauseClusterOperatordeferrable + dedicated triggers
  • GCP DataprocStartClusterOperator / DataprocStopClusterOperatordeferrable
  • This provider's own DatabricksRunNowOperator, DatabricksSQLStatementsOperator, and sensors — all deferrable

So these two operators would be the only blocking-poll operators in the Databricks provider. My concern is less "please add it now" and more that deferring it has a compatibility cost: once released, wait_for_termination and timeout are public API, and retrofitting deferrable around them is awkward — DatabricksSQLStatementsOperator needs its "wait_timeout": "0s" trick precisely to make one set of parameters serve both paths. Doing it up front is cheaper than reconciling it later.

The groundwork is mostly there: the hook already has _a_do_api_call, and the existing a_get_cluster_state / a_get_sql_statement_state are only a handful of lines each, so a_get_warehouse_state plus a DatabricksWarehouseStateTrigger alongside the two existing triggers looks like a modest addition rather than a redesign.

I'm not blocking on this — it is a scope judgement that belongs to the committers, not to me, and "merge Phase 1 now, add deferrable in Phase 2" is a legitimate answer if the parameter surface is settled deliberately. I'd just rather it be an explicit decision than an omission noticed after release.

Also ran locally:

  • pytest test_databricks_warehouse.py test_databricks.py — 149 passed.
  • prek --stage pre-commit — the only two failures are Update providers build files and Validate provider.yaml files, both from Docker not running on my machine, not from your diff.

Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6a5489 to c6f018dCompareJuly 27, 2026 05:26
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@moomindani, thanks for the thorough review and for validating the lifecycle behavior against a real workspace.

I pushed c6f018d and addressed all four inline comments:

  • Start polling now treats a STOPPED response immediately after the start request as potentially stale and continues until RUNNING, deletion, or timeout. The regression test covers STOPPED pre-check → start request → stale STOPPED poll → RUNNING.
  • The shared polling path now uses WarehouseState.is_deleted as the source of truth for terminal deletion states.
  • Hook construction is inlined into the cached _hook property.
  • The unused ENV_ID assignment is removed from the system-test example.

I also corrected the PR description's timeout wording: no new poll starts after the deadline, while a target or deletion state returned by an already-started poll is still honored.

On deferrable execution: I agree it would be valuable, but I am deliberately keeping it in Phase 2 rather than broadening this Phase 1 PR. That scope was recorded on #21377 and in the PR description before implementation. Since the warehouse start/stop endpoints return immediately, a future deferrable path can remain additive while preserving wait_for_termination, polling_period_seconds, and timeout. That follow-up will need the async state hook, serialized trigger and timeout behavior, operator completion path, and compatibility tests. If a committer considers deferrable execution a pre-merge requirement, I can revisit the scope here.

Validation on the rebased branch:

  • Full Databricks provider suite: 842 passed, 12 skipped.
  • Focused operator and warehouse-hook suites: 35 passed.
  • System-test example: 1 test collected.
  • Provider mypy: Success: no issues found.
  • Branch-level pre-commit and manual prek checks: passed.

Drafted-by: Codex (GPT-5); reviewed by @Vamsi-klu before posting

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified c6f018d by running it rather than reading the summary — all four are correctly addressed.

The race fix is the right shape: dropping the failure_states parameter and keying terminal detection off state.is_deleted fixes finding 1 and 2 in one move. I re-ran my original reproduction and the behaviour is now:

ScenarioBeforeNow
STOPPED (pre-check) → stale STOPPEDRUNNINGerrorreaches RUNNING
Warehouse never leaves STOPPEDerror (misleading)timeout, last state: STOPPED
DELETING mid-waiterrorerror (unchanged)

That is exactly the trade I hoped for — a genuine never-starts now surfaces as a timeout with the last observed state in the message, which is more diagnosable than the old immediate failure.

The test updates are what I'd have asked for: parametrizing test_starts_then_waits_until_running over ["STARTING", "STOPPED"] pins the regression, and re-pointing the start leg of test_execute_raises_on_failure_state from STOPPED to DELETING keeps the terminal-state assertion meaningful instead of just deleting it. 150 passed locally. prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff. Diff against current main is your 9 files only.

On deferrable: that's a reasonable answer, and recording it explicitly is all I was after. My concern was an unexamined omission, not the choice itself — you've now stated the Phase 2 plan and the parameter-compatibility reasoning, so a committer can weigh it deliberately. No objection from me to merging Phase 1 as scoped.

Nothing further from my side.


Drafted-by: Claude Code (Opus 5)

@eladkal

Copy link
Copy Markdown
Contributor

So @moomindani if I get it right you are approving the change?

A slow final status request can finish after the deadline even when it confirms the requested state. Treating that observation as a timeout can fail an otherwise successful Dag.
A warehouse can still report STOPPED immediately after the start request because the API response is eventually consistent. Keep polling until RUNNING or deletion/timeout so valid starts do not fail spuriously.
@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6f018d to a486797CompareJuly 31, 2026 06:51
@Vamsi-klu

Vamsi-klu commented Jul 31, 2026

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal All four findings are addressed and retested per your review. @moomindani the review is marked COMMENTED. Can i get maintainer approval please? Thanks!

@eladkal
eladkal self-requested a review August 6, 2026 05:48

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there is an open point around defer support. What is the plan here?

Comment threadproviders/databricks/src/airflow/providers/databricks/hooks/databricks.py Outdated
Comment threadproviders/databricks/docs/operators/sql_warehouse.rst Outdated

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladkal sorry for the slow reply to your question from Jul 27 — yes, as far as my own review goes I have no remaining objections. All four findings I raised were addressed, and I re-verified on a486797 rather than re-reading the summary: stale STOPPED after start now reaches RUNNING, a warehouse that never leaves STOPPED times out with the last observed state, and 150 tests pass. The warehouse code is byte-identical to the c6f018d I checked earlier.

I am deliberately not marking this approved, though, because your four points from Aug 6 are still open and three of them need code changes. I checked them and they all hold:

  • File naming (warehouse.py) — amazon uses athena.py / ec2.py, google uses bigquery.py; none repeat the provider name, so the existing databricks_*.py files are the deviation.
  • Unused hook methods — confirmed. WarehouseState.to_json / from_json have no production caller; only test_databricks.py:1619 round-trips them against themselves. (is_deleted is now used by _wait_for_state, so that one is fine.)
  • Docs — agreed, drop the system-test framing at sql_warehouse.rst:49 and just describe what the trigger rule does.

Separately: the branch is 186 commits behind main. Diffed against main it looks like this PR reverts #70130 and #69442 — that is a stale-base artifact, not a real revert (against the merge base it is only the 9 files of this PR). Worth rebasing so CI runs on current main and that diff stops misleading reviewers.


Drafted-by: Claude Code (Opus 5)

Vamsi-kluand others added 2 commits August 8, 2026 04:50
…rehouse-lifecycle
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Rename the operator module to warehouse.py to follow provider naming
conventions, drop the unused WarehouseState.to_json/from_json helpers
that have no production caller until the deferrable trigger lands, and
describe the all_done trigger rule behavior in the docs without
referring to system tests.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal pushed 727bfc3, which covers all four of your points: the module is renamed to warehouse.py, the unused WarehouseState serializers are gone, and the docs no longer mention system tests.

On defer support, my plan was to add it as a follow-up rather than fold it in here. Phase 2 adds a_get_warehouse_state to the hook plus a DatabricksWarehouseStateTrigger next to the two triggers the provider already has, keeping wait_for_termination, polling_period_seconds and timeout exactly as they are, so deferrable lands as an additive change rather than a parameter redesign. @moomindani reviewed that reasoning and had no objection to merging phase 1 as scoped. If you would rather see deferrable in this PR before it merges, say so and I will extend it here instead.

@moomindani I also merged latest main in the same push, so the diff no longer looks like it reverts #70130 and #69442.

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on 727bfc3. All four of @eladkal's points are addressed and my own earlier findings still hold — verified by running it, not by re-reading the summary.

@eladkal's points:

  • Renameoperators/warehouse.py and tests/.../test_warehouse.py, with the module path updated in both provider.yaml and get_provider_info.py. No stale references to the old name anywhere in the provider.
  • Unused serializersWarehouseState.to_json / from_json are gone. is_deleted is kept, which is right: it is the terminal-state check in _wait_for_state.
  • Docs — the system-test framing is gone from sql_warehouse.rst.

My findings, re-checked: stale STOPPED right after start still reaches RUNNING; a warehouse that never leaves STOPPED still surfaces as a timeout with the last observed state; DELETING mid-wait is still fatal. 149 tests pass locally, CI is 56/56 green, and prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff.

One correction to something I said on my previous pass, in case it caused any confusion: I reported that diffing against main made this PR look like it reverted #70130 and #69442. That was my local main being stale, not a problem with your branch. Against the correct merge base this PR is 9 files, +831/-1 — only its own work. Apologies for the noise.

The branch is now behind main again (56 commits) simply because main moved since your push; a rebase before merge is worth it for CI freshness, but the misleading-diff problem I raised earlier is resolved.

On deferrable: your Phase 2 plan is recorded and @eladkal has the question in front of him, so that is a scope call for the committers. No objection from me to merging Phase 1 as scoped.


Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from 2f6b872 to 727bfc3CompareAugust 15, 2026 06:10
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal, quick status. cc @moomindani

All four points from your Aug 6 review are in 727bfc3, and those threads are resolved. moomindani approved on Aug 12 after checking the lifecycle against a real workspace.

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here. Happy to rebase onto latest main if you want a fresh CI run.

@eladkal

Copy link
Copy Markdown
Contributor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM will merge after last open item is fixed

Comment threadproviders/databricks/docs/operators/warehouse.rst
Match the operator module name so the how-to page follows the
same provider naming convention as warehouse.py.
Co-authored-by: nrvamsi13 <nrvamsi13@gmail.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

@eladkal

Copy link
Copy Markdown
Contributor

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

yes

@eladkal
eladkal merged commit 263fafc into apache:mainAug 17, 2026
158 of 159 checks passed
@Vamsi-klu

Vamsi-klu commented Aug 18, 2026

Copy link
Copy Markdown
ContributorAuthor

Follow-up for the agreed deferrable warehouse path: #71752

@Vamsi-klu
Vamsi-klu deleted the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
@Vamsi-klu
Vamsi-klu restored the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
cursorBot pushed a commit to Vamsi-klu/airflow that referenced this pull request Aug 24, 2026
Start and stop waits from apache#70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
eladkal pushed a commit that referenced this pull request Aug 26, 2026
* Add deferrable mode to Databricks SQL warehouse operators
Start and stop waits from #70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Honor Databricks warehouse deferrable timeout across triggerer restarts
A duration recomputed inside the trigger started a fresh wait after every triggerer restart or HA rebalance, so a warehouse that never reached its target could stay deferred well past the configured timeout.
* Fix Databricks warehouse trigger docs spellcheck
Sphinx treats the HA term as a misspelling and fails the provider docs job.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@Vamsi-klu@eladkal@moomindani@potiuk@cursoragent
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add Databricks SQL warehouse lifecycle operators - #70088

Merged
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle
Aug 17, 2026
Merged

Add Databricks SQL warehouse lifecycle operators#70088
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle

Conversation

@Vamsi-klu

@Vamsi-kluVamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This adds first-class operators for starting and stopping existing Databricks SQL warehouses, including optional polling until the requested lifecycle state is reached.

related: #21377

Problem

Airflow's Databricks provider can execute SQL against a warehouse, but it has no first-class way to manage an existing warehouse's start/stop lifecycle. Dag authors currently need custom REST calls around their SQL tasks.

What changed

  • Add DatabricksHook methods for retrieving, starting, and stopping a warehouse through the Databricks SQL Warehouses API.
  • Add a validated WarehouseState model for the six documented lifecycle states.
  • Add DatabricksStartWarehouseOperator and DatabricksStopWarehouseOperator with idempotent pre-checks, optional waiting, monotonic deadlines, and explicit terminal-state errors.
  • Register the operators in provider metadata and add a how-to guide plus a system-test example with unconditional stop cleanup.

Warehouse IDs are embedded in the documented REST paths; no request-body workaround or new dependency is introduced. The implementation follows the Databricks SQL Warehouses API.

Scope

This is the Phase 1 scope proposed on #21377: get/state/start/stop plus synchronous waiting. Create/delete, edit, warehouse-by-name resolution, async hooks, and deferrable operators remain outside this PR so the initial contribution stays reviewable and independently useful.

Behavior and compatibility

  • Starting an already RUNNING warehouse and stopping an already STOPPED warehouse are no-ops.
  • Existing STARTING/STOPPING transitions are reused instead of issuing duplicate requests.
  • A start accepted while the warehouse still reports STOPPING continues polling; Databricks API transition rejections propagate unchanged.
  • Waiting uses time.monotonic(), starts no new poll after the configured deadline, and still honors a target or deletion state returned by a poll that began before the deadline.
  • The new operator validates templated warehouse IDs at execution time and remains import-compatible across supported Airflow versions through common.compat.sdk.

Validation

  • breeze run pytest providers/databricks/tests/unit/databricks/operators/test_databricks_warehouse.py -xvs — 23 passed.
  • breeze testing providers-tests --test-type "Providers[databricks]" — 842 passed, 12 skipped.
  • breeze testing providers-tests --test-type "Providers[amazon,common.compat,common.sql,databricks,google,openlineage]" — 11,858 passed, 185 skipped.
  • breeze run mypy providers/databricks/src/airflow/providers/databricks/exceptions.py providers/databricks/src/airflow/providers/databricks/hooks/databricks.py providers/databricks/src/airflow/providers/databricks/operators/databricks_warehouse.py — success, no issues.
  • Explicit nine-file prek pre-commit checks — passed.
  • Explicit nine-file prek manual checks — passed, including the providers mypy hook.
  • breeze build-docs --docs-only --clean-build databricks — documentation build successful; the generated guide contains both lifecycle examples.
  • breeze run pytest providers/databricks/tests/system/databricks/example_databricks_sql_warehouse.py --collect-only -q — 1 system test collected.
  • breeze ci selective-check --commit-ref HEAD — selected provider unit/compatibility tests, provider mypy, docs, Python scans, and the system-test path; no UI tests selected.

Reviewer evidence

This PR has no UI surface, so before/after screenshots and browser validation are not applicable. The REST boundary is covered with autospecced request assertions, operator behavior is covered with a specced hook, and the system example is import-validated. No Databricks workspace credentials were used or required for these deterministic lifecycle tests.

The narrow Phase 1 scope was posted on the issue before implementation: #21377 (comment)


Was generative AI tooling used to co-author this PR?
  • Yes — Codex (GPT-5)

Generated-by: Codex (GPT-5) following the guidelines

@Vamsi-klu

Vamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
ContributorAuthor

Local validation evidence for the Databricks SQL warehouse lifecycle implementation:

  • Focused operator suite: 21 passed.
  • Full Databricks provider suite: 838 passed, 12 skipped.
  • Selective six-provider dependency matrix: 11,858 passed, 185 skipped.
  • Changed-source mypy: Success: no issues found in 3 source files.
  • Explicit pre-commit and manual prek checks: passed; the manual run included the providers mypy hook.
  • Databricks docs build: successful; generated output contains both start and stop examples.
  • System-test example: one test_run collected successfully.
  • Selective-check analysis selected the expected provider unit/compatibility, provider mypy, docs, Python scan, and system-test jobs; it selected no UI work.

The tests assert the exact Databricks Warehouses API paths, idempotent start/stop behavior, transition-in-progress behavior, terminal failure states, templated-ID validation, and strict monotonic timeout handling.

There are no UI changes in this PR, so screenshots would not add reviewer signal. No Databricks credentials were used: REST calls are mocked at the hook boundary, while the system-test Dag is import-validated. Live workspace execution can be added later if a reviewer specifically requests it.


Drafted-by: Codex (GPT-5)

@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal@moomindani Can i get some feedack/Stamp for the PR please? Thanks!

@Vamsi-klu
Vamsi-klu marked this pull request as ready for review July 19, 2026 07:01
@potiukpotiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 20, 2026

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — nice, self-contained contribution.

Conventions I checked and found consistent: _DatabricksWarehouseBaseOperator sharing start/stop mirrors GCP's _DataprocStartStopClusterBaseOperator; WarehouseState follows the existing RunState / SQLStatementState shape in the hook; and wait_for_termination / polling_period_seconds / databricks_retry_* match DatabricksSQLStatementsOperator — note these differ from AWS's wait_for_completion, but matching the provider is the right precedence. time.monotonic(), spec/autospec mocks, and the all_done cleanup task in the system example are all correct.

I validated the lifecycle behaviour against a real workspace (2X-Small serverless warehouse, auto_stop_mins=10) rather than only reading the code:

ProbeObserved
POST /start from STOPPED, then tight-poll GET3/3 trials flipped STOPPED -> STARTING within 0.45-0.46s
POST /stop from RUNNINGreached STOPPED in ~2s
Start requested while stoppingSTARTING at t=3s, RUNNING at t=8s, no API rejection

Two things I'd like maintainer input on, then some small cleanups.

1. STOPPED as a start-path failure state is racy. The first poll after start_warehouse() runs with no time.sleep() in between, so a single lagging GET fails the task even though the start succeeded. Sub-second in my probes, but structural — details and a reproduction inline.

2. Shipping these without a deferrable mode is the part I'd most like a second opinion on. I know the PR body scopes deferrable out of Phase 1, and I understand wanting to keep the first contribution reviewable. But start/stop are multi-minute waits that hold a worker slot for their whole duration, which is the canonical case for deferrable operators — and the comparable operators elsewhere all have one:

  • AWS RedshiftResumeClusterOperator / RedshiftPauseClusterOperatordeferrable + dedicated triggers
  • GCP DataprocStartClusterOperator / DataprocStopClusterOperatordeferrable
  • This provider's own DatabricksRunNowOperator, DatabricksSQLStatementsOperator, and sensors — all deferrable

So these two operators would be the only blocking-poll operators in the Databricks provider. My concern is less "please add it now" and more that deferring it has a compatibility cost: once released, wait_for_termination and timeout are public API, and retrofitting deferrable around them is awkward — DatabricksSQLStatementsOperator needs its "wait_timeout": "0s" trick precisely to make one set of parameters serve both paths. Doing it up front is cheaper than reconciling it later.

The groundwork is mostly there: the hook already has _a_do_api_call, and the existing a_get_cluster_state / a_get_sql_statement_state are only a handful of lines each, so a_get_warehouse_state plus a DatabricksWarehouseStateTrigger alongside the two existing triggers looks like a modest addition rather than a redesign.

I'm not blocking on this — it is a scope judgement that belongs to the committers, not to me, and "merge Phase 1 now, add deferrable in Phase 2" is a legitimate answer if the parameter surface is settled deliberately. I'd just rather it be an explicit decision than an omission noticed after release.

Also ran locally:

  • pytest test_databricks_warehouse.py test_databricks.py — 149 passed.
  • prek --stage pre-commit — the only two failures are Update providers build files and Validate provider.yaml files, both from Docker not running on my machine, not from your diff.

Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6a5489 to c6f018dCompareJuly 27, 2026 05:26
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@moomindani, thanks for the thorough review and for validating the lifecycle behavior against a real workspace.

I pushed c6f018d and addressed all four inline comments:

  • Start polling now treats a STOPPED response immediately after the start request as potentially stale and continues until RUNNING, deletion, or timeout. The regression test covers STOPPED pre-check → start request → stale STOPPED poll → RUNNING.
  • The shared polling path now uses WarehouseState.is_deleted as the source of truth for terminal deletion states.
  • Hook construction is inlined into the cached _hook property.
  • The unused ENV_ID assignment is removed from the system-test example.

I also corrected the PR description's timeout wording: no new poll starts after the deadline, while a target or deletion state returned by an already-started poll is still honored.

On deferrable execution: I agree it would be valuable, but I am deliberately keeping it in Phase 2 rather than broadening this Phase 1 PR. That scope was recorded on #21377 and in the PR description before implementation. Since the warehouse start/stop endpoints return immediately, a future deferrable path can remain additive while preserving wait_for_termination, polling_period_seconds, and timeout. That follow-up will need the async state hook, serialized trigger and timeout behavior, operator completion path, and compatibility tests. If a committer considers deferrable execution a pre-merge requirement, I can revisit the scope here.

Validation on the rebased branch:

  • Full Databricks provider suite: 842 passed, 12 skipped.
  • Focused operator and warehouse-hook suites: 35 passed.
  • System-test example: 1 test collected.
  • Provider mypy: Success: no issues found.
  • Branch-level pre-commit and manual prek checks: passed.

Drafted-by: Codex (GPT-5); reviewed by @Vamsi-klu before posting

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified c6f018d by running it rather than reading the summary — all four are correctly addressed.

The race fix is the right shape: dropping the failure_states parameter and keying terminal detection off state.is_deleted fixes finding 1 and 2 in one move. I re-ran my original reproduction and the behaviour is now:

ScenarioBeforeNow
STOPPED (pre-check) → stale STOPPEDRUNNINGerrorreaches RUNNING
Warehouse never leaves STOPPEDerror (misleading)timeout, last state: STOPPED
DELETING mid-waiterrorerror (unchanged)

That is exactly the trade I hoped for — a genuine never-starts now surfaces as a timeout with the last observed state in the message, which is more diagnosable than the old immediate failure.

The test updates are what I'd have asked for: parametrizing test_starts_then_waits_until_running over ["STARTING", "STOPPED"] pins the regression, and re-pointing the start leg of test_execute_raises_on_failure_state from STOPPED to DELETING keeps the terminal-state assertion meaningful instead of just deleting it. 150 passed locally. prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff. Diff against current main is your 9 files only.

On deferrable: that's a reasonable answer, and recording it explicitly is all I was after. My concern was an unexamined omission, not the choice itself — you've now stated the Phase 2 plan and the parameter-compatibility reasoning, so a committer can weigh it deliberately. No objection from me to merging Phase 1 as scoped.

Nothing further from my side.


Drafted-by: Claude Code (Opus 5)

@eladkal

Copy link
Copy Markdown
Contributor

So @moomindani if I get it right you are approving the change?

A slow final status request can finish after the deadline even when it confirms the requested state. Treating that observation as a timeout can fail an otherwise successful Dag.
A warehouse can still report STOPPED immediately after the start request because the API response is eventually consistent. Keep polling until RUNNING or deletion/timeout so valid starts do not fail spuriously.
@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6f018d to a486797CompareJuly 31, 2026 06:51
@Vamsi-klu

Vamsi-klu commented Jul 31, 2026

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal All four findings are addressed and retested per your review. @moomindani the review is marked COMMENTED. Can i get maintainer approval please? Thanks!

@eladkal
eladkal self-requested a review August 6, 2026 05:48

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there is an open point around defer support. What is the plan here?

Comment threadproviders/databricks/src/airflow/providers/databricks/hooks/databricks.py Outdated
Comment threadproviders/databricks/docs/operators/sql_warehouse.rst Outdated

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladkal sorry for the slow reply to your question from Jul 27 — yes, as far as my own review goes I have no remaining objections. All four findings I raised were addressed, and I re-verified on a486797 rather than re-reading the summary: stale STOPPED after start now reaches RUNNING, a warehouse that never leaves STOPPED times out with the last observed state, and 150 tests pass. The warehouse code is byte-identical to the c6f018d I checked earlier.

I am deliberately not marking this approved, though, because your four points from Aug 6 are still open and three of them need code changes. I checked them and they all hold:

  • File naming (warehouse.py) — amazon uses athena.py / ec2.py, google uses bigquery.py; none repeat the provider name, so the existing databricks_*.py files are the deviation.
  • Unused hook methods — confirmed. WarehouseState.to_json / from_json have no production caller; only test_databricks.py:1619 round-trips them against themselves. (is_deleted is now used by _wait_for_state, so that one is fine.)
  • Docs — agreed, drop the system-test framing at sql_warehouse.rst:49 and just describe what the trigger rule does.

Separately: the branch is 186 commits behind main. Diffed against main it looks like this PR reverts #70130 and #69442 — that is a stale-base artifact, not a real revert (against the merge base it is only the 9 files of this PR). Worth rebasing so CI runs on current main and that diff stops misleading reviewers.


Drafted-by: Claude Code (Opus 5)

Vamsi-kluand others added 2 commits August 8, 2026 04:50
…rehouse-lifecycle
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Rename the operator module to warehouse.py to follow provider naming
conventions, drop the unused WarehouseState.to_json/from_json helpers
that have no production caller until the deferrable trigger lands, and
describe the all_done trigger rule behavior in the docs without
referring to system tests.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal pushed 727bfc3, which covers all four of your points: the module is renamed to warehouse.py, the unused WarehouseState serializers are gone, and the docs no longer mention system tests.

On defer support, my plan was to add it as a follow-up rather than fold it in here. Phase 2 adds a_get_warehouse_state to the hook plus a DatabricksWarehouseStateTrigger next to the two triggers the provider already has, keeping wait_for_termination, polling_period_seconds and timeout exactly as they are, so deferrable lands as an additive change rather than a parameter redesign. @moomindani reviewed that reasoning and had no objection to merging phase 1 as scoped. If you would rather see deferrable in this PR before it merges, say so and I will extend it here instead.

@moomindani I also merged latest main in the same push, so the diff no longer looks like it reverts #70130 and #69442.

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on 727bfc3. All four of @eladkal's points are addressed and my own earlier findings still hold — verified by running it, not by re-reading the summary.

@eladkal's points:

  • Renameoperators/warehouse.py and tests/.../test_warehouse.py, with the module path updated in both provider.yaml and get_provider_info.py. No stale references to the old name anywhere in the provider.
  • Unused serializersWarehouseState.to_json / from_json are gone. is_deleted is kept, which is right: it is the terminal-state check in _wait_for_state.
  • Docs — the system-test framing is gone from sql_warehouse.rst.

My findings, re-checked: stale STOPPED right after start still reaches RUNNING; a warehouse that never leaves STOPPED still surfaces as a timeout with the last observed state; DELETING mid-wait is still fatal. 149 tests pass locally, CI is 56/56 green, and prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff.

One correction to something I said on my previous pass, in case it caused any confusion: I reported that diffing against main made this PR look like it reverted #70130 and #69442. That was my local main being stale, not a problem with your branch. Against the correct merge base this PR is 9 files, +831/-1 — only its own work. Apologies for the noise.

The branch is now behind main again (56 commits) simply because main moved since your push; a rebase before merge is worth it for CI freshness, but the misleading-diff problem I raised earlier is resolved.

On deferrable: your Phase 2 plan is recorded and @eladkal has the question in front of him, so that is a scope call for the committers. No objection from me to merging Phase 1 as scoped.


Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from 2f6b872 to 727bfc3CompareAugust 15, 2026 06:10
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal, quick status. cc @moomindani

All four points from your Aug 6 review are in 727bfc3, and those threads are resolved. moomindani approved on Aug 12 after checking the lifecycle against a real workspace.

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here. Happy to rebase onto latest main if you want a fresh CI run.

@eladkal

Copy link
Copy Markdown
Contributor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM will merge after last open item is fixed

Comment threadproviders/databricks/docs/operators/warehouse.rst
Match the operator module name so the how-to page follows the
same provider naming convention as warehouse.py.
Co-authored-by: nrvamsi13 <nrvamsi13@gmail.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

@eladkal

Copy link
Copy Markdown
Contributor

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

yes

@eladkal
eladkal merged commit 263fafc into apache:mainAug 17, 2026
158 of 159 checks passed
@Vamsi-klu

Vamsi-klu commented Aug 18, 2026

Copy link
Copy Markdown
ContributorAuthor

Follow-up for the agreed deferrable warehouse path: #71752

@Vamsi-klu
Vamsi-klu deleted the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
@Vamsi-klu
Vamsi-klu restored the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
cursorBot pushed a commit to Vamsi-klu/airflow that referenced this pull request Aug 24, 2026
Start and stop waits from apache#70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
eladkal pushed a commit that referenced this pull request Aug 26, 2026
* Add deferrable mode to Databricks SQL warehouse operators
Start and stop waits from #70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Honor Databricks warehouse deferrable timeout across triggerer restarts
A duration recomputed inside the trigger started a fresh wait after every triggerer restart or HA rebalance, so a warehouse that never reached its target could stay deferred well past the configured timeout.
* Fix Databricks warehouse trigger docs spellcheck
Sphinx treats the HA term as a misspelling and fails the provider docs job.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@Vamsi-klu@eladkal@moomindani@potiuk@cursoragent
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Add Databricks SQL warehouse lifecycle operators - #70088

Merged
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle
Aug 17, 2026
Merged

Add Databricks SQL warehouse lifecycle operators#70088
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle

Conversation

@Vamsi-klu

@Vamsi-kluVamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This adds first-class operators for starting and stopping existing Databricks SQL warehouses, including optional polling until the requested lifecycle state is reached.

related: #21377

Problem

Airflow's Databricks provider can execute SQL against a warehouse, but it has no first-class way to manage an existing warehouse's start/stop lifecycle. Dag authors currently need custom REST calls around their SQL tasks.

What changed

  • Add DatabricksHook methods for retrieving, starting, and stopping a warehouse through the Databricks SQL Warehouses API.
  • Add a validated WarehouseState model for the six documented lifecycle states.
  • Add DatabricksStartWarehouseOperator and DatabricksStopWarehouseOperator with idempotent pre-checks, optional waiting, monotonic deadlines, and explicit terminal-state errors.
  • Register the operators in provider metadata and add a how-to guide plus a system-test example with unconditional stop cleanup.

Warehouse IDs are embedded in the documented REST paths; no request-body workaround or new dependency is introduced. The implementation follows the Databricks SQL Warehouses API.

Scope

This is the Phase 1 scope proposed on #21377: get/state/start/stop plus synchronous waiting. Create/delete, edit, warehouse-by-name resolution, async hooks, and deferrable operators remain outside this PR so the initial contribution stays reviewable and independently useful.

Behavior and compatibility

  • Starting an already RUNNING warehouse and stopping an already STOPPED warehouse are no-ops.
  • Existing STARTING/STOPPING transitions are reused instead of issuing duplicate requests.
  • A start accepted while the warehouse still reports STOPPING continues polling; Databricks API transition rejections propagate unchanged.
  • Waiting uses time.monotonic(), starts no new poll after the configured deadline, and still honors a target or deletion state returned by a poll that began before the deadline.
  • The new operator validates templated warehouse IDs at execution time and remains import-compatible across supported Airflow versions through common.compat.sdk.

Validation

  • breeze run pytest providers/databricks/tests/unit/databricks/operators/test_databricks_warehouse.py -xvs — 23 passed.
  • breeze testing providers-tests --test-type "Providers[databricks]" — 842 passed, 12 skipped.
  • breeze testing providers-tests --test-type "Providers[amazon,common.compat,common.sql,databricks,google,openlineage]" — 11,858 passed, 185 skipped.
  • breeze run mypy providers/databricks/src/airflow/providers/databricks/exceptions.py providers/databricks/src/airflow/providers/databricks/hooks/databricks.py providers/databricks/src/airflow/providers/databricks/operators/databricks_warehouse.py — success, no issues.
  • Explicit nine-file prek pre-commit checks — passed.
  • Explicit nine-file prek manual checks — passed, including the providers mypy hook.
  • breeze build-docs --docs-only --clean-build databricks — documentation build successful; the generated guide contains both lifecycle examples.
  • breeze run pytest providers/databricks/tests/system/databricks/example_databricks_sql_warehouse.py --collect-only -q — 1 system test collected.
  • breeze ci selective-check --commit-ref HEAD — selected provider unit/compatibility tests, provider mypy, docs, Python scans, and the system-test path; no UI tests selected.

Reviewer evidence

This PR has no UI surface, so before/after screenshots and browser validation are not applicable. The REST boundary is covered with autospecced request assertions, operator behavior is covered with a specced hook, and the system example is import-validated. No Databricks workspace credentials were used or required for these deterministic lifecycle tests.

The narrow Phase 1 scope was posted on the issue before implementation: #21377 (comment)


Was generative AI tooling used to co-author this PR?
  • Yes — Codex (GPT-5)

Generated-by: Codex (GPT-5) following the guidelines

@Vamsi-klu

Vamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
ContributorAuthor

Local validation evidence for the Databricks SQL warehouse lifecycle implementation:

  • Focused operator suite: 21 passed.
  • Full Databricks provider suite: 838 passed, 12 skipped.
  • Selective six-provider dependency matrix: 11,858 passed, 185 skipped.
  • Changed-source mypy: Success: no issues found in 3 source files.
  • Explicit pre-commit and manual prek checks: passed; the manual run included the providers mypy hook.
  • Databricks docs build: successful; generated output contains both start and stop examples.
  • System-test example: one test_run collected successfully.
  • Selective-check analysis selected the expected provider unit/compatibility, provider mypy, docs, Python scan, and system-test jobs; it selected no UI work.

The tests assert the exact Databricks Warehouses API paths, idempotent start/stop behavior, transition-in-progress behavior, terminal failure states, templated-ID validation, and strict monotonic timeout handling.

There are no UI changes in this PR, so screenshots would not add reviewer signal. No Databricks credentials were used: REST calls are mocked at the hook boundary, while the system-test Dag is import-validated. Live workspace execution can be added later if a reviewer specifically requests it.


Drafted-by: Codex (GPT-5)

@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal@moomindani Can i get some feedack/Stamp for the PR please? Thanks!

@Vamsi-klu
Vamsi-klu marked this pull request as ready for review July 19, 2026 07:01
@potiukpotiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 20, 2026

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — nice, self-contained contribution.

Conventions I checked and found consistent: _DatabricksWarehouseBaseOperator sharing start/stop mirrors GCP's _DataprocStartStopClusterBaseOperator; WarehouseState follows the existing RunState / SQLStatementState shape in the hook; and wait_for_termination / polling_period_seconds / databricks_retry_* match DatabricksSQLStatementsOperator — note these differ from AWS's wait_for_completion, but matching the provider is the right precedence. time.monotonic(), spec/autospec mocks, and the all_done cleanup task in the system example are all correct.

I validated the lifecycle behaviour against a real workspace (2X-Small serverless warehouse, auto_stop_mins=10) rather than only reading the code:

ProbeObserved
POST /start from STOPPED, then tight-poll GET3/3 trials flipped STOPPED -> STARTING within 0.45-0.46s
POST /stop from RUNNINGreached STOPPED in ~2s
Start requested while stoppingSTARTING at t=3s, RUNNING at t=8s, no API rejection

Two things I'd like maintainer input on, then some small cleanups.

1. STOPPED as a start-path failure state is racy. The first poll after start_warehouse() runs with no time.sleep() in between, so a single lagging GET fails the task even though the start succeeded. Sub-second in my probes, but structural — details and a reproduction inline.

2. Shipping these without a deferrable mode is the part I'd most like a second opinion on. I know the PR body scopes deferrable out of Phase 1, and I understand wanting to keep the first contribution reviewable. But start/stop are multi-minute waits that hold a worker slot for their whole duration, which is the canonical case for deferrable operators — and the comparable operators elsewhere all have one:

  • AWS RedshiftResumeClusterOperator / RedshiftPauseClusterOperatordeferrable + dedicated triggers
  • GCP DataprocStartClusterOperator / DataprocStopClusterOperatordeferrable
  • This provider's own DatabricksRunNowOperator, DatabricksSQLStatementsOperator, and sensors — all deferrable

So these two operators would be the only blocking-poll operators in the Databricks provider. My concern is less "please add it now" and more that deferring it has a compatibility cost: once released, wait_for_termination and timeout are public API, and retrofitting deferrable around them is awkward — DatabricksSQLStatementsOperator needs its "wait_timeout": "0s" trick precisely to make one set of parameters serve both paths. Doing it up front is cheaper than reconciling it later.

The groundwork is mostly there: the hook already has _a_do_api_call, and the existing a_get_cluster_state / a_get_sql_statement_state are only a handful of lines each, so a_get_warehouse_state plus a DatabricksWarehouseStateTrigger alongside the two existing triggers looks like a modest addition rather than a redesign.

I'm not blocking on this — it is a scope judgement that belongs to the committers, not to me, and "merge Phase 1 now, add deferrable in Phase 2" is a legitimate answer if the parameter surface is settled deliberately. I'd just rather it be an explicit decision than an omission noticed after release.

Also ran locally:

  • pytest test_databricks_warehouse.py test_databricks.py — 149 passed.
  • prek --stage pre-commit — the only two failures are Update providers build files and Validate provider.yaml files, both from Docker not running on my machine, not from your diff.

Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6a5489 to c6f018dCompareJuly 27, 2026 05:26
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@moomindani, thanks for the thorough review and for validating the lifecycle behavior against a real workspace.

I pushed c6f018d and addressed all four inline comments:

  • Start polling now treats a STOPPED response immediately after the start request as potentially stale and continues until RUNNING, deletion, or timeout. The regression test covers STOPPED pre-check → start request → stale STOPPED poll → RUNNING.
  • The shared polling path now uses WarehouseState.is_deleted as the source of truth for terminal deletion states.
  • Hook construction is inlined into the cached _hook property.
  • The unused ENV_ID assignment is removed from the system-test example.

I also corrected the PR description's timeout wording: no new poll starts after the deadline, while a target or deletion state returned by an already-started poll is still honored.

On deferrable execution: I agree it would be valuable, but I am deliberately keeping it in Phase 2 rather than broadening this Phase 1 PR. That scope was recorded on #21377 and in the PR description before implementation. Since the warehouse start/stop endpoints return immediately, a future deferrable path can remain additive while preserving wait_for_termination, polling_period_seconds, and timeout. That follow-up will need the async state hook, serialized trigger and timeout behavior, operator completion path, and compatibility tests. If a committer considers deferrable execution a pre-merge requirement, I can revisit the scope here.

Validation on the rebased branch:

  • Full Databricks provider suite: 842 passed, 12 skipped.
  • Focused operator and warehouse-hook suites: 35 passed.
  • System-test example: 1 test collected.
  • Provider mypy: Success: no issues found.
  • Branch-level pre-commit and manual prek checks: passed.

Drafted-by: Codex (GPT-5); reviewed by @Vamsi-klu before posting

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified c6f018d by running it rather than reading the summary — all four are correctly addressed.

The race fix is the right shape: dropping the failure_states parameter and keying terminal detection off state.is_deleted fixes finding 1 and 2 in one move. I re-ran my original reproduction and the behaviour is now:

ScenarioBeforeNow
STOPPED (pre-check) → stale STOPPEDRUNNINGerrorreaches RUNNING
Warehouse never leaves STOPPEDerror (misleading)timeout, last state: STOPPED
DELETING mid-waiterrorerror (unchanged)

That is exactly the trade I hoped for — a genuine never-starts now surfaces as a timeout with the last observed state in the message, which is more diagnosable than the old immediate failure.

The test updates are what I'd have asked for: parametrizing test_starts_then_waits_until_running over ["STARTING", "STOPPED"] pins the regression, and re-pointing the start leg of test_execute_raises_on_failure_state from STOPPED to DELETING keeps the terminal-state assertion meaningful instead of just deleting it. 150 passed locally. prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff. Diff against current main is your 9 files only.

On deferrable: that's a reasonable answer, and recording it explicitly is all I was after. My concern was an unexamined omission, not the choice itself — you've now stated the Phase 2 plan and the parameter-compatibility reasoning, so a committer can weigh it deliberately. No objection from me to merging Phase 1 as scoped.

Nothing further from my side.


Drafted-by: Claude Code (Opus 5)

@eladkal

Copy link
Copy Markdown
Contributor

So @moomindani if I get it right you are approving the change?

A slow final status request can finish after the deadline even when it confirms the requested state. Treating that observation as a timeout can fail an otherwise successful Dag.
A warehouse can still report STOPPED immediately after the start request because the API response is eventually consistent. Keep polling until RUNNING or deletion/timeout so valid starts do not fail spuriously.
@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6f018d to a486797CompareJuly 31, 2026 06:51
@Vamsi-klu

Vamsi-klu commented Jul 31, 2026

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal All four findings are addressed and retested per your review. @moomindani the review is marked COMMENTED. Can i get maintainer approval please? Thanks!

@eladkal
eladkal self-requested a review August 6, 2026 05:48

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there is an open point around defer support. What is the plan here?

Comment threadproviders/databricks/src/airflow/providers/databricks/hooks/databricks.py Outdated
Comment threadproviders/databricks/docs/operators/sql_warehouse.rst Outdated

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladkal sorry for the slow reply to your question from Jul 27 — yes, as far as my own review goes I have no remaining objections. All four findings I raised were addressed, and I re-verified on a486797 rather than re-reading the summary: stale STOPPED after start now reaches RUNNING, a warehouse that never leaves STOPPED times out with the last observed state, and 150 tests pass. The warehouse code is byte-identical to the c6f018d I checked earlier.

I am deliberately not marking this approved, though, because your four points from Aug 6 are still open and three of them need code changes. I checked them and they all hold:

  • File naming (warehouse.py) — amazon uses athena.py / ec2.py, google uses bigquery.py; none repeat the provider name, so the existing databricks_*.py files are the deviation.
  • Unused hook methods — confirmed. WarehouseState.to_json / from_json have no production caller; only test_databricks.py:1619 round-trips them against themselves. (is_deleted is now used by _wait_for_state, so that one is fine.)
  • Docs — agreed, drop the system-test framing at sql_warehouse.rst:49 and just describe what the trigger rule does.

Separately: the branch is 186 commits behind main. Diffed against main it looks like this PR reverts #70130 and #69442 — that is a stale-base artifact, not a real revert (against the merge base it is only the 9 files of this PR). Worth rebasing so CI runs on current main and that diff stops misleading reviewers.


Drafted-by: Claude Code (Opus 5)

Vamsi-kluand others added 2 commits August 8, 2026 04:50
…rehouse-lifecycle
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Rename the operator module to warehouse.py to follow provider naming
conventions, drop the unused WarehouseState.to_json/from_json helpers
that have no production caller until the deferrable trigger lands, and
describe the all_done trigger rule behavior in the docs without
referring to system tests.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal pushed 727bfc3, which covers all four of your points: the module is renamed to warehouse.py, the unused WarehouseState serializers are gone, and the docs no longer mention system tests.

On defer support, my plan was to add it as a follow-up rather than fold it in here. Phase 2 adds a_get_warehouse_state to the hook plus a DatabricksWarehouseStateTrigger next to the two triggers the provider already has, keeping wait_for_termination, polling_period_seconds and timeout exactly as they are, so deferrable lands as an additive change rather than a parameter redesign. @moomindani reviewed that reasoning and had no objection to merging phase 1 as scoped. If you would rather see deferrable in this PR before it merges, say so and I will extend it here instead.

@moomindani I also merged latest main in the same push, so the diff no longer looks like it reverts #70130 and #69442.

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on 727bfc3. All four of @eladkal's points are addressed and my own earlier findings still hold — verified by running it, not by re-reading the summary.

@eladkal's points:

  • Renameoperators/warehouse.py and tests/.../test_warehouse.py, with the module path updated in both provider.yaml and get_provider_info.py. No stale references to the old name anywhere in the provider.
  • Unused serializersWarehouseState.to_json / from_json are gone. is_deleted is kept, which is right: it is the terminal-state check in _wait_for_state.
  • Docs — the system-test framing is gone from sql_warehouse.rst.

My findings, re-checked: stale STOPPED right after start still reaches RUNNING; a warehouse that never leaves STOPPED still surfaces as a timeout with the last observed state; DELETING mid-wait is still fatal. 149 tests pass locally, CI is 56/56 green, and prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff.

One correction to something I said on my previous pass, in case it caused any confusion: I reported that diffing against main made this PR look like it reverted #70130 and #69442. That was my local main being stale, not a problem with your branch. Against the correct merge base this PR is 9 files, +831/-1 — only its own work. Apologies for the noise.

The branch is now behind main again (56 commits) simply because main moved since your push; a rebase before merge is worth it for CI freshness, but the misleading-diff problem I raised earlier is resolved.

On deferrable: your Phase 2 plan is recorded and @eladkal has the question in front of him, so that is a scope call for the committers. No objection from me to merging Phase 1 as scoped.


Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from 2f6b872 to 727bfc3CompareAugust 15, 2026 06:10
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal, quick status. cc @moomindani

All four points from your Aug 6 review are in 727bfc3, and those threads are resolved. moomindani approved on Aug 12 after checking the lifecycle against a real workspace.

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here. Happy to rebase onto latest main if you want a fresh CI run.

@eladkal

Copy link
Copy Markdown
Contributor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM will merge after last open item is fixed

Comment threadproviders/databricks/docs/operators/warehouse.rst
Match the operator module name so the how-to page follows the
same provider naming convention as warehouse.py.
Co-authored-by: nrvamsi13 <nrvamsi13@gmail.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

@eladkal

Copy link
Copy Markdown
Contributor

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

yes

@eladkal
eladkal merged commit 263fafc into apache:mainAug 17, 2026
158 of 159 checks passed
@Vamsi-klu

Vamsi-klu commented Aug 18, 2026

Copy link
Copy Markdown
ContributorAuthor

Follow-up for the agreed deferrable warehouse path: #71752

@Vamsi-klu
Vamsi-klu deleted the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
@Vamsi-klu
Vamsi-klu restored the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
cursorBot pushed a commit to Vamsi-klu/airflow that referenced this pull request Aug 24, 2026
Start and stop waits from apache#70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
eladkal pushed a commit that referenced this pull request Aug 26, 2026
* Add deferrable mode to Databricks SQL warehouse operators
Start and stop waits from #70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Honor Databricks warehouse deferrable timeout across triggerer restarts
A duration recomputed inside the trigger started a fresh wait after every triggerer restart or HA rebalance, so a warehouse that never reached its target could stay deferred well past the configured timeout.
* Fix Databricks warehouse trigger docs spellcheck
Sphinx treats the HA term as a misspelling and fails the provider docs job.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@Vamsi-klu@eladkal@moomindani@potiuk@cursoragent
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add Databricks SQL warehouse lifecycle operators - #70088

Merged
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle
Aug 17, 2026
Merged

Add Databricks SQL warehouse lifecycle operators#70088
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle

Conversation

@Vamsi-klu

@Vamsi-kluVamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This adds first-class operators for starting and stopping existing Databricks SQL warehouses, including optional polling until the requested lifecycle state is reached.

related: #21377

Problem

Airflow's Databricks provider can execute SQL against a warehouse, but it has no first-class way to manage an existing warehouse's start/stop lifecycle. Dag authors currently need custom REST calls around their SQL tasks.

What changed

  • Add DatabricksHook methods for retrieving, starting, and stopping a warehouse through the Databricks SQL Warehouses API.
  • Add a validated WarehouseState model for the six documented lifecycle states.
  • Add DatabricksStartWarehouseOperator and DatabricksStopWarehouseOperator with idempotent pre-checks, optional waiting, monotonic deadlines, and explicit terminal-state errors.
  • Register the operators in provider metadata and add a how-to guide plus a system-test example with unconditional stop cleanup.

Warehouse IDs are embedded in the documented REST paths; no request-body workaround or new dependency is introduced. The implementation follows the Databricks SQL Warehouses API.

Scope

This is the Phase 1 scope proposed on #21377: get/state/start/stop plus synchronous waiting. Create/delete, edit, warehouse-by-name resolution, async hooks, and deferrable operators remain outside this PR so the initial contribution stays reviewable and independently useful.

Behavior and compatibility

  • Starting an already RUNNING warehouse and stopping an already STOPPED warehouse are no-ops.
  • Existing STARTING/STOPPING transitions are reused instead of issuing duplicate requests.
  • A start accepted while the warehouse still reports STOPPING continues polling; Databricks API transition rejections propagate unchanged.
  • Waiting uses time.monotonic(), starts no new poll after the configured deadline, and still honors a target or deletion state returned by a poll that began before the deadline.
  • The new operator validates templated warehouse IDs at execution time and remains import-compatible across supported Airflow versions through common.compat.sdk.

Validation

  • breeze run pytest providers/databricks/tests/unit/databricks/operators/test_databricks_warehouse.py -xvs — 23 passed.
  • breeze testing providers-tests --test-type "Providers[databricks]" — 842 passed, 12 skipped.
  • breeze testing providers-tests --test-type "Providers[amazon,common.compat,common.sql,databricks,google,openlineage]" — 11,858 passed, 185 skipped.
  • breeze run mypy providers/databricks/src/airflow/providers/databricks/exceptions.py providers/databricks/src/airflow/providers/databricks/hooks/databricks.py providers/databricks/src/airflow/providers/databricks/operators/databricks_warehouse.py — success, no issues.
  • Explicit nine-file prek pre-commit checks — passed.
  • Explicit nine-file prek manual checks — passed, including the providers mypy hook.
  • breeze build-docs --docs-only --clean-build databricks — documentation build successful; the generated guide contains both lifecycle examples.
  • breeze run pytest providers/databricks/tests/system/databricks/example_databricks_sql_warehouse.py --collect-only -q — 1 system test collected.
  • breeze ci selective-check --commit-ref HEAD — selected provider unit/compatibility tests, provider mypy, docs, Python scans, and the system-test path; no UI tests selected.

Reviewer evidence

This PR has no UI surface, so before/after screenshots and browser validation are not applicable. The REST boundary is covered with autospecced request assertions, operator behavior is covered with a specced hook, and the system example is import-validated. No Databricks workspace credentials were used or required for these deterministic lifecycle tests.

The narrow Phase 1 scope was posted on the issue before implementation: #21377 (comment)


Was generative AI tooling used to co-author this PR?
  • Yes — Codex (GPT-5)

Generated-by: Codex (GPT-5) following the guidelines

@Vamsi-klu

Vamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
ContributorAuthor

Local validation evidence for the Databricks SQL warehouse lifecycle implementation:

  • Focused operator suite: 21 passed.
  • Full Databricks provider suite: 838 passed, 12 skipped.
  • Selective six-provider dependency matrix: 11,858 passed, 185 skipped.
  • Changed-source mypy: Success: no issues found in 3 source files.
  • Explicit pre-commit and manual prek checks: passed; the manual run included the providers mypy hook.
  • Databricks docs build: successful; generated output contains both start and stop examples.
  • System-test example: one test_run collected successfully.
  • Selective-check analysis selected the expected provider unit/compatibility, provider mypy, docs, Python scan, and system-test jobs; it selected no UI work.

The tests assert the exact Databricks Warehouses API paths, idempotent start/stop behavior, transition-in-progress behavior, terminal failure states, templated-ID validation, and strict monotonic timeout handling.

There are no UI changes in this PR, so screenshots would not add reviewer signal. No Databricks credentials were used: REST calls are mocked at the hook boundary, while the system-test Dag is import-validated. Live workspace execution can be added later if a reviewer specifically requests it.


Drafted-by: Codex (GPT-5)

@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal@moomindani Can i get some feedack/Stamp for the PR please? Thanks!

@Vamsi-klu
Vamsi-klu marked this pull request as ready for review July 19, 2026 07:01
@potiukpotiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 20, 2026

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — nice, self-contained contribution.

Conventions I checked and found consistent: _DatabricksWarehouseBaseOperator sharing start/stop mirrors GCP's _DataprocStartStopClusterBaseOperator; WarehouseState follows the existing RunState / SQLStatementState shape in the hook; and wait_for_termination / polling_period_seconds / databricks_retry_* match DatabricksSQLStatementsOperator — note these differ from AWS's wait_for_completion, but matching the provider is the right precedence. time.monotonic(), spec/autospec mocks, and the all_done cleanup task in the system example are all correct.

I validated the lifecycle behaviour against a real workspace (2X-Small serverless warehouse, auto_stop_mins=10) rather than only reading the code:

ProbeObserved
POST /start from STOPPED, then tight-poll GET3/3 trials flipped STOPPED -> STARTING within 0.45-0.46s
POST /stop from RUNNINGreached STOPPED in ~2s
Start requested while stoppingSTARTING at t=3s, RUNNING at t=8s, no API rejection

Two things I'd like maintainer input on, then some small cleanups.

1. STOPPED as a start-path failure state is racy. The first poll after start_warehouse() runs with no time.sleep() in between, so a single lagging GET fails the task even though the start succeeded. Sub-second in my probes, but structural — details and a reproduction inline.

2. Shipping these without a deferrable mode is the part I'd most like a second opinion on. I know the PR body scopes deferrable out of Phase 1, and I understand wanting to keep the first contribution reviewable. But start/stop are multi-minute waits that hold a worker slot for their whole duration, which is the canonical case for deferrable operators — and the comparable operators elsewhere all have one:

  • AWS RedshiftResumeClusterOperator / RedshiftPauseClusterOperatordeferrable + dedicated triggers
  • GCP DataprocStartClusterOperator / DataprocStopClusterOperatordeferrable
  • This provider's own DatabricksRunNowOperator, DatabricksSQLStatementsOperator, and sensors — all deferrable

So these two operators would be the only blocking-poll operators in the Databricks provider. My concern is less "please add it now" and more that deferring it has a compatibility cost: once released, wait_for_termination and timeout are public API, and retrofitting deferrable around them is awkward — DatabricksSQLStatementsOperator needs its "wait_timeout": "0s" trick precisely to make one set of parameters serve both paths. Doing it up front is cheaper than reconciling it later.

The groundwork is mostly there: the hook already has _a_do_api_call, and the existing a_get_cluster_state / a_get_sql_statement_state are only a handful of lines each, so a_get_warehouse_state plus a DatabricksWarehouseStateTrigger alongside the two existing triggers looks like a modest addition rather than a redesign.

I'm not blocking on this — it is a scope judgement that belongs to the committers, not to me, and "merge Phase 1 now, add deferrable in Phase 2" is a legitimate answer if the parameter surface is settled deliberately. I'd just rather it be an explicit decision than an omission noticed after release.

Also ran locally:

  • pytest test_databricks_warehouse.py test_databricks.py — 149 passed.
  • prek --stage pre-commit — the only two failures are Update providers build files and Validate provider.yaml files, both from Docker not running on my machine, not from your diff.

Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6a5489 to c6f018dCompareJuly 27, 2026 05:26
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@moomindani, thanks for the thorough review and for validating the lifecycle behavior against a real workspace.

I pushed c6f018d and addressed all four inline comments:

  • Start polling now treats a STOPPED response immediately after the start request as potentially stale and continues until RUNNING, deletion, or timeout. The regression test covers STOPPED pre-check → start request → stale STOPPED poll → RUNNING.
  • The shared polling path now uses WarehouseState.is_deleted as the source of truth for terminal deletion states.
  • Hook construction is inlined into the cached _hook property.
  • The unused ENV_ID assignment is removed from the system-test example.

I also corrected the PR description's timeout wording: no new poll starts after the deadline, while a target or deletion state returned by an already-started poll is still honored.

On deferrable execution: I agree it would be valuable, but I am deliberately keeping it in Phase 2 rather than broadening this Phase 1 PR. That scope was recorded on #21377 and in the PR description before implementation. Since the warehouse start/stop endpoints return immediately, a future deferrable path can remain additive while preserving wait_for_termination, polling_period_seconds, and timeout. That follow-up will need the async state hook, serialized trigger and timeout behavior, operator completion path, and compatibility tests. If a committer considers deferrable execution a pre-merge requirement, I can revisit the scope here.

Validation on the rebased branch:

  • Full Databricks provider suite: 842 passed, 12 skipped.
  • Focused operator and warehouse-hook suites: 35 passed.
  • System-test example: 1 test collected.
  • Provider mypy: Success: no issues found.
  • Branch-level pre-commit and manual prek checks: passed.

Drafted-by: Codex (GPT-5); reviewed by @Vamsi-klu before posting

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified c6f018d by running it rather than reading the summary — all four are correctly addressed.

The race fix is the right shape: dropping the failure_states parameter and keying terminal detection off state.is_deleted fixes finding 1 and 2 in one move. I re-ran my original reproduction and the behaviour is now:

ScenarioBeforeNow
STOPPED (pre-check) → stale STOPPEDRUNNINGerrorreaches RUNNING
Warehouse never leaves STOPPEDerror (misleading)timeout, last state: STOPPED
DELETING mid-waiterrorerror (unchanged)

That is exactly the trade I hoped for — a genuine never-starts now surfaces as a timeout with the last observed state in the message, which is more diagnosable than the old immediate failure.

The test updates are what I'd have asked for: parametrizing test_starts_then_waits_until_running over ["STARTING", "STOPPED"] pins the regression, and re-pointing the start leg of test_execute_raises_on_failure_state from STOPPED to DELETING keeps the terminal-state assertion meaningful instead of just deleting it. 150 passed locally. prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff. Diff against current main is your 9 files only.

On deferrable: that's a reasonable answer, and recording it explicitly is all I was after. My concern was an unexamined omission, not the choice itself — you've now stated the Phase 2 plan and the parameter-compatibility reasoning, so a committer can weigh it deliberately. No objection from me to merging Phase 1 as scoped.

Nothing further from my side.


Drafted-by: Claude Code (Opus 5)

@eladkal

Copy link
Copy Markdown
Contributor

So @moomindani if I get it right you are approving the change?

A slow final status request can finish after the deadline even when it confirms the requested state. Treating that observation as a timeout can fail an otherwise successful Dag.
A warehouse can still report STOPPED immediately after the start request because the API response is eventually consistent. Keep polling until RUNNING or deletion/timeout so valid starts do not fail spuriously.
@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6f018d to a486797CompareJuly 31, 2026 06:51
@Vamsi-klu

Vamsi-klu commented Jul 31, 2026

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal All four findings are addressed and retested per your review. @moomindani the review is marked COMMENTED. Can i get maintainer approval please? Thanks!

@eladkal
eladkal self-requested a review August 6, 2026 05:48

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there is an open point around defer support. What is the plan here?

Comment threadproviders/databricks/src/airflow/providers/databricks/hooks/databricks.py Outdated
Comment threadproviders/databricks/docs/operators/sql_warehouse.rst Outdated

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladkal sorry for the slow reply to your question from Jul 27 — yes, as far as my own review goes I have no remaining objections. All four findings I raised were addressed, and I re-verified on a486797 rather than re-reading the summary: stale STOPPED after start now reaches RUNNING, a warehouse that never leaves STOPPED times out with the last observed state, and 150 tests pass. The warehouse code is byte-identical to the c6f018d I checked earlier.

I am deliberately not marking this approved, though, because your four points from Aug 6 are still open and three of them need code changes. I checked them and they all hold:

  • File naming (warehouse.py) — amazon uses athena.py / ec2.py, google uses bigquery.py; none repeat the provider name, so the existing databricks_*.py files are the deviation.
  • Unused hook methods — confirmed. WarehouseState.to_json / from_json have no production caller; only test_databricks.py:1619 round-trips them against themselves. (is_deleted is now used by _wait_for_state, so that one is fine.)
  • Docs — agreed, drop the system-test framing at sql_warehouse.rst:49 and just describe what the trigger rule does.

Separately: the branch is 186 commits behind main. Diffed against main it looks like this PR reverts #70130 and #69442 — that is a stale-base artifact, not a real revert (against the merge base it is only the 9 files of this PR). Worth rebasing so CI runs on current main and that diff stops misleading reviewers.


Drafted-by: Claude Code (Opus 5)

Vamsi-kluand others added 2 commits August 8, 2026 04:50
…rehouse-lifecycle
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Rename the operator module to warehouse.py to follow provider naming
conventions, drop the unused WarehouseState.to_json/from_json helpers
that have no production caller until the deferrable trigger lands, and
describe the all_done trigger rule behavior in the docs without
referring to system tests.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal pushed 727bfc3, which covers all four of your points: the module is renamed to warehouse.py, the unused WarehouseState serializers are gone, and the docs no longer mention system tests.

On defer support, my plan was to add it as a follow-up rather than fold it in here. Phase 2 adds a_get_warehouse_state to the hook plus a DatabricksWarehouseStateTrigger next to the two triggers the provider already has, keeping wait_for_termination, polling_period_seconds and timeout exactly as they are, so deferrable lands as an additive change rather than a parameter redesign. @moomindani reviewed that reasoning and had no objection to merging phase 1 as scoped. If you would rather see deferrable in this PR before it merges, say so and I will extend it here instead.

@moomindani I also merged latest main in the same push, so the diff no longer looks like it reverts #70130 and #69442.

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on 727bfc3. All four of @eladkal's points are addressed and my own earlier findings still hold — verified by running it, not by re-reading the summary.

@eladkal's points:

  • Renameoperators/warehouse.py and tests/.../test_warehouse.py, with the module path updated in both provider.yaml and get_provider_info.py. No stale references to the old name anywhere in the provider.
  • Unused serializersWarehouseState.to_json / from_json are gone. is_deleted is kept, which is right: it is the terminal-state check in _wait_for_state.
  • Docs — the system-test framing is gone from sql_warehouse.rst.

My findings, re-checked: stale STOPPED right after start still reaches RUNNING; a warehouse that never leaves STOPPED still surfaces as a timeout with the last observed state; DELETING mid-wait is still fatal. 149 tests pass locally, CI is 56/56 green, and prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff.

One correction to something I said on my previous pass, in case it caused any confusion: I reported that diffing against main made this PR look like it reverted #70130 and #69442. That was my local main being stale, not a problem with your branch. Against the correct merge base this PR is 9 files, +831/-1 — only its own work. Apologies for the noise.

The branch is now behind main again (56 commits) simply because main moved since your push; a rebase before merge is worth it for CI freshness, but the misleading-diff problem I raised earlier is resolved.

On deferrable: your Phase 2 plan is recorded and @eladkal has the question in front of him, so that is a scope call for the committers. No objection from me to merging Phase 1 as scoped.


Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from 2f6b872 to 727bfc3CompareAugust 15, 2026 06:10
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal, quick status. cc @moomindani

All four points from your Aug 6 review are in 727bfc3, and those threads are resolved. moomindani approved on Aug 12 after checking the lifecycle against a real workspace.

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here. Happy to rebase onto latest main if you want a fresh CI run.

@eladkal

Copy link
Copy Markdown
Contributor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM will merge after last open item is fixed

Comment threadproviders/databricks/docs/operators/warehouse.rst
Match the operator module name so the how-to page follows the
same provider naming convention as warehouse.py.
Co-authored-by: nrvamsi13 <nrvamsi13@gmail.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

@eladkal

Copy link
Copy Markdown
Contributor

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

yes

@eladkal
eladkal merged commit 263fafc into apache:mainAug 17, 2026
158 of 159 checks passed
@Vamsi-klu

Vamsi-klu commented Aug 18, 2026

Copy link
Copy Markdown
ContributorAuthor

Follow-up for the agreed deferrable warehouse path: #71752

@Vamsi-klu
Vamsi-klu deleted the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
@Vamsi-klu
Vamsi-klu restored the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
cursorBot pushed a commit to Vamsi-klu/airflow that referenced this pull request Aug 24, 2026
Start and stop waits from apache#70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
eladkal pushed a commit that referenced this pull request Aug 26, 2026
* Add deferrable mode to Databricks SQL warehouse operators
Start and stop waits from #70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Honor Databricks warehouse deferrable timeout across triggerer restarts
A duration recomputed inside the trigger started a fresh wait after every triggerer restart or HA rebalance, so a warehouse that never reached its target could stay deferred well past the configured timeout.
* Fix Databricks warehouse trigger docs spellcheck
Sphinx treats the HA term as a misspelling and fails the provider docs job.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@Vamsi-klu@eladkal@moomindani@potiuk@cursoragent
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Add Databricks SQL warehouse lifecycle operators - #70088

Merged
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle
Aug 17, 2026
Merged

Add Databricks SQL warehouse lifecycle operators#70088
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle

Conversation

@Vamsi-klu

@Vamsi-kluVamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This adds first-class operators for starting and stopping existing Databricks SQL warehouses, including optional polling until the requested lifecycle state is reached.

related: #21377

Problem

Airflow's Databricks provider can execute SQL against a warehouse, but it has no first-class way to manage an existing warehouse's start/stop lifecycle. Dag authors currently need custom REST calls around their SQL tasks.

What changed

  • Add DatabricksHook methods for retrieving, starting, and stopping a warehouse through the Databricks SQL Warehouses API.
  • Add a validated WarehouseState model for the six documented lifecycle states.
  • Add DatabricksStartWarehouseOperator and DatabricksStopWarehouseOperator with idempotent pre-checks, optional waiting, monotonic deadlines, and explicit terminal-state errors.
  • Register the operators in provider metadata and add a how-to guide plus a system-test example with unconditional stop cleanup.

Warehouse IDs are embedded in the documented REST paths; no request-body workaround or new dependency is introduced. The implementation follows the Databricks SQL Warehouses API.

Scope

This is the Phase 1 scope proposed on #21377: get/state/start/stop plus synchronous waiting. Create/delete, edit, warehouse-by-name resolution, async hooks, and deferrable operators remain outside this PR so the initial contribution stays reviewable and independently useful.

Behavior and compatibility

  • Starting an already RUNNING warehouse and stopping an already STOPPED warehouse are no-ops.
  • Existing STARTING/STOPPING transitions are reused instead of issuing duplicate requests.
  • A start accepted while the warehouse still reports STOPPING continues polling; Databricks API transition rejections propagate unchanged.
  • Waiting uses time.monotonic(), starts no new poll after the configured deadline, and still honors a target or deletion state returned by a poll that began before the deadline.
  • The new operator validates templated warehouse IDs at execution time and remains import-compatible across supported Airflow versions through common.compat.sdk.

Validation

  • breeze run pytest providers/databricks/tests/unit/databricks/operators/test_databricks_warehouse.py -xvs — 23 passed.
  • breeze testing providers-tests --test-type "Providers[databricks]" — 842 passed, 12 skipped.
  • breeze testing providers-tests --test-type "Providers[amazon,common.compat,common.sql,databricks,google,openlineage]" — 11,858 passed, 185 skipped.
  • breeze run mypy providers/databricks/src/airflow/providers/databricks/exceptions.py providers/databricks/src/airflow/providers/databricks/hooks/databricks.py providers/databricks/src/airflow/providers/databricks/operators/databricks_warehouse.py — success, no issues.
  • Explicit nine-file prek pre-commit checks — passed.
  • Explicit nine-file prek manual checks — passed, including the providers mypy hook.
  • breeze build-docs --docs-only --clean-build databricks — documentation build successful; the generated guide contains both lifecycle examples.
  • breeze run pytest providers/databricks/tests/system/databricks/example_databricks_sql_warehouse.py --collect-only -q — 1 system test collected.
  • breeze ci selective-check --commit-ref HEAD — selected provider unit/compatibility tests, provider mypy, docs, Python scans, and the system-test path; no UI tests selected.

Reviewer evidence

This PR has no UI surface, so before/after screenshots and browser validation are not applicable. The REST boundary is covered with autospecced request assertions, operator behavior is covered with a specced hook, and the system example is import-validated. No Databricks workspace credentials were used or required for these deterministic lifecycle tests.

The narrow Phase 1 scope was posted on the issue before implementation: #21377 (comment)


Was generative AI tooling used to co-author this PR?
  • Yes — Codex (GPT-5)

Generated-by: Codex (GPT-5) following the guidelines

@Vamsi-klu

Vamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
ContributorAuthor

Local validation evidence for the Databricks SQL warehouse lifecycle implementation:

  • Focused operator suite: 21 passed.
  • Full Databricks provider suite: 838 passed, 12 skipped.
  • Selective six-provider dependency matrix: 11,858 passed, 185 skipped.
  • Changed-source mypy: Success: no issues found in 3 source files.
  • Explicit pre-commit and manual prek checks: passed; the manual run included the providers mypy hook.
  • Databricks docs build: successful; generated output contains both start and stop examples.
  • System-test example: one test_run collected successfully.
  • Selective-check analysis selected the expected provider unit/compatibility, provider mypy, docs, Python scan, and system-test jobs; it selected no UI work.

The tests assert the exact Databricks Warehouses API paths, idempotent start/stop behavior, transition-in-progress behavior, terminal failure states, templated-ID validation, and strict monotonic timeout handling.

There are no UI changes in this PR, so screenshots would not add reviewer signal. No Databricks credentials were used: REST calls are mocked at the hook boundary, while the system-test Dag is import-validated. Live workspace execution can be added later if a reviewer specifically requests it.


Drafted-by: Codex (GPT-5)

@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal@moomindani Can i get some feedack/Stamp for the PR please? Thanks!

@Vamsi-klu
Vamsi-klu marked this pull request as ready for review July 19, 2026 07:01
@potiukpotiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 20, 2026

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — nice, self-contained contribution.

Conventions I checked and found consistent: _DatabricksWarehouseBaseOperator sharing start/stop mirrors GCP's _DataprocStartStopClusterBaseOperator; WarehouseState follows the existing RunState / SQLStatementState shape in the hook; and wait_for_termination / polling_period_seconds / databricks_retry_* match DatabricksSQLStatementsOperator — note these differ from AWS's wait_for_completion, but matching the provider is the right precedence. time.monotonic(), spec/autospec mocks, and the all_done cleanup task in the system example are all correct.

I validated the lifecycle behaviour against a real workspace (2X-Small serverless warehouse, auto_stop_mins=10) rather than only reading the code:

ProbeObserved
POST /start from STOPPED, then tight-poll GET3/3 trials flipped STOPPED -> STARTING within 0.45-0.46s
POST /stop from RUNNINGreached STOPPED in ~2s
Start requested while stoppingSTARTING at t=3s, RUNNING at t=8s, no API rejection

Two things I'd like maintainer input on, then some small cleanups.

1. STOPPED as a start-path failure state is racy. The first poll after start_warehouse() runs with no time.sleep() in between, so a single lagging GET fails the task even though the start succeeded. Sub-second in my probes, but structural — details and a reproduction inline.

2. Shipping these without a deferrable mode is the part I'd most like a second opinion on. I know the PR body scopes deferrable out of Phase 1, and I understand wanting to keep the first contribution reviewable. But start/stop are multi-minute waits that hold a worker slot for their whole duration, which is the canonical case for deferrable operators — and the comparable operators elsewhere all have one:

  • AWS RedshiftResumeClusterOperator / RedshiftPauseClusterOperatordeferrable + dedicated triggers
  • GCP DataprocStartClusterOperator / DataprocStopClusterOperatordeferrable
  • This provider's own DatabricksRunNowOperator, DatabricksSQLStatementsOperator, and sensors — all deferrable

So these two operators would be the only blocking-poll operators in the Databricks provider. My concern is less "please add it now" and more that deferring it has a compatibility cost: once released, wait_for_termination and timeout are public API, and retrofitting deferrable around them is awkward — DatabricksSQLStatementsOperator needs its "wait_timeout": "0s" trick precisely to make one set of parameters serve both paths. Doing it up front is cheaper than reconciling it later.

The groundwork is mostly there: the hook already has _a_do_api_call, and the existing a_get_cluster_state / a_get_sql_statement_state are only a handful of lines each, so a_get_warehouse_state plus a DatabricksWarehouseStateTrigger alongside the two existing triggers looks like a modest addition rather than a redesign.

I'm not blocking on this — it is a scope judgement that belongs to the committers, not to me, and "merge Phase 1 now, add deferrable in Phase 2" is a legitimate answer if the parameter surface is settled deliberately. I'd just rather it be an explicit decision than an omission noticed after release.

Also ran locally:

  • pytest test_databricks_warehouse.py test_databricks.py — 149 passed.
  • prek --stage pre-commit — the only two failures are Update providers build files and Validate provider.yaml files, both from Docker not running on my machine, not from your diff.

Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6a5489 to c6f018dCompareJuly 27, 2026 05:26
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@moomindani, thanks for the thorough review and for validating the lifecycle behavior against a real workspace.

I pushed c6f018d and addressed all four inline comments:

  • Start polling now treats a STOPPED response immediately after the start request as potentially stale and continues until RUNNING, deletion, or timeout. The regression test covers STOPPED pre-check → start request → stale STOPPED poll → RUNNING.
  • The shared polling path now uses WarehouseState.is_deleted as the source of truth for terminal deletion states.
  • Hook construction is inlined into the cached _hook property.
  • The unused ENV_ID assignment is removed from the system-test example.

I also corrected the PR description's timeout wording: no new poll starts after the deadline, while a target or deletion state returned by an already-started poll is still honored.

On deferrable execution: I agree it would be valuable, but I am deliberately keeping it in Phase 2 rather than broadening this Phase 1 PR. That scope was recorded on #21377 and in the PR description before implementation. Since the warehouse start/stop endpoints return immediately, a future deferrable path can remain additive while preserving wait_for_termination, polling_period_seconds, and timeout. That follow-up will need the async state hook, serialized trigger and timeout behavior, operator completion path, and compatibility tests. If a committer considers deferrable execution a pre-merge requirement, I can revisit the scope here.

Validation on the rebased branch:

  • Full Databricks provider suite: 842 passed, 12 skipped.
  • Focused operator and warehouse-hook suites: 35 passed.
  • System-test example: 1 test collected.
  • Provider mypy: Success: no issues found.
  • Branch-level pre-commit and manual prek checks: passed.

Drafted-by: Codex (GPT-5); reviewed by @Vamsi-klu before posting

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified c6f018d by running it rather than reading the summary — all four are correctly addressed.

The race fix is the right shape: dropping the failure_states parameter and keying terminal detection off state.is_deleted fixes finding 1 and 2 in one move. I re-ran my original reproduction and the behaviour is now:

ScenarioBeforeNow
STOPPED (pre-check) → stale STOPPEDRUNNINGerrorreaches RUNNING
Warehouse never leaves STOPPEDerror (misleading)timeout, last state: STOPPED
DELETING mid-waiterrorerror (unchanged)

That is exactly the trade I hoped for — a genuine never-starts now surfaces as a timeout with the last observed state in the message, which is more diagnosable than the old immediate failure.

The test updates are what I'd have asked for: parametrizing test_starts_then_waits_until_running over ["STARTING", "STOPPED"] pins the regression, and re-pointing the start leg of test_execute_raises_on_failure_state from STOPPED to DELETING keeps the terminal-state assertion meaningful instead of just deleting it. 150 passed locally. prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff. Diff against current main is your 9 files only.

On deferrable: that's a reasonable answer, and recording it explicitly is all I was after. My concern was an unexamined omission, not the choice itself — you've now stated the Phase 2 plan and the parameter-compatibility reasoning, so a committer can weigh it deliberately. No objection from me to merging Phase 1 as scoped.

Nothing further from my side.


Drafted-by: Claude Code (Opus 5)

@eladkal

Copy link
Copy Markdown
Contributor

So @moomindani if I get it right you are approving the change?

A slow final status request can finish after the deadline even when it confirms the requested state. Treating that observation as a timeout can fail an otherwise successful Dag.
A warehouse can still report STOPPED immediately after the start request because the API response is eventually consistent. Keep polling until RUNNING or deletion/timeout so valid starts do not fail spuriously.
@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6f018d to a486797CompareJuly 31, 2026 06:51
@Vamsi-klu

Vamsi-klu commented Jul 31, 2026

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal All four findings are addressed and retested per your review. @moomindani the review is marked COMMENTED. Can i get maintainer approval please? Thanks!

@eladkal
eladkal self-requested a review August 6, 2026 05:48

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there is an open point around defer support. What is the plan here?

Comment threadproviders/databricks/src/airflow/providers/databricks/hooks/databricks.py Outdated
Comment threadproviders/databricks/docs/operators/sql_warehouse.rst Outdated

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladkal sorry for the slow reply to your question from Jul 27 — yes, as far as my own review goes I have no remaining objections. All four findings I raised were addressed, and I re-verified on a486797 rather than re-reading the summary: stale STOPPED after start now reaches RUNNING, a warehouse that never leaves STOPPED times out with the last observed state, and 150 tests pass. The warehouse code is byte-identical to the c6f018d I checked earlier.

I am deliberately not marking this approved, though, because your four points from Aug 6 are still open and three of them need code changes. I checked them and they all hold:

  • File naming (warehouse.py) — amazon uses athena.py / ec2.py, google uses bigquery.py; none repeat the provider name, so the existing databricks_*.py files are the deviation.
  • Unused hook methods — confirmed. WarehouseState.to_json / from_json have no production caller; only test_databricks.py:1619 round-trips them against themselves. (is_deleted is now used by _wait_for_state, so that one is fine.)
  • Docs — agreed, drop the system-test framing at sql_warehouse.rst:49 and just describe what the trigger rule does.

Separately: the branch is 186 commits behind main. Diffed against main it looks like this PR reverts #70130 and #69442 — that is a stale-base artifact, not a real revert (against the merge base it is only the 9 files of this PR). Worth rebasing so CI runs on current main and that diff stops misleading reviewers.


Drafted-by: Claude Code (Opus 5)

Vamsi-kluand others added 2 commits August 8, 2026 04:50
…rehouse-lifecycle
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Rename the operator module to warehouse.py to follow provider naming
conventions, drop the unused WarehouseState.to_json/from_json helpers
that have no production caller until the deferrable trigger lands, and
describe the all_done trigger rule behavior in the docs without
referring to system tests.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal pushed 727bfc3, which covers all four of your points: the module is renamed to warehouse.py, the unused WarehouseState serializers are gone, and the docs no longer mention system tests.

On defer support, my plan was to add it as a follow-up rather than fold it in here. Phase 2 adds a_get_warehouse_state to the hook plus a DatabricksWarehouseStateTrigger next to the two triggers the provider already has, keeping wait_for_termination, polling_period_seconds and timeout exactly as they are, so deferrable lands as an additive change rather than a parameter redesign. @moomindani reviewed that reasoning and had no objection to merging phase 1 as scoped. If you would rather see deferrable in this PR before it merges, say so and I will extend it here instead.

@moomindani I also merged latest main in the same push, so the diff no longer looks like it reverts #70130 and #69442.

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on 727bfc3. All four of @eladkal's points are addressed and my own earlier findings still hold — verified by running it, not by re-reading the summary.

@eladkal's points:

  • Renameoperators/warehouse.py and tests/.../test_warehouse.py, with the module path updated in both provider.yaml and get_provider_info.py. No stale references to the old name anywhere in the provider.
  • Unused serializersWarehouseState.to_json / from_json are gone. is_deleted is kept, which is right: it is the terminal-state check in _wait_for_state.
  • Docs — the system-test framing is gone from sql_warehouse.rst.

My findings, re-checked: stale STOPPED right after start still reaches RUNNING; a warehouse that never leaves STOPPED still surfaces as a timeout with the last observed state; DELETING mid-wait is still fatal. 149 tests pass locally, CI is 56/56 green, and prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff.

One correction to something I said on my previous pass, in case it caused any confusion: I reported that diffing against main made this PR look like it reverted #70130 and #69442. That was my local main being stale, not a problem with your branch. Against the correct merge base this PR is 9 files, +831/-1 — only its own work. Apologies for the noise.

The branch is now behind main again (56 commits) simply because main moved since your push; a rebase before merge is worth it for CI freshness, but the misleading-diff problem I raised earlier is resolved.

On deferrable: your Phase 2 plan is recorded and @eladkal has the question in front of him, so that is a scope call for the committers. No objection from me to merging Phase 1 as scoped.


Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from 2f6b872 to 727bfc3CompareAugust 15, 2026 06:10
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal, quick status. cc @moomindani

All four points from your Aug 6 review are in 727bfc3, and those threads are resolved. moomindani approved on Aug 12 after checking the lifecycle against a real workspace.

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here. Happy to rebase onto latest main if you want a fresh CI run.

@eladkal

Copy link
Copy Markdown
Contributor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM will merge after last open item is fixed

Comment threadproviders/databricks/docs/operators/warehouse.rst
Match the operator module name so the how-to page follows the
same provider naming convention as warehouse.py.
Co-authored-by: nrvamsi13 <nrvamsi13@gmail.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

@eladkal

Copy link
Copy Markdown
Contributor

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

yes

@eladkal
eladkal merged commit 263fafc into apache:mainAug 17, 2026
158 of 159 checks passed
@Vamsi-klu

Vamsi-klu commented Aug 18, 2026

Copy link
Copy Markdown
ContributorAuthor

Follow-up for the agreed deferrable warehouse path: #71752

@Vamsi-klu
Vamsi-klu deleted the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
@Vamsi-klu
Vamsi-klu restored the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
cursorBot pushed a commit to Vamsi-klu/airflow that referenced this pull request Aug 24, 2026
Start and stop waits from apache#70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
eladkal pushed a commit that referenced this pull request Aug 26, 2026
* Add deferrable mode to Databricks SQL warehouse operators
Start and stop waits from #70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Honor Databricks warehouse deferrable timeout across triggerer restarts
A duration recomputed inside the trigger started a fresh wait after every triggerer restart or HA rebalance, so a warehouse that never reached its target could stay deferred well past the configured timeout.
* Fix Databricks warehouse trigger docs spellcheck
Sphinx treats the HA term as a misspelling and fails the provider docs job.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@Vamsi-klu@eladkal@moomindani@potiuk@cursoragent
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Add Databricks SQL warehouse lifecycle operators - #70088

Merged
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle
Aug 17, 2026
Merged

Add Databricks SQL warehouse lifecycle operators#70088
eladkal merged 7 commits into
apache:mainfrom
Vamsi-klu:agent/databricks-warehouse-lifecycle

Conversation

@Vamsi-klu

@Vamsi-kluVamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This adds first-class operators for starting and stopping existing Databricks SQL warehouses, including optional polling until the requested lifecycle state is reached.

related: #21377

Problem

Airflow's Databricks provider can execute SQL against a warehouse, but it has no first-class way to manage an existing warehouse's start/stop lifecycle. Dag authors currently need custom REST calls around their SQL tasks.

What changed

  • Add DatabricksHook methods for retrieving, starting, and stopping a warehouse through the Databricks SQL Warehouses API.
  • Add a validated WarehouseState model for the six documented lifecycle states.
  • Add DatabricksStartWarehouseOperator and DatabricksStopWarehouseOperator with idempotent pre-checks, optional waiting, monotonic deadlines, and explicit terminal-state errors.
  • Register the operators in provider metadata and add a how-to guide plus a system-test example with unconditional stop cleanup.

Warehouse IDs are embedded in the documented REST paths; no request-body workaround or new dependency is introduced. The implementation follows the Databricks SQL Warehouses API.

Scope

This is the Phase 1 scope proposed on #21377: get/state/start/stop plus synchronous waiting. Create/delete, edit, warehouse-by-name resolution, async hooks, and deferrable operators remain outside this PR so the initial contribution stays reviewable and independently useful.

Behavior and compatibility

  • Starting an already RUNNING warehouse and stopping an already STOPPED warehouse are no-ops.
  • Existing STARTING/STOPPING transitions are reused instead of issuing duplicate requests.
  • A start accepted while the warehouse still reports STOPPING continues polling; Databricks API transition rejections propagate unchanged.
  • Waiting uses time.monotonic(), starts no new poll after the configured deadline, and still honors a target or deletion state returned by a poll that began before the deadline.
  • The new operator validates templated warehouse IDs at execution time and remains import-compatible across supported Airflow versions through common.compat.sdk.

Validation

  • breeze run pytest providers/databricks/tests/unit/databricks/operators/test_databricks_warehouse.py -xvs — 23 passed.
  • breeze testing providers-tests --test-type "Providers[databricks]" — 842 passed, 12 skipped.
  • breeze testing providers-tests --test-type "Providers[amazon,common.compat,common.sql,databricks,google,openlineage]" — 11,858 passed, 185 skipped.
  • breeze run mypy providers/databricks/src/airflow/providers/databricks/exceptions.py providers/databricks/src/airflow/providers/databricks/hooks/databricks.py providers/databricks/src/airflow/providers/databricks/operators/databricks_warehouse.py — success, no issues.
  • Explicit nine-file prek pre-commit checks — passed.
  • Explicit nine-file prek manual checks — passed, including the providers mypy hook.
  • breeze build-docs --docs-only --clean-build databricks — documentation build successful; the generated guide contains both lifecycle examples.
  • breeze run pytest providers/databricks/tests/system/databricks/example_databricks_sql_warehouse.py --collect-only -q — 1 system test collected.
  • breeze ci selective-check --commit-ref HEAD — selected provider unit/compatibility tests, provider mypy, docs, Python scans, and the system-test path; no UI tests selected.

Reviewer evidence

This PR has no UI surface, so before/after screenshots and browser validation are not applicable. The REST boundary is covered with autospecced request assertions, operator behavior is covered with a specced hook, and the system example is import-validated. No Databricks workspace credentials were used or required for these deterministic lifecycle tests.

The narrow Phase 1 scope was posted on the issue before implementation: #21377 (comment)


Was generative AI tooling used to co-author this PR?
  • Yes — Codex (GPT-5)

Generated-by: Codex (GPT-5) following the guidelines

@Vamsi-klu

Vamsi-klu commented Jul 19, 2026

Copy link
Copy Markdown
ContributorAuthor

Local validation evidence for the Databricks SQL warehouse lifecycle implementation:

  • Focused operator suite: 21 passed.
  • Full Databricks provider suite: 838 passed, 12 skipped.
  • Selective six-provider dependency matrix: 11,858 passed, 185 skipped.
  • Changed-source mypy: Success: no issues found in 3 source files.
  • Explicit pre-commit and manual prek checks: passed; the manual run included the providers mypy hook.
  • Databricks docs build: successful; generated output contains both start and stop examples.
  • System-test example: one test_run collected successfully.
  • Selective-check analysis selected the expected provider unit/compatibility, provider mypy, docs, Python scan, and system-test jobs; it selected no UI work.

The tests assert the exact Databricks Warehouses API paths, idempotent start/stop behavior, transition-in-progress behavior, terminal failure states, templated-ID validation, and strict monotonic timeout handling.

There are no UI changes in this PR, so screenshots would not add reviewer signal. No Databricks credentials were used: REST calls are mocked at the hook boundary, while the system-test Dag is import-validated. Live workspace execution can be added later if a reviewer specifically requests it.


Drafted-by: Codex (GPT-5)

@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal@moomindani Can i get some feedack/Stamp for the PR please? Thanks!

@Vamsi-klu
Vamsi-klu marked this pull request as ready for review July 19, 2026 07:01
@potiukpotiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 20, 2026

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this — nice, self-contained contribution.

Conventions I checked and found consistent: _DatabricksWarehouseBaseOperator sharing start/stop mirrors GCP's _DataprocStartStopClusterBaseOperator; WarehouseState follows the existing RunState / SQLStatementState shape in the hook; and wait_for_termination / polling_period_seconds / databricks_retry_* match DatabricksSQLStatementsOperator — note these differ from AWS's wait_for_completion, but matching the provider is the right precedence. time.monotonic(), spec/autospec mocks, and the all_done cleanup task in the system example are all correct.

I validated the lifecycle behaviour against a real workspace (2X-Small serverless warehouse, auto_stop_mins=10) rather than only reading the code:

ProbeObserved
POST /start from STOPPED, then tight-poll GET3/3 trials flipped STOPPED -> STARTING within 0.45-0.46s
POST /stop from RUNNINGreached STOPPED in ~2s
Start requested while stoppingSTARTING at t=3s, RUNNING at t=8s, no API rejection

Two things I'd like maintainer input on, then some small cleanups.

1. STOPPED as a start-path failure state is racy. The first poll after start_warehouse() runs with no time.sleep() in between, so a single lagging GET fails the task even though the start succeeded. Sub-second in my probes, but structural — details and a reproduction inline.

2. Shipping these without a deferrable mode is the part I'd most like a second opinion on. I know the PR body scopes deferrable out of Phase 1, and I understand wanting to keep the first contribution reviewable. But start/stop are multi-minute waits that hold a worker slot for their whole duration, which is the canonical case for deferrable operators — and the comparable operators elsewhere all have one:

  • AWS RedshiftResumeClusterOperator / RedshiftPauseClusterOperatordeferrable + dedicated triggers
  • GCP DataprocStartClusterOperator / DataprocStopClusterOperatordeferrable
  • This provider's own DatabricksRunNowOperator, DatabricksSQLStatementsOperator, and sensors — all deferrable

So these two operators would be the only blocking-poll operators in the Databricks provider. My concern is less "please add it now" and more that deferring it has a compatibility cost: once released, wait_for_termination and timeout are public API, and retrofitting deferrable around them is awkward — DatabricksSQLStatementsOperator needs its "wait_timeout": "0s" trick precisely to make one set of parameters serve both paths. Doing it up front is cheaper than reconciling it later.

The groundwork is mostly there: the hook already has _a_do_api_call, and the existing a_get_cluster_state / a_get_sql_statement_state are only a handful of lines each, so a_get_warehouse_state plus a DatabricksWarehouseStateTrigger alongside the two existing triggers looks like a modest addition rather than a redesign.

I'm not blocking on this — it is a scope judgement that belongs to the committers, not to me, and "merge Phase 1 now, add deferrable in Phase 2" is a legitimate answer if the parameter surface is settled deliberately. I'd just rather it be an explicit decision than an omission noticed after release.

Also ran locally:

  • pytest test_databricks_warehouse.py test_databricks.py — 149 passed.
  • prek --stage pre-commit — the only two failures are Update providers build files and Validate provider.yaml files, both from Docker not running on my machine, not from your diff.

Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6a5489 to c6f018dCompareJuly 27, 2026 05:26
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@moomindani, thanks for the thorough review and for validating the lifecycle behavior against a real workspace.

I pushed c6f018d and addressed all four inline comments:

  • Start polling now treats a STOPPED response immediately after the start request as potentially stale and continues until RUNNING, deletion, or timeout. The regression test covers STOPPED pre-check → start request → stale STOPPED poll → RUNNING.
  • The shared polling path now uses WarehouseState.is_deleted as the source of truth for terminal deletion states.
  • Hook construction is inlined into the cached _hook property.
  • The unused ENV_ID assignment is removed from the system-test example.

I also corrected the PR description's timeout wording: no new poll starts after the deadline, while a target or deletion state returned by an already-started poll is still honored.

On deferrable execution: I agree it would be valuable, but I am deliberately keeping it in Phase 2 rather than broadening this Phase 1 PR. That scope was recorded on #21377 and in the PR description before implementation. Since the warehouse start/stop endpoints return immediately, a future deferrable path can remain additive while preserving wait_for_termination, polling_period_seconds, and timeout. That follow-up will need the async state hook, serialized trigger and timeout behavior, operator completion path, and compatibility tests. If a committer considers deferrable execution a pre-merge requirement, I can revisit the scope here.

Validation on the rebased branch:

  • Full Databricks provider suite: 842 passed, 12 skipped.
  • Focused operator and warehouse-hook suites: 35 passed.
  • System-test example: 1 test collected.
  • Provider mypy: Success: no issues found.
  • Branch-level pre-commit and manual prek checks: passed.

Drafted-by: Codex (GPT-5); reviewed by @Vamsi-klu before posting

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified c6f018d by running it rather than reading the summary — all four are correctly addressed.

The race fix is the right shape: dropping the failure_states parameter and keying terminal detection off state.is_deleted fixes finding 1 and 2 in one move. I re-ran my original reproduction and the behaviour is now:

ScenarioBeforeNow
STOPPED (pre-check) → stale STOPPEDRUNNINGerrorreaches RUNNING
Warehouse never leaves STOPPEDerror (misleading)timeout, last state: STOPPED
DELETING mid-waiterrorerror (unchanged)

That is exactly the trade I hoped for — a genuine never-starts now surfaces as a timeout with the last observed state in the message, which is more diagnosable than the old immediate failure.

The test updates are what I'd have asked for: parametrizing test_starts_then_waits_until_running over ["STARTING", "STOPPED"] pins the regression, and re-pointing the start leg of test_execute_raises_on_failure_state from STOPPED to DELETING keeps the terminal-state assertion meaningful instead of just deleting it. 150 passed locally. prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff. Diff against current main is your 9 files only.

On deferrable: that's a reasonable answer, and recording it explicitly is all I was after. My concern was an unexamined omission, not the choice itself — you've now stated the Phase 2 plan and the parameter-compatibility reasoning, so a committer can weigh it deliberately. No objection from me to merging Phase 1 as scoped.

Nothing further from my side.


Drafted-by: Claude Code (Opus 5)

@eladkal

Copy link
Copy Markdown
Contributor

So @moomindani if I get it right you are approving the change?

A slow final status request can finish after the deadline even when it confirms the requested state. Treating that observation as a timeout can fail an otherwise successful Dag.
A warehouse can still report STOPPED immediately after the start request because the API response is eventually consistent. Keep polling until RUNNING or deletion/timeout so valid starts do not fail spuriously.
@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from c6f018d to a486797CompareJuly 31, 2026 06:51
@Vamsi-klu

Vamsi-klu commented Jul 31, 2026

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal All four findings are addressed and retested per your review. @moomindani the review is marked COMMENTED. Can i get maintainer approval please? Thanks!

@eladkal
eladkal self-requested a review August 6, 2026 05:48

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there is an open point around defer support. What is the plan here?

Comment threadproviders/databricks/src/airflow/providers/databricks/hooks/databricks.py Outdated
Comment threadproviders/databricks/docs/operators/sql_warehouse.rst Outdated

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eladkal sorry for the slow reply to your question from Jul 27 — yes, as far as my own review goes I have no remaining objections. All four findings I raised were addressed, and I re-verified on a486797 rather than re-reading the summary: stale STOPPED after start now reaches RUNNING, a warehouse that never leaves STOPPED times out with the last observed state, and 150 tests pass. The warehouse code is byte-identical to the c6f018d I checked earlier.

I am deliberately not marking this approved, though, because your four points from Aug 6 are still open and three of them need code changes. I checked them and they all hold:

  • File naming (warehouse.py) — amazon uses athena.py / ec2.py, google uses bigquery.py; none repeat the provider name, so the existing databricks_*.py files are the deviation.
  • Unused hook methods — confirmed. WarehouseState.to_json / from_json have no production caller; only test_databricks.py:1619 round-trips them against themselves. (is_deleted is now used by _wait_for_state, so that one is fine.)
  • Docs — agreed, drop the system-test framing at sql_warehouse.rst:49 and just describe what the trigger rule does.

Separately: the branch is 186 commits behind main. Diffed against main it looks like this PR reverts #70130 and #69442 — that is a stale-base artifact, not a real revert (against the merge base it is only the 9 files of this PR). Worth rebasing so CI runs on current main and that diff stops misleading reviewers.


Drafted-by: Claude Code (Opus 5)

Vamsi-kluand others added 2 commits August 8, 2026 04:50
…rehouse-lifecycle
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Rename the operator module to warehouse.py to follow provider naming
conventions, drop the unused WarehouseState.to_json/from_json helpers
that have no production caller until the deferrable trigger lands, and
describe the all_done trigger rule behavior in the docs without
referring to system tests.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

@eladkal pushed 727bfc3, which covers all four of your points: the module is renamed to warehouse.py, the unused WarehouseState serializers are gone, and the docs no longer mention system tests.

On defer support, my plan was to add it as a follow-up rather than fold it in here. Phase 2 adds a_get_warehouse_state to the hook plus a DatabricksWarehouseStateTrigger next to the two triggers the provider already has, keeping wait_for_termination, polling_period_seconds and timeout exactly as they are, so deferrable lands as an additive change rather than a parameter redesign. @moomindani reviewed that reasoning and had no objection to merging phase 1 as scoped. If you would rather see deferrable in this PR before it merges, say so and I will extend it here instead.

@moomindani I also merged latest main in the same push, so the diff no longer looks like it reverts #70130 and #69442.

@moomindanimoomindani left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on 727bfc3. All four of @eladkal's points are addressed and my own earlier findings still hold — verified by running it, not by re-reading the summary.

@eladkal's points:

  • Renameoperators/warehouse.py and tests/.../test_warehouse.py, with the module path updated in both provider.yaml and get_provider_info.py. No stale references to the old name anywhere in the provider.
  • Unused serializersWarehouseState.to_json / from_json are gone. is_deleted is kept, which is right: it is the terminal-state check in _wait_for_state.
  • Docs — the system-test framing is gone from sql_warehouse.rst.

My findings, re-checked: stale STOPPED right after start still reaches RUNNING; a warehouse that never leaves STOPPED still surfaces as a timeout with the last observed state; DELETING mid-wait is still fatal. 149 tests pass locally, CI is 56/56 green, and prek --stage pre-commit is clean apart from the two Docker-dependent hooks that fail on my machine regardless of the diff.

One correction to something I said on my previous pass, in case it caused any confusion: I reported that diffing against main made this PR look like it reverted #70130 and #69442. That was my local main being stale, not a problem with your branch. Against the correct merge base this PR is 9 files, +831/-1 — only its own work. Apologies for the noise.

The branch is now behind main again (56 commits) simply because main moved since your push; a rebase before merge is worth it for CI freshness, but the misleading-diff problem I raised earlier is resolved.

On deferrable: your Phase 2 plan is recorded and @eladkal has the question in front of him, so that is a scope call for the committers. No objection from me to merging Phase 1 as scoped.


Drafted-by: Claude Code (Opus 5)

@Vamsi-klu
Vamsi-kluforce-pushed the agent/databricks-warehouse-lifecycle branch from 2f6b872 to 727bfc3CompareAugust 15, 2026 06:10
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Hi @eladkal, quick status. cc @moomindani

All four points from your Aug 6 review are in 727bfc3, and those threads are resolved. moomindani approved on Aug 12 after checking the lifecycle against a real workspace.

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here. Happy to rebase onto latest main if you want a fresh CI run.

@eladkal

Copy link
Copy Markdown
Contributor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkaleladkal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM will merge after last open item is fixed

Comment threadproviders/databricks/docs/operators/warehouse.rst
Match the operator module name so the how-to page follows the
same provider naming convention as warehouse.py.
Co-authored-by: nrvamsi13 <nrvamsi13@gmail.com>
@Vamsi-klu

Copy link
Copy Markdown
ContributorAuthor

Is there anything else you need from me to merge this? If you'd rather have defer support in this PR instead of a follow-up, say so and I'll push it here.

It can be a followup but please lets have it soon. I assume you are raising the followup PR?

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

@eladkal

Copy link
Copy Markdown
Contributor

@eladkal thanks for the feedback, I resolved your feedback. Yes, I'm working on the follow-up PR. Will raise by this weekend. Please let me know if that works for you?

yes

@eladkal
eladkal merged commit 263fafc into apache:mainAug 17, 2026
158 of 159 checks passed
@Vamsi-klu

Vamsi-klu commented Aug 18, 2026

Copy link
Copy Markdown
ContributorAuthor

Follow-up for the agreed deferrable warehouse path: #71752

@Vamsi-klu
Vamsi-klu deleted the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
@Vamsi-klu
Vamsi-klu restored the agent/databricks-warehouse-lifecycle branch August 18, 2026 01:06
cursorBot pushed a commit to Vamsi-klu/airflow that referenced this pull request Aug 24, 2026
Start and stop waits from apache#70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
eladkal pushed a commit that referenced this pull request Aug 26, 2026
* Add deferrable mode to Databricks SQL warehouse operators
Start and stop waits from #70088 held a worker for the whole warehouse
lifecycle. This follow-up lands the agreed additive triggerer path so
those waits no longer occupy a worker slot.
Co-authored-by: Cursor <cursoragent@cursor.com>
* Honor Databricks warehouse deferrable timeout across triggerer restarts
A duration recomputed inside the trigger started a fresh wait after every triggerer restart or HA rebalance, so a warehouse that never reached its target could stay deferred well past the configured timeout.
* Fix Databricks warehouse trigger docs spellcheck
Sphinx treats the HA term as a misspelling and fails the provider docs job.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@Vamsi-klu@eladkal@moomindani@potiuk@cursoragent