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

fix(dbt): dbt Cloud columns as the standard #197

Merged
merged 1 commit into from
Mar 31, 2023
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
4 changes: 4 additions & 0 deletions src/preset_cli/api/clients/dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,10 @@ def get_models(self, job_id: int) -> List[ModelSchema]:
description
meta
tags
columns {
name
description
}
}
}
"""
Expand Down
1 change: 1 addition & 0 deletions src/preset_cli/cli/superset/sync/dbt/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def dbt_core( # pylint: disable=too-many-arguments, too-many-locals
# conform to the same schema that dbt Cloud uses for models
unique_id = config["uniqueId"] = config["unique_id"]
config["children"] = configs["child_map"][unique_id]
config["columns"] = list(config["columns"].values())
models.append(model_schema.load(config))
models = apply_select(models, select, exclude)
model_map = {
Expand Down
7 changes: 4 additions & 3 deletions src/preset_cli/cli/superset/sync/dbt/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,13 @@ def sync_datasets( # pylint: disable=too-many-locals, too-many-branches, too-ma

# update column descriptions
if columns := model.get("columns"):
column_metadata = {column["name"]: column for column in columns}
current_columns = client.get_dataset(dataset["id"])["columns"]
for column in current_columns:
name = column["column_name"]
if name in columns:
column["description"] = columns[name].get("description", "")
column["label"] = columns[name].get("label", "")
if name in column_metadata:
column["description"] = column_metadata[name].get("description", "")
column["verbose_name"] = column_metadata[name].get("name", "")

# remove columns that are not part of the update payload
for key in ("changed_on", "created_on", "type_generic"):
Expand Down
4 changes: 2 additions & 2 deletions tests/cli/superset/sync/dbt/command_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_dbt_core(mocker: MockerFixture, fs: FakeFilesystem) -> None:
models = [
{
"database": "examples_dev",
"columns": {},
"columns": [],
"meta": {},
"description": "",
"name": "messages_channels",
Expand Down Expand Up @@ -341,7 +341,7 @@ def test_dbt(mocker: MockerFixture, fs: FakeFilesystem) -> None:
{
"meta": {},
"tags": [],
"columns": {},
"columns": [],
"schema": "public",
"name": "messages_channels",
"database": "examples_dev",
Expand Down
14 changes: 7 additions & 7 deletions tests/cli/superset/sync/dbt/datasets_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"meta": {},
"name": "messages_channels",
"unique_id": "model.superset_examples.messages_channels",
"columns": {"id": {"description": "Primary key", "label": "some label"}},
"columns": [{"name": "id", "description": "Primary key"}],
},
),
]
Expand Down Expand Up @@ -115,8 +115,8 @@ def test_sync_datasets_new(mocker: MockerFixture) -> None:
{
"column_name": "id",
"description": "Primary key",
"label": "some label",
"is_dttm": False,
"verbose_name": "id",
},
{
"column_name": "ts",
Expand Down Expand Up @@ -152,7 +152,7 @@ def test_sync_datasets_with_alias(mocker: MockerFixture) -> None:
"meta": {},
"name": "messages_channels",
"unique_id": "model.superset_examples.messages_channels",
"columns": {"id": {"description": "Primary key"}},
"columns": [{"name": "id", "description": "Primary key"}],
},
),
]
Expand Down Expand Up @@ -206,8 +206,8 @@ def test_sync_datasets_with_alias(mocker: MockerFixture) -> None:
{
"column_name": "id",
"description": "Primary key",
"label": "",
"is_dttm": False,
"verbose_name": "id",
},
{
"column_name": "ts",
Expand Down Expand Up @@ -266,8 +266,8 @@ def test_sync_datasets_no_metrics(mocker: MockerFixture) -> None:
{
"column_name": "id",
"description": "Primary key",
"label": "some label",
"is_dttm": False,
"verbose_name": "id",
},
],
),
Expand Down Expand Up @@ -359,8 +359,8 @@ def test_sync_datasets_existing(mocker: MockerFixture) -> None:
{
"column_name": "id",
"description": "Primary key",
"label": "some label",
"is_dttm": False,
"verbose_name": "id",
},
],
),
Expand Down Expand Up @@ -447,8 +447,8 @@ def test_sync_datasets_external_url(mocker: MockerFixture) -> None:
{
"column_name": "id",
"description": "Primary key",
"label": "some label",
"is_dttm": False,
"verbose_name": "id",
},
],
),
Expand Down