Skip to content

Commit 348cb43

Browse files
authored
Changes to work with Databricks SDK v0.38.0 (#350)
Changes to work with Databricks SDK [`v0.38.0`](https://github.com/databricks/databricks-sdk-py/releases/tag/v0.38.0) Resolves #349 Resolves #348 Resolves #347 Resolves #346 Resolves #345 Resolves #344 Resolves #343 Resolves #342 Resolves #341 Resolves #340 Resolves #339 Resolves #338 Resolves #337 Resolves #336 Resolves #335 Resolves #334 Resolves #333 Resolves #332
1 parent 55699cb commit 348cb43

File tree

5 files changed

+44
-48
lines changed

5 files changed

+44
-48
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ classifiers = [
2121
]
2222
dependencies = [
2323
"databricks-labs-blueprint[yaml]>=0.4.2",
24-
"databricks-sdk~=0.37",
24+
"databricks-sdk~=0.38",
2525
"sqlglot>=22.3.1"
2626
]
2727

src/databricks/labs/lsql/dashboards.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,9 +1133,9 @@ def create_dashboard(
11331133
warehouse_id=warehouse_id,
11341134
)
11351135
if dashboard_id is not None:
1136-
sdk_dashboard = self._ws.lakeview.update(dashboard_id, dashboard=dashboard_to_create.as_dict()) # type: ignore
1136+
sdk_dashboard = self._ws.lakeview.update(dashboard_id, dashboard=dashboard_to_create)
11371137
else:
1138-
sdk_dashboard = self._ws.lakeview.create(dashboard=dashboard_to_create.as_dict()) # type: ignore
1138+
sdk_dashboard = self._ws.lakeview.create(dashboard=dashboard_to_create)
11391139
if publish:
11401140
assert sdk_dashboard.dashboard_id is not None
11411141
self._ws.lakeview.publish(sdk_dashboard.dashboard_id, warehouse_id=warehouse_id)

tests/integration/test_core.py

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,44 @@ def test_sql_execution_chunked(ws, disposition):
1717
assert total == 1999999000000
1818

1919

20-
def test_sql_execution(ws, env_or_skip):
21-
results = []
20+
NYC_TAXI_TRIPS_LIMITED = """
21+
WITH zipcodes AS (
22+
SELECT DISTINCT pickup_zip, dropoff_zip
23+
FROM samples.nyctaxi.trips
24+
WHERE pickup_zip = 10282 AND dropoff_zip <= 10005
25+
)
26+
27+
SELECT
28+
trips.pickup_zip,
29+
trips.dropoff_zip,
30+
trips.tpep_pickup_datetime,
31+
trips.tpep_dropoff_datetime
32+
FROM
33+
zipcodes
34+
JOIN
35+
samples.nyctaxi.trips AS trips
36+
ON zipcodes.pickup_zip = trips.pickup_zip AND zipcodes.dropoff_zip = trips.dropoff_zip
37+
ORDER BY trips.dropoff_zip, trips.tpep_pickup_datetime, trips.tpep_dropoff_datetime
38+
"""
39+
40+
41+
def test_sql_execution(ws, env_or_skip) -> None:
2242
see = StatementExecutionExt(ws, warehouse_id=env_or_skip("TEST_DEFAULT_WAREHOUSE_ID"))
23-
for pickup_zip, dropoff_zip in see.fetch_all(
24-
"SELECT pickup_zip, dropoff_zip FROM nyctaxi.trips LIMIT 10", catalog="samples"
25-
):
26-
results.append((pickup_zip, dropoff_zip))
27-
assert results == [
28-
(10282, 10171),
29-
(10110, 10110),
30-
(10103, 10023),
31-
(10022, 10017),
32-
(10110, 10282),
33-
(10009, 10065),
34-
(10153, 10199),
35-
(10112, 10069),
36-
(10023, 10153),
37-
(10012, 10003),
38-
]
39-
40-
41-
def test_sql_execution_partial(ws, env_or_skip):
42-
results = []
43+
44+
records = see.fetch_all(NYC_TAXI_TRIPS_LIMITED, catalog="samples")
45+
46+
assert len([True for _ in records]) > 1
47+
48+
49+
def test_sql_execution_as_iterator(ws, env_or_skip) -> None:
50+
number_of_records = 0
4351
see = StatementExecutionExt(ws, warehouse_id=env_or_skip("TEST_DEFAULT_WAREHOUSE_ID"), catalog="samples")
44-
for row in see("SELECT * FROM nyctaxi.trips LIMIT 10"):
45-
pickup_time, dropoff_time = row[0], row[1]
46-
pickup_zip = row.pickup_zip
47-
dropoff_zip = row["dropoff_zip"]
52+
for row in see(NYC_TAXI_TRIPS_LIMITED):
53+
pickup_zip, dropoff_zip, pickup_time, dropoff_time = row[0], row[1], row[2], row[3]
4854
all_fields = row.asDict()
4955
logger.info(f"{pickup_zip}@{pickup_time} -> {dropoff_zip}@{dropoff_time}: {all_fields}")
50-
results.append((pickup_zip, dropoff_zip))
51-
assert results == [
52-
(10282, 10171),
53-
(10110, 10110),
54-
(10103, 10023),
55-
(10022, 10017),
56-
(10110, 10282),
57-
(10009, 10065),
58-
(10153, 10199),
59-
(10112, 10069),
60-
(10023, 10153),
61-
(10012, 10003),
62-
]
56+
number_of_records += 1
57+
assert number_of_records > 1
6358

6459

6560
def test_fetch_one(ws):
@@ -73,9 +68,10 @@ def test_fetch_one_fails_if_limit_is_bigger(ws):
7368
see.fetch_one("SELECT * FROM samples.nyctaxi.trips LIMIT 100")
7469

7570

76-
def test_fetch_one_works(ws):
71+
def test_fetch_one_works(ws) -> None:
7772
see = StatementExecutionExt(ws)
78-
row = see.fetch_one("SELECT * FROM samples.nyctaxi.trips LIMIT 1")
73+
row = see.fetch_one("SELECT pickup_zip FROM samples.nyctaxi.trips WHERE pickup_zip == 10282 LIMIT 1")
74+
assert row is not None
7975
assert row.pickup_zip == 10282
8076

8177

tests/integration/test_dashboards.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def create(*, display_name: str = "") -> SDKDashboard:
5858
display_name = f"created_by_lsql_{make_random()}"
5959
else:
6060
display_name = f"{display_name} ({make_random()})"
61-
dashboard = ws.lakeview.create(dashboard=SDKDashboard(display_name=display_name).as_dict())
61+
dashboard = ws.lakeview.create(dashboard=SDKDashboard(display_name=display_name))
6262
if is_in_debug():
6363
dashboard_url = f"{ws.config.host}/sql/dashboardsv3/{dashboard.dashboard_id}"
6464
webbrowser.open(dashboard_url)
@@ -117,7 +117,7 @@ def test_dashboards_creates_exported_dashboard_definition(ws, make_dashboard) ->
117117
dashboard_content = (Path(__file__).parent / "dashboards" / "dashboard.lvdash.json").read_text()
118118

119119
dashboard_to_create = dataclasses.replace(sdk_dashboard, serialized_dashboard=dashboard_content)
120-
ws.lakeview.update(sdk_dashboard.dashboard_id, dashboard=dashboard_to_create.as_dict())
120+
ws.lakeview.update(sdk_dashboard.dashboard_id, dashboard=dashboard_to_create)
121121
lakeview_dashboard = Dashboard.from_dict(json.loads(dashboard_content))
122122
new_dashboard = dashboards.get_dashboard(sdk_dashboard.path)
123123

tests/unit/test_dashboards.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,7 @@ def test_dashboards_calls_create_without_dashboard_id() -> None:
14781478

14791479
dashboards.create_dashboard(dashboard_metadata, parent_path="/non/existing/path", warehouse_id="warehouse")
14801480

1481-
ws.lakeview.create.assert_called_with(dashboard=sdk_dashboard.as_dict())
1481+
ws.lakeview.create.assert_called_with(dashboard=sdk_dashboard)
14821482
ws.lakeview.update.assert_not_called()
14831483
ws.lakeview.publish.assert_not_called()
14841484

@@ -1498,7 +1498,7 @@ def test_dashboards_calls_update_with_dashboard_id() -> None:
14981498
dashboards.create_dashboard(dashboard_metadata, dashboard_id="id", warehouse_id="warehouse")
14991499

15001500
ws.lakeview.create.assert_not_called()
1501-
ws.lakeview.update.assert_called_with("id", dashboard=sdk_dashboard.as_dict())
1501+
ws.lakeview.update.assert_called_with("id", dashboard=sdk_dashboard)
15021502
ws.lakeview.publish.assert_not_called()
15031503

15041504

0 commit comments

Comments
 (0)