-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dagster-powerbi] Pull owners, additional asset metadata (#25676)
## Summary Pull owner metadata as well as columnar metadata from PowerBI, if available. ## How I Tested These Changes Update unit tests. ## Changelog > [dagster-powerbi] When using a full workspace scan, owner and column metadata is now attached automatically to assets.
- Loading branch information
Showing
3 changed files
with
159 additions
and
22 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 |
---|---|---|
|
@@ -39,14 +39,14 @@ | |
"datasetWorkspaceId": "a2122b8f-d7e1-42e8-be2b-a5e636ca3221", | ||
"users": [], | ||
"subscriptions": [], | ||
"createdBy": "[email protected]", | ||
} | ||
|
||
SAMPLE_SEMANTIC_MODEL = { | ||
"id": "8e9c85a1-7b33-4223-9590-76bde70f9a20", | ||
"name": "Sales & Returns Sample v201912", | ||
"webUrl": "https://app.powerbi.com/groups/a2122b8f-d7e1-42e8-be2b-a5e636ca3221/datasets/8e9c85a1-7b33-4223-9590-76bde70f9a20", | ||
"addRowsAPIEnabled": False, | ||
"configuredBy": "[email protected]", | ||
"isRefreshable": True, | ||
"isEffectiveIdentityRequired": False, | ||
"isEffectiveIdentityRolesRequired": False, | ||
|
@@ -58,6 +58,19 @@ | |
"upstreamDatasets": [], | ||
"users": [], | ||
"queryScaleOutSettings": {"autoSyncReadOnlyReplicas": True, "maxReadOnlyReplicas": 0}, | ||
"configuredBy": "[email protected]", | ||
"tables": [ | ||
{ | ||
"name": "sales", | ||
"columns": [ | ||
{"name": "order_id", "dataType": "Int64"}, | ||
{"name": "product_id", "dataType": "Int64"}, | ||
{"name": "quantity", "dataType": "Int64"}, | ||
{"name": "price", "dataType": "Decimal"}, | ||
{"name": "order_date", "dataType": "DateTime"}, | ||
], | ||
} | ||
], | ||
} | ||
|
||
|
||
|
@@ -78,6 +91,26 @@ | |
"upstreamDatasets": [], | ||
"users": [], | ||
"queryScaleOutSettings": {"autoSyncReadOnlyReplicas": True, "maxReadOnlyReplicas": 0}, | ||
"tables": [ | ||
{ | ||
"name": "sales", | ||
"columns": [ | ||
{"name": "order_id", "dataType": "Int64"}, | ||
{"name": "product_id", "dataType": "Int64"}, | ||
{"name": "quantity", "dataType": "Int64"}, | ||
{"name": "price", "dataType": "Decimal"}, | ||
{"name": "order_date", "dataType": "DateTime"}, | ||
], | ||
}, | ||
{ | ||
"name": "customers", | ||
"columns": [ | ||
{"name": "customer_id", "dataType": "Int64"}, | ||
{"name": "customer_name", "dataType": "String"}, | ||
{"name": "customer_email", "dataType": "String"}, | ||
], | ||
}, | ||
], | ||
} | ||
|
||
|
||
|
@@ -266,3 +299,21 @@ def second_workspace_data_api_mocks_fixture( | |
) | ||
|
||
yield workspace_data_api_mocks | ||
|
||
|
||
@pytest.fixture( | ||
name="second_workspace_data", | ||
) | ||
def second_workspace_data_fixture(second_workspace_id: str) -> PowerBIWorkspaceData: | ||
return PowerBIWorkspaceData( | ||
workspace_id=second_workspace_id, | ||
dashboards_by_id={}, | ||
reports_by_id={}, | ||
semantic_models_by_id={ | ||
OTHER_SAMPLE_SEMANTIC_MODEL["id"]: PowerBIContentData( | ||
content_type=PowerBIContentType.SEMANTIC_MODEL, | ||
properties=OTHER_SAMPLE_SEMANTIC_MODEL, | ||
) | ||
}, | ||
data_sources_by_id={}, | ||
) |
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,6 +1,7 @@ | ||
from dagster._core.definitions.asset_key import AssetKey | ||
from dagster._core.definitions.asset_spec import AssetSpec | ||
from dagster._core.definitions.metadata.metadata_value import MetadataValue | ||
from dagster._core.definitions.metadata.table import TableColumn, TableSchema | ||
from dagster._core.definitions.tags import build_kind_tag | ||
from dagster_powerbi import DagsterPowerBITranslator | ||
from dagster_powerbi.translator import PowerBIContentData, PowerBIWorkspaceData | ||
|
@@ -48,6 +49,7 @@ def test_translator_report_spec(workspace_data: PowerBIWorkspaceData) -> None: | |
**build_kind_tag("powerbi"), | ||
**build_kind_tag("report"), | ||
} | ||
assert asset_spec.owners == ["[email protected]"] | ||
|
||
|
||
def test_translator_semantic_model(workspace_data: PowerBIWorkspaceData) -> None: | ||
|
@@ -66,12 +68,52 @@ def test_translator_semantic_model(workspace_data: PowerBIWorkspaceData) -> None | |
"https://app.powerbi.com/groups/a2122b8f-d7e1-42e8-be2b-a5e636ca3221/datasets/8e9c85a1-7b33-4223-9590-76bde70f9a20" | ||
), | ||
"dagster-powerbi/id": "8e9c85a1-7b33-4223-9590-76bde70f9a20", | ||
"dagster/table_name": "sales", | ||
"dagster/column_schema": TableSchema( | ||
columns=[ | ||
TableColumn(name="order_id", type="Int64"), | ||
TableColumn(name="product_id", type="Int64"), | ||
TableColumn(name="quantity", type="Int64"), | ||
TableColumn(name="price", type="Decimal"), | ||
TableColumn(name="order_date", type="DateTime"), | ||
] | ||
), | ||
} | ||
assert asset_spec.tags == { | ||
"dagster-powerbi/asset_type": "semantic_model", | ||
**build_kind_tag("powerbi"), | ||
**build_kind_tag("semantic model"), | ||
} | ||
assert asset_spec.owners == ["[email protected]"] | ||
|
||
|
||
def test_translator_semantic_model_many_tables(second_workspace_data: PowerBIWorkspaceData) -> None: | ||
semantic_model = next(iter(second_workspace_data.semantic_models_by_id.values())) | ||
|
||
translator = DagsterPowerBITranslator(second_workspace_data) | ||
asset_spec = translator.get_asset_spec(semantic_model) | ||
assert asset_spec.metadata == { | ||
"dagster-powerbi/web_url": MetadataValue.url( | ||
"https://app.powerbi.com/groups/a2122b8f-d7e1-42e8-be2b-a5e636ca3221/datasets/8e9c85a1-7b33-4223-9590-76bde70f9a20" | ||
), | ||
"dagster-powerbi/id": "ae9c85a1-7b33-4223-9590-76bde70f9a20", | ||
"sales_column_schema": TableSchema( | ||
columns=[ | ||
TableColumn(name="order_id", type="Int64"), | ||
TableColumn(name="product_id", type="Int64"), | ||
TableColumn(name="quantity", type="Int64"), | ||
TableColumn(name="price", type="Decimal"), | ||
TableColumn(name="order_date", type="DateTime"), | ||
] | ||
), | ||
"customers_column_schema": TableSchema( | ||
columns=[ | ||
TableColumn(name="customer_id", type="Int64"), | ||
TableColumn(name="customer_name", type="String"), | ||
TableColumn(name="customer_email", type="String"), | ||
] | ||
), | ||
} | ||
|
||
|
||
class MyCustomTranslator(DagsterPowerBITranslator): | ||
|