Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend replace database in query #210

Merged
merged 18 commits into from
Jul 11, 2024
Merged
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
8 changes: 6 additions & 2 deletions labs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ commands:
flags:
- name: folder
description: The folder with dashboard files. By default, the current working directory.
- name: catalog
description: |
Overwrite the catalog in the queries' `FROM` clauses with given value.
Useful when developing with seperated catalogs, for example, for production and development.
- name: database
description: |
Overwrite the database in query with given value. Useful when developing with seperated databases, for
example, for production and development.
Overwrite the database in the queries' `FROM` clauses 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
13 changes: 6 additions & 7 deletions src/databricks/labs/lsql/cli.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
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
from databricks.labs.lsql.dashboards import DashboardMetadata, Dashboards

logger = get_logger(__file__)
lsql = App(__file__)
Expand All @@ -18,17 +16,18 @@ def create_dashboard(
w: WorkspaceClient,
folder: Path = Path.cwd(),
*,
catalog: str = "",
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)
dashboard_metadata = DashboardMetadata.from_path(folder).replace_database(
catalog=catalog or None, database=database or None
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
catalog=catalog or None, database=database or None
catalog=catalog or None, database=database or None,

nit

Copy link
Member Author

Choose a reason for hiding this comment

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

lakeview_dashboard = lakeview_dashboards.create_dashboard(dashboard_metadata)
sdk_dashboard = lakeview_dashboards.deploy_dashboard(lakeview_dashboard)
if not no_open:
assert sdk_dashboard.dashboard_id is not None
Expand Down
Loading
Loading