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

Handle query with star #155

Merged
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
2 changes: 2 additions & 0 deletions src/databricks/labs/lsql/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ def _get_fields(query: str) -> list[Field]:
continue
for named_select in projection.named_selects:
field = Field(name=named_select, expression=f"`{named_select}`")
if named_select == "*":
raise NotImplementedError(f"Select with `*` is ignored, please define column explicitly: {query}")
fields.append(field)
return fields

Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,20 @@ def test_dashboard_handles_incorrect_query_header(tmp_path, caplog):
ws.assert_not_called()


def test_dashboard_handles_query_with_star(tmp_path, caplog):
ws = create_autospec(WorkspaceClient)

query = "SELECT * FROM table"
with (tmp_path / "star.sql").open("w") as f:
f.write(query)

with pytest.raises(NotImplementedError) as e:
Dashboards(ws).create_dashboard(tmp_path)

assert query in str(e)
ws.assert_not_called()


@pytest.mark.parametrize(
"query",
[
Expand Down
Loading