Skip to content

Commit 727bfc3

Browse files
Vamsi-kluclaude
andcommitted
Address review feedback on Databricks SQL warehouse operators
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>
1 parent 2717dbf commit 727bfc3

8 files changed

Lines changed: 19 additions & 35 deletions

File tree

providers/databricks/docs/operators/sql_warehouse.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
Databricks SQL warehouse lifecycle operators
2222
============================================
2323

24-
Use :class:`~airflow.providers.databricks.operators.databricks_warehouse.DatabricksStartWarehouseOperator`
25-
and :class:`~airflow.providers.databricks.operators.databricks_warehouse.DatabricksStopWarehouseOperator`
24+
Use :class:`~airflow.providers.databricks.operators.warehouse.DatabricksStartWarehouseOperator`
25+
and :class:`~airflow.providers.databricks.operators.warehouse.DatabricksStopWarehouseOperator`
2626
to start and stop an existing Databricks SQL warehouse through the
2727
`Databricks SQL Warehouses API <https://docs.databricks.com/api/workspace/warehouses>`_.
2828
Both operators require the warehouse ID and use the :ref:`Databricks connection
@@ -46,8 +46,8 @@ Start a SQL warehouse
4646
Stop a SQL warehouse
4747
--------------------
4848

49-
The system-test example marks the stop task with the ``all_done`` trigger rule so it runs as cleanup
50-
even when an upstream task fails.
49+
The stop task uses the ``all_done`` trigger rule so the warehouse is stopped even when an upstream
50+
task fails.
5151

5252
.. exampleinclude:: /../../databricks/tests/system/databricks/example_databricks_sql_warehouse.py
5353
:language: python

providers/databricks/provider.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ operators:
148148
- integration-name: Databricks SQL
149149
python-modules:
150150
- airflow.providers.databricks.operators.databricks_sql
151-
- airflow.providers.databricks.operators.databricks_warehouse
151+
- airflow.providers.databricks.operators.warehouse
152152
- integration-name: Databricks Repos
153153
python-modules:
154154
- airflow.providers.databricks.operators.databricks_repos

providers/databricks/src/airflow/providers/databricks/get_provider_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def get_provider_info():
7777
"integration-name": "Databricks SQL",
7878
"python-modules": [
7979
"airflow.providers.databricks.operators.databricks_sql",
80-
"airflow.providers.databricks.operators.databricks_warehouse",
80+
"airflow.providers.databricks.operators.warehouse",
8181
],
8282
},
8383
{

providers/databricks/src/airflow/providers/databricks/hooks/databricks.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,6 @@ def __hash__(self):
307307
def __repr__(self) -> str:
308308
return str(self.__dict__)
309309

310-
def to_json(self) -> str:
311-
return json.dumps(self.__dict__)
312-
313-
@classmethod
314-
def from_json(cls, data: str) -> WarehouseState:
315-
return WarehouseState(**json.loads(data))
316-
317310

318311
class DatabricksHook(BaseDatabricksHook):
319312
"""

providers/databricks/src/airflow/providers/databricks/operators/databricks_warehouse.py renamed to providers/databricks/src/airflow/providers/databricks/operators/warehouse.py

File renamed without changes.

providers/databricks/tests/system/databricks/example_databricks_sql_warehouse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from datetime import datetime
2323

2424
from airflow.providers.common.compat.sdk import DAG
25-
from airflow.providers.databricks.operators.databricks_warehouse import (
25+
from airflow.providers.databricks.operators.warehouse import (
2626
DatabricksStartWarehouseOperator,
2727
DatabricksStopWarehouseOperator,
2828
)

providers/databricks/tests/unit/databricks/hooks/test_databricks.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,15 +1614,6 @@ def test_warehouse_state_unexpected_raises_value_error(self):
16141614
with pytest.raises(ValueError, match="Unexpected warehouse state: FOO"):
16151615
WarehouseState("FOO")
16161616

1617-
def test_warehouse_state_json_roundtrip(self):
1618-
state = WarehouseState("STARTING")
1619-
restored = WarehouseState.from_json(state.to_json())
1620-
1621-
assert restored == state
1622-
assert restored != object()
1623-
assert hash(restored) == hash(state)
1624-
assert repr(restored) == "{'state': 'STARTING'}"
1625-
16261617

16271618
class TestRunState:
16281619
def test_is_terminal_true(self):

providers/databricks/tests/unit/databricks/operators/test_databricks_warehouse.py renamed to providers/databricks/tests/unit/databricks/operators/test_warehouse.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from airflow.providers.databricks.exceptions import DatabricksWarehouseError
2424
from airflow.providers.databricks.hooks.databricks import DatabricksHook, WarehouseState
25-
from airflow.providers.databricks.operators.databricks_warehouse import (
25+
from airflow.providers.databricks.operators.warehouse import (
2626
DatabricksStartWarehouseOperator,
2727
DatabricksStopWarehouseOperator,
2828
)
@@ -37,7 +37,7 @@ class TestDatabricksStartWarehouseOperator:
3737
["STARTING", "STOPPED"],
3838
ids=["transitioning", "stale-stopped"],
3939
)
40-
@mock.patch("airflow.providers.databricks.operators.databricks_warehouse.time.sleep")
40+
@mock.patch("airflow.providers.databricks.operators.warehouse.time.sleep")
4141
@mock.patch.object(DatabricksStartWarehouseOperator, "_hook", new_callable=mock.PropertyMock)
4242
def test_starts_then_waits_until_running(self, mock_hook_property, mock_sleep, first_polled_state):
4343
hook = mock.MagicMock(spec=DatabricksHook)
@@ -87,7 +87,7 @@ def test_skips_start_when_starting_without_waiting(self, mock_hook_property):
8787
hook.start_warehouse.assert_not_called()
8888
hook.get_warehouse_state.assert_called_once_with(WAREHOUSE_ID)
8989

90-
@mock.patch("airflow.providers.databricks.operators.databricks_warehouse.time.sleep")
90+
@mock.patch("airflow.providers.databricks.operators.warehouse.time.sleep")
9191
@mock.patch.object(DatabricksStartWarehouseOperator, "_hook", new_callable=mock.PropertyMock)
9292
def test_starts_while_stopping_and_waits_until_running(self, mock_hook_property, mock_sleep):
9393
hook = mock.MagicMock(spec=DatabricksHook)
@@ -111,7 +111,7 @@ def test_starts_while_stopping_and_waits_until_running(self, mock_hook_property,
111111

112112

113113
class TestDatabricksStopWarehouseOperator:
114-
@mock.patch("airflow.providers.databricks.operators.databricks_warehouse.time.sleep")
114+
@mock.patch("airflow.providers.databricks.operators.warehouse.time.sleep")
115115
@mock.patch.object(DatabricksStopWarehouseOperator, "_hook", new_callable=mock.PropertyMock)
116116
def test_stops_then_waits_until_stopped(self, mock_hook_property, mock_sleep):
117117
hook = mock.MagicMock(spec=DatabricksHook)
@@ -206,7 +206,7 @@ def test_execute_raises_on_failure_state(
206206
(DatabricksStopWarehouseOperator, "STOPPING", "STOPPED", "stop_warehouse"),
207207
],
208208
)
209-
@mock.patch("airflow.providers.databricks.operators.databricks_warehouse.time.sleep")
209+
@mock.patch("airflow.providers.databricks.operators.warehouse.time.sleep")
210210
@mock.patch.object(DatabricksStartWarehouseOperator, "_hook", new_callable=mock.PropertyMock)
211211
@mock.patch.object(DatabricksStopWarehouseOperator, "_hook", new_callable=mock.PropertyMock)
212212
def test_transition_in_progress_skips_request_and_continues_waiting(
@@ -271,9 +271,9 @@ def test_transition_without_waiting(
271271
getattr(hook, transition_method).assert_called_once_with(WAREHOUSE_ID)
272272
hook.get_warehouse_state.assert_called_once_with(WAREHOUSE_ID)
273273

274-
@mock.patch("airflow.providers.databricks.operators.databricks_warehouse.time.sleep")
274+
@mock.patch("airflow.providers.databricks.operators.warehouse.time.sleep")
275275
@mock.patch(
276-
"airflow.providers.databricks.operators.databricks_warehouse.time.monotonic",
276+
"airflow.providers.databricks.operators.warehouse.time.monotonic",
277277
return_value=0,
278278
)
279279
@mock.patch.object(DatabricksStartWarehouseOperator, "_hook", new_callable=mock.PropertyMock)
@@ -304,9 +304,9 @@ def advance_to_deadline(seconds):
304304
hook.get_warehouse_state.assert_called_once_with(WAREHOUSE_ID)
305305
mock_sleep.assert_called_once_with(10)
306306

307-
@mock.patch("airflow.providers.databricks.operators.databricks_warehouse.time.sleep")
307+
@mock.patch("airflow.providers.databricks.operators.warehouse.time.sleep")
308308
@mock.patch(
309-
"airflow.providers.databricks.operators.databricks_warehouse.time.monotonic",
309+
"airflow.providers.databricks.operators.warehouse.time.monotonic",
310310
return_value=0,
311311
)
312312
@mock.patch.object(DatabricksStartWarehouseOperator, "_hook", new_callable=mock.PropertyMock)
@@ -332,9 +332,9 @@ def get_state_after_deadline(_):
332332
hook.get_warehouse_state.assert_called_once_with(WAREHOUSE_ID)
333333
mock_sleep.assert_not_called()
334334

335-
@mock.patch("airflow.providers.databricks.operators.databricks_warehouse.time.sleep")
335+
@mock.patch("airflow.providers.databricks.operators.warehouse.time.sleep")
336336
@mock.patch(
337-
"airflow.providers.databricks.operators.databricks_warehouse.time.monotonic",
337+
"airflow.providers.databricks.operators.warehouse.time.monotonic",
338338
return_value=0,
339339
)
340340
@mock.patch.object(DatabricksStartWarehouseOperator, "_hook", new_callable=mock.PropertyMock)
@@ -384,7 +384,7 @@ def test_invalid_warehouse_id(self, operator_class, warehouse_id):
384384
with pytest.raises(ValueError, match="warehouse_id must be provided"):
385385
operator.execute(None)
386386

387-
@mock.patch("airflow.providers.databricks.operators.databricks_warehouse.DatabricksHook", autospec=True)
387+
@mock.patch("airflow.providers.databricks.operators.warehouse.DatabricksHook", autospec=True)
388388
def test_operator_builds_hook(self, mock_hook_class):
389389
retry_args = {"reraise": True}
390390
operator = DatabricksStartWarehouseOperator(

0 commit comments

Comments
 (0)