Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/acceptance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ permissions:
concurrency:
group: single-acceptance-job-per-repo

env:
HATCH_VERBOSE: "2"
HATCH_VERSION: "1.16.5"

jobs:
integration:
if: github.event_name == 'pull_request' && github.event.pull_request.draft == false
Expand All @@ -32,7 +36,7 @@ jobs:
python-version: '3.10'

- name: Install hatch
run: pip install hatch==1.9.4
run: pip install "hatch==${HATCH_VERSION}"

- name: Run integration tests
uses: databrickslabs/sandbox/acceptance@acceptance/v0.4.2
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/downstreams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ permissions:
contents: read
pull-requests: write

env:
HATCH_VERBOSE: "2"
HATCH_VERSION: '1.16.5'

jobs:
compatibility:
strategy:
Expand All @@ -44,7 +48,8 @@ jobs:

- name: Install toolchain
run: |
pip install hatch==1.9.4
pip install "hatch==${HATCH_VERSION}"

- name: Acceptance
uses: databrickslabs/sandbox/downstreams@acceptance/v0.4.2
with:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ permissions:
concurrency:
group: single-acceptance-job-per-repo

env:
HATCH_VERBOSE: "2"
HATCH_VERSION: "1.16.5"

jobs:
integration:
environment: runtime
Expand All @@ -32,7 +36,7 @@ jobs:
python-version: '3.10'

- name: Install hatch
run: pip install hatch==1.9.4
run: pip install "hatch==${HATCH_VERSION}"

- name: Run nightly tests
uses: databrickslabs/sandbox/acceptance@acceptance/v0.4.2
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ on:
branches:
- main

env:
HATCH_VERBOSE: "2"
HATCH_VERSION: "1.16.5"

jobs:
ci:
strategy:
Expand All @@ -34,7 +38,7 @@ jobs:

- name: Run unit tests
run: |
pip install hatch==1.9.4
pip install "hatch==${HATCH_VERSION}"
make test

- name: Publish test coverage
Expand All @@ -55,7 +59,7 @@ jobs:

- name: Format all files
run: |
pip install hatch==1.9.4
pip install "hatch==${HATCH_VERSION}"
make dev fmt

- name: Fail on differences
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
tags:
- 'v*'

env:
HATCH_VERBOSE: "2"
HATCH_VERSION: "1.16.5"

jobs:
publish:
runs-on:
Expand All @@ -27,7 +31,7 @@ jobs:

- name: Build wheels
run: |
pip install hatch==1.9.4
pip install "hatch==${HATCH_VERSION}"
hatch build
- name: Draft release
Expand Down
15 changes: 14 additions & 1 deletion src/databricks/labs/lsql/lakeview/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,20 @@ def as_dict(self) -> Json:

@classmethod
def from_dict(cls, d: Json) -> Dataset:
return cls(display_name=d.get("displayName", None), name=d.get("name", None), query=d.get("query", None))
# Compatibility:
# - Dashboard APIs previously placed the queries in the "query" attribute as-is, but now it's placed in the
# "queryLines" attribute as an array of strings.
# - We need to load from both previously saved files, as well as the Dashboard APIs.
# - Canonical format is therefore "query".
query: str | None
match d:
case {"query": str() as query, **_kw}:
pass
case {"queryLines": list() as queryLines, **_kw}:
query = "".join(queryLines)
case _:
query = None
return cls(display_name=d.get("displayName", None), name=d.get("name", None), query=query)


@dataclass
Expand Down
24 changes: 24 additions & 0 deletions tests/integration/test_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
import datetime as dt
import json
import logging
import textwrap
import webbrowser
from pathlib import Path

import pytest
from databricks.labs.blueprint.entrypoint import is_in_debug
from databricks.sdk import WorkspaceClient
from databricks.sdk.core import DatabricksError
from databricks.sdk.service.catalog import SchemaInfo
from databricks.sdk.service.dashboards import Dashboard as SDKDashboard
Expand Down Expand Up @@ -143,6 +145,28 @@ def test_dashboard_deploys_dashboard_the_same_as_created_dashboard(ws, make_dash
)


def test_dashboards_save_to_folder_saves_sql_files(ws: WorkspaceClient, make_dashboard, tmp_path: Path) -> None:
dashboards = Dashboards(ws)
sdk_dashboard = make_dashboard()

(tmp_path / "counter.sql").write_text("SELECT 10 AS count", encoding="utf-8")
dashboard_metadata = DashboardMetadata.from_path(tmp_path)
sdk_dashboard = dashboards.create_dashboard(dashboard_metadata, dashboard_id=sdk_dashboard.dashboard_id)

assert sdk_dashboard.path is not None
lakeview_dashboard = dashboards.get_dashboard(sdk_dashboard.path)
save_path = tmp_path / "saved"
dashboards.save_to_folder(lakeview_dashboard, save_path)

exported_path = save_path / "counter.sql"
exported_query = exported_path.read_text(encoding="utf-8")
# Exporting formats the queries with sqlglot.
expected_query = textwrap.dedent("""\
SELECT
10 AS count""")
assert exported_query == expected_query


def test_dashboard_deploys_dashboard_with_ten_counters(ws, make_dashboard, tmp_path):
dashboards = Dashboards(ws)
sdk_dashboard = make_dashboard()
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/lakeview/test_model.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
from databricks.labs.lsql.lakeview.model import (
Dataset,
PaginationSize,
TableV1EncodingMap,
TableV1Spec,
)


def test_dataset_serialisation_round_trip() -> None:
dataset = Dataset("a_name", display_name="A Name", query="SELECT a FROM name")
serialized_first = dataset.as_dict()
restored = Dataset.from_dict(serialized_first)
assert dataset == restored
serialized_second = restored.as_dict()
assert serialized_first == serialized_second


def test_dataset_from_dict_reads_query_lines() -> None:
dataset = Dataset.from_dict({"name": "d", "queryLines": ["SELECT ", "1"]})
assert dataset.query == "SELECT 1"


def test_dataset_from_dict_query_is_none_when_absent() -> None:
dataset = Dataset.from_dict({"name": "d"})
assert dataset.query is None


def test_dataset_from_dict_reads_query() -> None:
dataset = Dataset.from_dict({"name": "d", "query": "SELECT 1"})
assert dataset.query == "SELECT 1"


def test_table_v1_spec_adds_invisible_columns_to_dict():
table_encodings = TableV1EncodingMap(None)
spec = TableV1Spec(
Expand Down
Loading