-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dashboard-as-code functionality (#201)
Initial version that covers functionality for [ucx](https://github.com/databrickslabs/ucx). This is a big PR staged to resolve #138. It was broken in multiple smaller PR into this feature branch (see links int the commits). The feature branch allows for reviewing of the dashboard as code functionality. - [x] Resolves #141 - [x] Resolves #112 - [x] Resolves #130 - [x] Resolves #131 - [x] Resolves #148 - [x] Resolves #133 - [x] Resolves #135 - [x] Resolves #202 - [x] Resolves #137 - [x] Resolves #110 - [x] Resolves #114 - [x] Resolves #158 - [x] Resolves #159 - [x] Resolves #163 - [x] Resolves #165 - [x] Resolves #169 - [x] Resolves #175 - [x] Resolves #187 - [x] Resolves #191 - [x] Resolves #200 - [x] Resolves #180 - [x] Resolves #157 - [x] Partially resolves #134 --------- Co-authored-by: Serge Smertin <[email protected]>
- Loading branch information
1 parent
f1bbf54
commit 56e7f70
Showing
13 changed files
with
2,093 additions
and
378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
name: lsql | ||
description: Lightweight SQL execution wrapper only on top of Databricks SDK | ||
entrypoint: src/databricks/labs/lsql/cli.py | ||
min_python: 3.10 | ||
commands: | ||
- name: create-dashboard | ||
description: Create an unpublished dashboard from code, see [docs](./docs/dashboards.md). | ||
flags: | ||
- name: folder | ||
description: The folder with dashboard files. By default, the current working directory. | ||
- name: database | ||
description: | | ||
Overwrite the database in query with given value. Useful when developing with seperated databases, for | ||
example, for production and development. | ||
- name: no-open | ||
description: Do not open the dashboard in the browser after creating |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .core import Row | ||
from databricks.labs.lsql.core import Row | ||
|
||
__all__ = ["Row"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import functools | ||
import webbrowser | ||
from pathlib import Path | ||
|
||
from databricks.labs.blueprint.cli import App | ||
from databricks.labs.blueprint.entrypoint import get_logger | ||
from databricks.sdk import WorkspaceClient | ||
|
||
from databricks.labs.lsql import dashboards | ||
from databricks.labs.lsql.dashboards import Dashboards | ||
|
||
logger = get_logger(__file__) | ||
lsql = App(__file__) | ||
|
||
|
||
@lsql.command | ||
def create_dashboard( | ||
w: WorkspaceClient, | ||
folder: Path = Path.cwd(), | ||
*, | ||
database: str = "", | ||
no_open: bool = False, | ||
): | ||
"""Create a dashboard from queries""" | ||
logger.debug("Creating dashboard ...") | ||
lakeview_dashboards = Dashboards(w) | ||
folder = Path(folder) | ||
replace_database_in_query = None | ||
if database: | ||
replace_database_in_query = functools.partial(dashboards.replace_database_in_query, database=database) | ||
lakeview_dashboard = lakeview_dashboards.create_dashboard(folder, query_transformer=replace_database_in_query) | ||
sdk_dashboard = lakeview_dashboards.deploy_dashboard(lakeview_dashboard) | ||
dashboard_url = f"{w.config.host}/sql/dashboardsv3/{sdk_dashboard.dashboard_id}" | ||
if not no_open: | ||
webbrowser.open(dashboard_url) | ||
print(sdk_dashboard.dashboard_id) | ||
|
||
|
||
if __name__ == "__main__": | ||
lsql() |
Oops, something went wrong.