From d757f7c162a727751beffef77ccf4256eb273f70 Mon Sep 17 00:00:00 2001 From: Brock Griffey <52086127+brock-acryl@users.noreply.github.com> Date: Mon, 2 Nov 2026 11:35:43 -0500 Subject: [PATCH 1/7] fix(ingest/powerbi): derive page and tile chart inputs from report fields With `extract_report_field_usage`, a report page chart's `ChartInfo.inputs` are now the semantic-model tables its visuals' resolved field references belong to (first-seen order) instead of every table of the model; a page whose references resolve to no table keeps the whole model, and the flag off keeps today's output. A tile pinned from a report takes the union of its report's pages' resolved tables, memoised per report id on the Mapper and resolved counter-free, so the page pass alone feeds the `report_field_references_*` counters as before; tiles pinned from a dataset, or from a report without resolved field references, keep the whole model. Page charts now carry `chartUrl` (the report URL plus the page segment, via `_page_url`) in every mode. This changes the flag-off goldens too: each page chart gains a `chartUrl`, which is intended; narrowed page `inputs` appear only in the workspace_apis field-usage goldens. An untitled tile is named `Tile ` after its 1-based position on the dashboard (`Constant.TILE_TITLE_FALLBACK`), applied to both `title` and `description`, instead of an empty string. Co-Authored-By: Claude Fable 5.1 --- .../docs/sources/powerbi/powerbi_pre.md | 2 +- .../ingestion/source/powerbi/config.py | 4 + .../ingestion/source/powerbi/powerbi.py | 70 +++++-- .../powerbi/golden_test_container.json | 2 + .../golden_test_databricks_native_query.json | 1 + .../powerbi/golden_test_mysql.json | 1 + .../golden_test_mysql_odbc_datasource.json | 1 + .../powerbi/golden_test_report.json | 2 + .../golden_test_soft_reference_mode.json | 1 + ...olden_test_workspace_apis_field_usage.json | 13 +- .../golden_test_workspace_apis_ingest.json | 13 +- .../test_enrich_from_item_definitions.py | 2 +- .../powerbi/test_workspace_apis_mapper.py | 188 +++++++++++++++++- 13 files changed, 264 insertions(+), 36 deletions(-) diff --git a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md index e067eea8f45a7..005238243466e 100644 --- a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md +++ b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md @@ -92,7 +92,7 @@ If the principal only has the `Viewer` role on a workspace, the dataset listing No Microsoft Entra application permissions need to change: both API families are authorized through the tenant settings and workspace roles above. The application requests a second token audience (`https://api.fabric.microsoft.com/.default`) in addition to the Power BI one. -What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report (not a paginated report, which never gets field usage or filters) whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. +What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report (not a paginated report, which never gets field usage or filters) whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. When field usage is extracted, a page chart and a tile pinned from a report list as inputs only the model tables their fields read (a page whose fields resolve to no table keeps the whole model); each page chart also links to its URL in the Power BI service, and a tile without a title is named `Tile ` after its 1-based position on the dashboard. **Fabric Lakehouse and Warehouse lineage.** The connector lists each workspace's Fabric items and registers the SQL analytics endpoint of every Lakehouse (one `GET lakehouses/{id}` call per lakehouse) and Warehouse (a warehouse is its own endpoint). A semantic-model table that reads one of them, either in DirectLake mode or through an Import/DirectQuery `Sql.Database(".datawarehouse.fabric.microsoft.com", ...)` query (a table navigation or a native `[Query=...]`), gets upstream lineage to the OneLake table (`fabric-onelake` platform, the same URN the OneLake connector emits) instead of a generic `mssql` one. The `Sql.Database` mapping applies in both metadata modes, since the admin scan also lists the workspace's Lakehouses and Warehouses. Map the workspace id in `server_to_platform_instance` to set the OneLake `platform_instance` and `env`. These OneLake edges are not subject to `dataset_type_mapping`, same as DirectLake lineage, so narrowing that mapping never turns such an edge into none; Dataflow Gen2 entities get the same mapping. The URNs match the OneLake connector's when that source runs with `convert_urns_to_lowercase: true` or this one with `convert_lineage_urns_to_lowercase: false` (by default Power BI lowercases the whole lineage URN while the OneLake connector keeps schema and table casing). A `Sql.Database` query may name the endpoint by id or by the item's display name. In `workspace_apis` mode a display name only matches on the workspace's own endpoint host; the admin scan reports no host, so there a display name matches the workspace's item on any host. A query naming an endpoint that is not among the workspace's items (for example a lakehouse in a workspace outside your workspace patterns) keeps its generic `mssql` edge and is reported as a `Fabric Endpoint Not Resolved` warning, and a display name shared by several items is reported as `Fabric Endpoint Name Ambiguous`. A `Sql.Databases` navigation, a navigation without an `Item`, or an endpoint behind a dataset parameter the connector could not resolve (the server argument is a parameter missing from the dataset) is not mapped: the first two are reported as `Fabric Endpoint M Shape Unsupported`, the last falls through to the generic SQL Server handling. Datamarts, mirrored databases and SQL databases are not covered: the OneLake connector does not ingest their tables, so no edge is emitted for them. diff --git a/metadata-ingestion/src/datahub/ingestion/source/powerbi/config.py b/metadata-ingestion/src/datahub/ingestion/source/powerbi/config.py index 89d959fe79ad3..90ade3093d1d4 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/powerbi/config.py +++ b/metadata-ingestion/src/datahub/ingestion/source/powerbi/config.py @@ -281,6 +281,8 @@ class Constant: PAGE_NAME = "pageName" VISUAL = "Visual" VISUAL_TITLE_FALLBACK = "{visual_type} on {page}" + # An untitled tile is named by its 1-based position on the dashboard. + TILE_TITLE_FALLBACK = "Tile {position}" URL_QUERY_SEPARATOR = "?" TOP = "$top" # Scan-API column types reproduced for TMDL-sourced columns @@ -1201,6 +1203,8 @@ class PowerBiDashboardSourceConfig( "page filter reads join that page's `inputFields`, and the fields a report " "filter reads join every page's. Note that a filter's condition includes the " "literal values it compares against, which may be business data. " + "Page charts and tiles pinned from the report then list only the model " + "tables their fields read as inputs, instead of every table of the model. " "Adds one Fabric getDefinition call per report. " "Requires `extract_reports`, `extract_dataset_schema` and either " "`metadata_api_mode: workspace_apis` or `enrich_from_item_definitions`.", diff --git a/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py b/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py index e018b9c399b8c..1b98f88634b82 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py +++ b/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py @@ -516,6 +516,9 @@ def __init__( # Refresh Operations are decided once per dataset and emitted on each # of its tables, so counters and warnings fire per dataset. self.__refresh_plans: Dict[str, List[_RefreshOperationPlan]] = {} + # Tables a report's pages read (from their resolved field references), + # by report id: every tile built from the report asks for them. + self.__report_used_dataset_urns: Dict[str, List[str]] = {} @staticmethod def urn_to_lowercase(value: str, flag: bool) -> str: @@ -2266,9 +2269,11 @@ def to_datahub_chart_mcp( ds_mcps: List[MetadataChangeProposalWrapper], workspace: powerbi_data_classes.Workspace, dashboard: powerbi_data_classes.Dashboard, + position: int = 1, ) -> List[MetadataChangeProposalWrapper]: """ - Map PowerBi tile to datahub chart + Map PowerBi tile to datahub chart. `position` is the tile's 1-based + place on the dashboard, which names a tile that has no title. """ logger.info( f"Converting tile {tile.title or '(untitled)'}(id={tile.id}) to chart" @@ -2285,6 +2290,12 @@ def to_datahub_chart_mcp( ds_input: List[str] = self.to_urn_set( [x for x in ds_mcps if x.entityType == Constant.DATASET] ) + # A tile pinned from a report shows one of its visuals, so when the + # report's definition told us which tables its pages read, those are + # the tile's inputs rather than every table of the model. + if tile.report is not None: + ds_input = self._report_used_dataset_urns(tile.report) or ds_input + title = tile.title or Constant.TILE_TITLE_FALLBACK.format(position=position) def tile_custom_properties(tile: powerbi_data_classes.Tile) -> dict: custom_properties: dict = { @@ -2308,8 +2319,8 @@ def tile_custom_properties(tile: powerbi_data_classes.Tile) -> dict: # Create chartInfo mcp # Set chartUrl only if tile is created from Report chart_info_instance = ChartInfoClass( - title=tile.title or "", - description=tile.title or "", + title=title, + description=title, lastModified=ChangeAuditStamps(), inputs=ds_input, externalUrl=tile.report.webUrl if tile.report else None, @@ -2738,14 +2749,14 @@ def to_datahub_chart( logger.info(f"Converting tiles(count={len(tiles)}) to charts") - for tile in tiles: + for position, tile in enumerate(tiles, start=1): if tile is None: continue # First convert the dataset to MCP, because dataset mcp is used in input attribute of chart mcp dataset_mcps = self.to_datahub_dataset(tile.dataset, workspace) # Now convert tile to chart MCP chart_mcp = self.to_datahub_chart_mcp( - tile, dataset_mcps, workspace, dashboard + tile, dataset_mcps, workspace, dashboard, position=position ) ds_mcps.extend(dataset_mcps) @@ -2838,20 +2849,47 @@ def _filter_properties( self.__reporter.report_filters_truncated += len(filters) - len(kept) return properties - def _page_input_fields_mcp( + def _page_input_fields( self, page: powerbi_data_classes.Page, report: powerbi_data_classes.Report, chart_urn: str, - ) -> Optional[MetadataChangeProposalWrapper]: + ) -> ResolvedInputFields: """Model columns and measures the page's visuals read, as inputFields - pointing at the semantic-model tables' schema fields.""" + pointing at the semantic-model tables' schema fields, plus the tables + they belong to. This page pass is the only place feeding the page + counters.""" resolved = self._resolve_input_fields( page.field_references, report, chart_urn, f"page {page.name}" ) self.__reporter.report_field_references_resolved += resolved.resolved self.__reporter.report_field_references_unresolved += resolved.unresolved - return resolved.mcp + return resolved + + def _report_used_dataset_urns( + self, report: powerbi_data_classes.Report + ) -> List[str]: + """Tables the report's pages read, from their resolved field references, + in first-seen order; empty when no definition was fetched or nothing + resolved. Memoised per report id and counter-free: the page pass + already counts these references, and every tile of the report asks.""" + cached = self.__report_used_dataset_urns.get(report.id) + if cached is not None: + return cached + dataset_urns: List[str] = [] + if self.__config.extract_report_field_usage: + for page in report.pages: + resolved = self._resolve_input_fields( + page.field_references, + report, + self.make_chart_urn_for_page(page), + f"page {page.name}", + ) + for dataset_urn in resolved.dataset_urns: + if dataset_urn not in dataset_urns: + dataset_urns.append(dataset_urn) + self.__report_used_dataset_urns[report.id] = dataset_urns + return dataset_urns def _resolve_input_fields( self, @@ -3100,12 +3138,18 @@ def to_chart_mcps( custom_properties[Constant.VISUAL_TYPES] = ", ".join(page.visual_types) custom_properties.update(self._filter_properties(page.filters)) - # Create chartInfo mcp - # Set chartUrl only if tile is created from Report + resolved = self._page_input_fields(page, report, chart_urn) + # When the report definition told us which tables the page's + # visuals read, those are the page's inputs; without field usage + # (or when nothing resolved) the whole model stays, as before. + if self.__config.extract_report_field_usage and resolved.dataset_urns: + ds_input = resolved.dataset_urns + chart_info_instance = ChartInfoClass( title=page.displayName or "", description=page.displayName or "", lastModified=ChangeAuditStamps(), + chartUrl=self._page_url(report, page), inputs=ds_input, customProperties=custom_properties, ) @@ -3115,8 +3159,6 @@ def to_chart_mcps( aspect=chart_info_instance, ) - input_fields_mcp = self._page_input_fields_mcp(page, report, chart_urn) - list_of_mcps = [ info_mcp, *self._chart_common_mcps( @@ -3124,7 +3166,7 @@ def to_chart_mcps( BIAssetSubTypes.POWERBI_PAGE, workspace, report, - input_fields_mcp, + resolved.mcp, ), ] diff --git a/metadata-ingestion/tests/integration/powerbi/golden_test_container.json b/metadata-ingestion/tests/integration/powerbi/golden_test_container.json index 5d1f5162cf63a..121b3ed2b0080 100644 --- a/metadata-ingestion/tests/integration/powerbi/golden_test_container.json +++ b/metadata-ingestion/tests/integration/powerbi/golden_test_container.json @@ -4744,6 +4744,7 @@ "actor": "urn:li:corpuser:unknown" } }, + "chartUrl": "https://app.powerbi.com/groups/64ED5CAD-7C10-4684-8180-826122881108/reports/5b218778-e7a5-4d73-8187-f10824047715/ReportSection", "inputs": [ { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,library-dataset.public_issue_history,DEV)" @@ -4888,6 +4889,7 @@ "actor": "urn:li:corpuser:unknown" } }, + "chartUrl": "https://app.powerbi.com/groups/64ED5CAD-7C10-4684-8180-826122881108/reports/5b218778-e7a5-4d73-8187-f10824047715/ReportSection1", "inputs": [ { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,library-dataset.public_issue_history,DEV)" diff --git a/metadata-ingestion/tests/integration/powerbi/golden_test_databricks_native_query.json b/metadata-ingestion/tests/integration/powerbi/golden_test_databricks_native_query.json index 6a43282c2f564..66cd46f8ef471 100644 --- a/metadata-ingestion/tests/integration/powerbi/golden_test_databricks_native_query.json +++ b/metadata-ingestion/tests/integration/powerbi/golden_test_databricks_native_query.json @@ -416,6 +416,7 @@ "actor": "urn:li:corpuser:unknown" } }, + "chartUrl": "https://app.powerbi.com/groups/64ed5cad-7c10-4684-8180-826122881108/reports/5e420b19-ee14-4bba-ab4b-1e1063847f37/ReportSection", "inputs": [ { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,databricks-dataset.databricks_native-query,PROD)" diff --git a/metadata-ingestion/tests/integration/powerbi/golden_test_mysql.json b/metadata-ingestion/tests/integration/powerbi/golden_test_mysql.json index 343b97a313b6e..516e4e8d76934 100644 --- a/metadata-ingestion/tests/integration/powerbi/golden_test_mysql.json +++ b/metadata-ingestion/tests/integration/powerbi/golden_test_mysql.json @@ -549,6 +549,7 @@ "actor": "urn:li:corpuser:unknown" } }, + "chartUrl": "https://app.powerbi.com/groups/64ed5cad-7c10-4684-8180-826122881108/reports/5e420b19-ee14-4bba-ab4b-1e1063847f37/ReportSection", "inputs": [ { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,EmployeeReport.employees_employees,PROD)" diff --git a/metadata-ingestion/tests/integration/powerbi/golden_test_mysql_odbc_datasource.json b/metadata-ingestion/tests/integration/powerbi/golden_test_mysql_odbc_datasource.json index 8906df80a5fe7..d937b6dc819c2 100644 --- a/metadata-ingestion/tests/integration/powerbi/golden_test_mysql_odbc_datasource.json +++ b/metadata-ingestion/tests/integration/powerbi/golden_test_mysql_odbc_datasource.json @@ -458,6 +458,7 @@ "actor": "urn:li:corpuser:unknown" } }, + "chartUrl": "https://app.powerbi.com/groups/64ed5cad-7c10-4684-8180-826122881108/reports/5e420b19-ee14-4bba-ab4b-1e1063847f37/ReportSection", "inputs": [ { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,EmployeeReport.employees_employees,PROD)" diff --git a/metadata-ingestion/tests/integration/powerbi/golden_test_report.json b/metadata-ingestion/tests/integration/powerbi/golden_test_report.json index 4f1ccfad6347d..606241484f687 100644 --- a/metadata-ingestion/tests/integration/powerbi/golden_test_report.json +++ b/metadata-ingestion/tests/integration/powerbi/golden_test_report.json @@ -3817,6 +3817,7 @@ "actor": "urn:li:corpuser:unknown" } }, + "chartUrl": "https://app.powerbi.com/groups/64ED5CAD-7C10-4684-8180-826122881108/reports/5b218778-e7a5-4d73-8187-f10824047715/ReportSection", "inputs": [ { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,library-dataset.public_issue_history,DEV)" @@ -3945,6 +3946,7 @@ "actor": "urn:li:corpuser:unknown" } }, + "chartUrl": "https://app.powerbi.com/groups/64ED5CAD-7C10-4684-8180-826122881108/reports/5b218778-e7a5-4d73-8187-f10824047715/ReportSection1", "inputs": [ { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,library-dataset.public_issue_history,DEV)" diff --git a/metadata-ingestion/tests/integration/powerbi/golden_test_soft_reference_mode.json b/metadata-ingestion/tests/integration/powerbi/golden_test_soft_reference_mode.json index 5b2c8aa7b6b3c..ef24eeb98f072 100644 --- a/metadata-ingestion/tests/integration/powerbi/golden_test_soft_reference_mode.json +++ b/metadata-ingestion/tests/integration/powerbi/golden_test_soft_reference_mode.json @@ -442,6 +442,7 @@ "actor": "urn:li:corpuser:unknown" } }, + "chartUrl": "https://app.powerbi.com/groups/64ed5cad-7c10-4684-8180-826122881108/reports/5e420b19-ee14-4bba-ab4b-1e1063847f37/ReportSection", "inputs": [ { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,EmployeeReport.employees_employees,PROD)" diff --git a/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_field_usage.json b/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_field_usage.json index 2c1a4e3a49824..50918df883c18 100644 --- a/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_field_usage.json +++ b/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_field_usage.json @@ -2909,21 +2909,16 @@ "actor": "urn:li:corpuser:unknown" } }, + "chartUrl": "https://app.powerbi.com/groups/64ED5CAD-7C10-4684-8180-826122881108/reports/584cf13a-1485-41c2-a514-b1bb66fff163/a1b2c3d4e5f6a7b8c9d0", "inputs": [ - { - "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Claims_By_State,DEV)" - }, - { - "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Claims,DEV)" - }, - { - "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Dataflow_Policies,DEV)" - }, { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Insurance_KPIs,DEV)" }, { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Policies,DEV)" + }, + { + "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Claims,DEV)" } ] } diff --git a/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_ingest.json b/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_ingest.json index bbb3e6bd73135..4a83fd647fd30 100644 --- a/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_ingest.json +++ b/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_ingest.json @@ -4202,21 +4202,16 @@ "actor": "urn:li:corpuser:unknown" } }, + "chartUrl": "https://app.powerbi.com/groups/64ED5CAD-7C10-4684-8180-826122881108/reports/584cf13a-1485-41c2-a514-b1bb66fff163/a1b2c3d4e5f6a7b8c9d0", "inputs": [ - { - "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Claims_By_State,DEV)" - }, - { - "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Claims,DEV)" - }, - { - "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Dataflow_Policies,DEV)" - }, { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Insurance_KPIs,DEV)" }, { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Policies,DEV)" + }, + { + "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Claims,DEV)" } ] } diff --git a/metadata-ingestion/tests/unit/powerbi/test_enrich_from_item_definitions.py b/metadata-ingestion/tests/unit/powerbi/test_enrich_from_item_definitions.py index 710e0d6bb1550..900a1f976300f 100644 --- a/metadata-ingestion/tests/unit/powerbi/test_enrich_from_item_definitions.py +++ b/metadata-ingestion/tests/unit/powerbi/test_enrich_from_item_definitions.py @@ -723,7 +723,7 @@ def test_report_definition_fills_field_usage_that_resolves_against_scan_columns( reporter=api.reporter, dataplatform_instance_resolver=create_dataplatform_instance_resolver(config), ) - mcp = mapper._page_input_fields_mcp(page, report, "urn:li:chart:(powerbi,page)") + mcp = mapper._page_input_fields(page, report, "urn:li:chart:(powerbi,page)").mcp assert mcp is not None assert isinstance(mcp.aspect, InputFieldsClass) assert [f.schemaFieldUrn.rsplit(",", 1)[1] for f in mcp.aspect.fields] == [ diff --git a/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py b/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py index 45318cc2635ca..6ce7ca1822b51 100644 --- a/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py +++ b/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py @@ -4,6 +4,7 @@ from typing import Any, Dict, List, Optional, Tuple from unittest.mock import MagicMock, patch +from datahub.emitter.mcp import MetadataChangeProposalWrapper from datahub.ingestion.source.common.subtypes import BIAssetSubTypes from datahub.ingestion.source.powerbi.config import ( Constant, @@ -22,6 +23,7 @@ from datahub.ingestion.source.powerbi.rest_api_wrapper.data_classes import ( FABRIC_ARTIFACT_LAKEHOUSE, Column, + Dashboard, DatasetRefresh, DatasetRefreshSchedule, DaxFieldReference, @@ -40,6 +42,7 @@ ReportType, RlsTableFilter, Table, + Tile, Visual, Workspace, ) @@ -55,6 +58,7 @@ OperationClass, OperationTypeClass, SchemaMetadataClass, + StatusClass, StringTypeClass, UpstreamLineageClass, ) @@ -970,9 +974,9 @@ def test_page_input_fields_resolve_against_dataset_schema() -> None: users=[], tags=[], ) - mcp = mapper._page_input_fields_mcp( + mcp = mapper._page_input_fields( page, report, "urn:li:chart:(powerbi,pages.r1.p1)" - ) + ).mcp assert mcp is not None assert isinstance(mcp.aspect, InputFieldsClass) policies_urn = _urn(mapper, policies) @@ -2112,3 +2116,183 @@ def test_visuals_are_not_emitted_when_flag_is_off() -> None: mapper, _, _, chart_mcps = _visual_charts(extract_report_visuals=False) assert {mcp.entityUrn for mcp in chart_mcps} == {PAGE_URN} assert mapper._Mapper__reporter.report_visuals_emitted == 0 # type: ignore[attr-defined] + + +def _three_table_report(with_field_references: bool = True) -> Report: + """A report over three tables whose single page reads only the first + two; without field references it is what the API gives when + `extract_report_field_usage` is off.""" + policies = Table( + name="Policies", full_name="Model.Policies", columns=[_column("State")] + ) + claims = Table(name="Claims", full_name="Model.Claims", columns=[_column("Status")]) + unused = Table(name="Unused", full_name="Model.Unused", columns=[_column("X")]) + report = _report_with_visuals( + _dataset([policies, claims, unused]), with_visuals=False + ) + if not with_field_references: + report.pages[0].field_references = [] + return report + + +def _model_mcps(mapper: Mapper, report: Report) -> List[MetadataChangeProposalWrapper]: + assert report.dataset is not None + return [ + MetadataChangeProposalWrapper( + entityUrn=_urn(mapper, table), aspect=StatusClass(removed=False) + ) + for table in report.dataset.tables + ] + + +def _page_chart_info( + mapper: Mapper, report: Report +) -> Tuple[ChartInfoClass, PowerBiDashboardSourceReport]: + workspace = _workspace() + mapper.workspace_key = mapper.make_container_key_for_workspace(workspace) + chart_mcps = mapper.pages_to_chart( + report.pages, + workspace=workspace, + ds_mcps=_model_mcps(mapper, report), + report=report, + ) + return _aspects_of(chart_mcps, PAGE_URN)["ChartInfoClass"], _reporter(mapper) + + +def test_page_inputs_are_the_tables_its_fields_read_with_field_usage() -> None: + mapper = _mapper(_config(extract_report_field_usage=True, platform_instance="prod")) + report = _three_table_report() + info, reporter = _page_chart_info(mapper, report) + assert report.dataset is not None + policies, claims, _ = report.dataset.tables + assert info.inputs == [_urn(mapper, policies), _urn(mapper, claims)] + assert info.chartUrl == "https://app.powerbi.com/groups/ws-1/reports/r1/p1" + assert reporter.report_field_references_resolved == 2 + assert reporter.report_field_references_unresolved == 0 + + +def test_page_inputs_stay_the_whole_model_without_field_usage() -> None: + mapper = _mapper(_config(platform_instance="prod")) + report = _three_table_report(with_field_references=False) + info, reporter = _page_chart_info(mapper, report) + assert report.dataset is not None + assert info.inputs == [_urn(mapper, t) for t in report.dataset.tables] + # The page URL does not depend on field usage. + assert info.chartUrl == "https://app.powerbi.com/groups/ws-1/reports/r1/p1" + assert reporter.report_field_references_resolved == 0 + + +def test_page_inputs_stay_the_whole_model_when_nothing_resolves() -> None: + mapper = _mapper(_config(extract_report_field_usage=True, platform_instance="prod")) + report = _three_table_report() + report.pages[0].field_references = [PageFieldReference("Other", "Gone", "column")] + info, reporter = _page_chart_info(mapper, report) + assert report.dataset is not None + assert info.inputs == [_urn(mapper, t) for t in report.dataset.tables] + assert reporter.report_field_references_unresolved == 1 + + +def _tile( + tile_id: str, + dataset: Optional[PowerBIDataset], + report: Optional[Report], + title: Optional[str], +) -> Tile: + """A tile pinned from `report`, or straight from `dataset` when there + is no report.""" + return Tile( + id=tile_id, + title=title, + embedUrl=None, + dataset_id=dataset.id if dataset is not None else None, + report_id=report.id if report is not None else None, + createdFrom=( + Tile.CreatedFrom.REPORT if report is not None else Tile.CreatedFrom.DATASET + ), + dataset=dataset, + report=report, + ) + + +def _tile_chart_infos(mapper: Mapper, tiles: List[Tile]) -> Dict[str, ChartInfoClass]: + workspace = _workspace() + mapper.workspace_key = mapper.make_container_key_for_workspace(workspace) + dashboard = Dashboard( + id="d1", + displayName="Board", + description="", + embedUrl=None, + isReadOnly=False, + workspace_id=workspace.id, + workspace_name=workspace.name, + tiles=tiles, + users=[], + tags=[], + webUrl=None, + ) + _, chart_mcps = mapper.to_datahub_chart(tiles, workspace, dashboard) + infos: Dict[str, ChartInfoClass] = {} + for mcp in chart_mcps: + if isinstance(mcp.aspect, ChartInfoClass): + assert mcp.entityUrn is not None + infos[mcp.entityUrn] = mcp.aspect + return infos + + +def test_report_tile_inputs_are_the_tables_the_report_pages_read() -> None: + mapper = _mapper(_config(extract_report_field_usage=True, platform_instance="prod")) + report = _three_table_report() + assert report.dataset is not None + policies, claims, _ = report.dataset.tables + whole_model = [_urn(mapper, t) for t in report.dataset.tables] + infos = _tile_chart_infos( + mapper, + [ + _tile("t1", report.dataset, report, "From report"), + _tile("t2", report.dataset, report, "Also from report"), + _tile("t3", report.dataset, None, "Pinned from the model"), + ], + ) + narrowed = [_urn(mapper, policies), _urn(mapper, claims)] + assert infos["urn:li:chart:(powerbi,prod.charts.t1)"].inputs == narrowed + assert infos["urn:li:chart:(powerbi,prod.charts.t2)"].inputs == narrowed + # A tile pinned straight from the model has no report pages to narrow by. + assert infos["urn:li:chart:(powerbi,prod.charts.t3)"].inputs == whole_model + # Tiles never feed the page counters; the page pass does that once. + reporter = _reporter(mapper) + assert reporter.report_field_references_resolved == 0 + assert reporter.report_field_references_unresolved == 0 + # Resolved once per report, then served from the memo. + with patch.object( + mapper, "_resolve_input_fields", wraps=mapper._resolve_input_fields + ) as resolve: + assert mapper._report_used_dataset_urns(report) == narrowed + resolve.assert_not_called() + + +def test_report_tile_inputs_stay_the_whole_model_without_field_usage() -> None: + mapper = _mapper(_config(platform_instance="prod")) + report = _three_table_report(with_field_references=False) + assert report.dataset is not None + infos = _tile_chart_infos( + mapper, [_tile("t1", report.dataset, report, "From report")] + ) + assert infos["urn:li:chart:(powerbi,prod.charts.t1)"].inputs == [ + _urn(mapper, t) for t in report.dataset.tables + ] + + +def test_untitled_tile_is_named_by_its_position_on_the_dashboard() -> None: + mapper = _mapper(_config(platform_instance="prod")) + report = _three_table_report(with_field_references=False) + infos = _tile_chart_infos( + mapper, + [ + _tile("t1", report.dataset, report, "Titled"), + _tile("t2", report.dataset, None, None), + ], + ) + assert infos["urn:li:chart:(powerbi,prod.charts.t1)"].title == "Titled" + untitled = infos["urn:li:chart:(powerbi,prod.charts.t2)"] + assert untitled.title == "Tile 2" + assert untitled.description == "Tile 2" From a3fa782736fb751ee1dadf4490aa915c825ced0a Mon Sep 17 00:00:00 2001 From: Brock Griffey <52086127+brock-acryl@users.noreply.github.com> Date: Mon, 2 Nov 2026 11:42:59 -0500 Subject: [PATCH 2/7] fix(ingest/powerbi): keep table inputs when only a chart field fails to match A page or tile reference whose table exists but whose field is missing from the fetched schema (a renamed column) still proves the chart reads that table, so the table-level input is kept and only the field is counted as unresolved. Also makes the tile position keyword-only and separates the flag-gated input narrowing from the unconditional page URL and untitled-tile fallback in the docs. Co-Authored-By: Claude Fable 5.1 --- .../docs/sources/powerbi/powerbi_pre.md | 2 +- .../ingestion/source/powerbi/powerbi.py | 12 ++++++++---- .../unit/powerbi/test_workspace_apis_mapper.py | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md index 005238243466e..b684b154543b5 100644 --- a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md +++ b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md @@ -92,7 +92,7 @@ If the principal only has the `Viewer` role on a workspace, the dataset listing No Microsoft Entra application permissions need to change: both API families are authorized through the tenant settings and workspace roles above. The application requests a second token audience (`https://api.fabric.microsoft.com/.default`) in addition to the Power BI one. -What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report (not a paginated report, which never gets field usage or filters) whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. When field usage is extracted, a page chart and a tile pinned from a report list as inputs only the model tables their fields read (a page whose fields resolve to no table keeps the whole model); each page chart also links to its URL in the Power BI service, and a tile without a title is named `Tile ` after its 1-based position on the dashboard. +What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report (not a paginated report, which never gets field usage or filters) whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. When field usage is extracted, a page chart and a tile pinned from a report list as inputs only the model tables their fields read: a table counts as read when a field reference names it, even if that field is missing from the fetched schema, and a page (or a report whose pages) that resolves to no table keeps the whole model. Independently of that flag, each page chart links to its URL in the Power BI service, and a tile without a title is named `Tile ` after its 1-based position on the dashboard. **Fabric Lakehouse and Warehouse lineage.** The connector lists each workspace's Fabric items and registers the SQL analytics endpoint of every Lakehouse (one `GET lakehouses/{id}` call per lakehouse) and Warehouse (a warehouse is its own endpoint). A semantic-model table that reads one of them, either in DirectLake mode or through an Import/DirectQuery `Sql.Database(".datawarehouse.fabric.microsoft.com", ...)` query (a table navigation or a native `[Query=...]`), gets upstream lineage to the OneLake table (`fabric-onelake` platform, the same URN the OneLake connector emits) instead of a generic `mssql` one. The `Sql.Database` mapping applies in both metadata modes, since the admin scan also lists the workspace's Lakehouses and Warehouses. Map the workspace id in `server_to_platform_instance` to set the OneLake `platform_instance` and `env`. These OneLake edges are not subject to `dataset_type_mapping`, same as DirectLake lineage, so narrowing that mapping never turns such an edge into none; Dataflow Gen2 entities get the same mapping. The URNs match the OneLake connector's when that source runs with `convert_urns_to_lowercase: true` or this one with `convert_lineage_urns_to_lowercase: false` (by default Power BI lowercases the whole lineage URN while the OneLake connector keeps schema and table casing). A `Sql.Database` query may name the endpoint by id or by the item's display name. In `workspace_apis` mode a display name only matches on the workspace's own endpoint host; the admin scan reports no host, so there a display name matches the workspace's item on any host. A query naming an endpoint that is not among the workspace's items (for example a lakehouse in a workspace outside your workspace patterns) keeps its generic `mssql` edge and is reported as a `Fabric Endpoint Not Resolved` warning, and a display name shared by several items is reported as `Fabric Endpoint Name Ambiguous`. A `Sql.Databases` navigation, a navigation without an `Item`, or an endpoint behind a dataset parameter the connector could not resolve (the server argument is a parameter missing from the dataset) is not mapped: the first two are reported as `Fabric Endpoint M Shape Unsupported`, the last falls through to the generic SQL Server handling. Datamarts, mirrored databases and SQL databases are not covered: the OneLake connector does not ingest their tables, so no edge is emitted for them. diff --git a/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py b/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py index 1b98f88634b82..78908731fab89 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py +++ b/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py @@ -2269,7 +2269,8 @@ def to_datahub_chart_mcp( ds_mcps: List[MetadataChangeProposalWrapper], workspace: powerbi_data_classes.Workspace, dashboard: powerbi_data_classes.Dashboard, - position: int = 1, + *, + position: int, ) -> List[MetadataChangeProposalWrapper]: """ Map PowerBi tile to datahub chart. `position` is the tile's 1-based @@ -2921,6 +2922,12 @@ def _resolve_input_fields( report.dataset.id, ) continue + # The table-level edge is justified by the table match alone: a + # reference whose field is missing from the schema (renamed + # column, hierarchy level) still proves the chart reads the table. + table_urn = self.make_dataset_urn_for_table(table) + if table_urn not in result.dataset_urns: + result.dataset_urns.append(table_urn) model_fields: List[ Union[powerbi_data_classes.Column, powerbi_data_classes.Measure] ] = [*(table.columns or []), *(table.measures or [])] @@ -2941,9 +2948,6 @@ def _resolve_input_fields( context, ) continue - table_urn = self.make_dataset_urn_for_table(table) - if table_urn not in result.dataset_urns: - result.dataset_urns.append(table_urn) field_urn = builder.make_schema_field_urn(table_urn, schema_field.name) fields.append( InputFieldClass( diff --git a/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py b/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py index 6ce7ca1822b51..2af7a3969ad67 100644 --- a/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py +++ b/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py @@ -2192,6 +2192,24 @@ def test_page_inputs_stay_the_whole_model_when_nothing_resolves() -> None: assert reporter.report_field_references_unresolved == 1 +def test_page_inputs_keep_a_table_whose_field_is_missing_from_the_schema() -> None: + """A renamed column proves the page reads the table even though the + field itself cannot be matched: the table-level edge stays, the field + is counted as unresolved and gets no inputField.""" + mapper = _mapper(_config(extract_report_field_usage=True, platform_instance="prod")) + report = _three_table_report() + report.pages[0].field_references = [ + PageFieldReference("Policies", "State", "column"), + PageFieldReference("Claims", "Renamed", "column"), + ] + info, reporter = _page_chart_info(mapper, report) + assert report.dataset is not None + policies, claims, _ = report.dataset.tables + assert info.inputs == [_urn(mapper, policies), _urn(mapper, claims)] + assert reporter.report_field_references_resolved == 1 + assert reporter.report_field_references_unresolved == 1 + + def _tile( tile_id: str, dataset: Optional[PowerBIDataset], From 7ae38e0256025807db90aa2379c4a29bd9adf551 Mon Sep 17 00:00:00 2001 From: Brock Griffey <52086127+brock-acryl@users.noreply.github.com> Date: Mon, 2 Nov 2026 12:20:21 -0500 Subject: [PATCH 3/7] fix(ingest/powerbi): only narrow chart inputs to emitted tables and report fallbacks A page chart or report-backed tile only narrows its inputs when the model was actually emitted, so a dataset dropped by filter_dataset_endorsements can no longer leave charts pointing at tables no MCP creates; a visual of such a page has no inputs either. Page and tile narrowing now reads as "narrowed or whole model" without the redundant flag checks, page field resolution is shared through _resolve_page_fields, and pages that fall back to the whole model are counted and surfaced as a warning. The unresolved counters are split between unknown tables and missing fields of known tables. Co-Authored-By: Claude Fable 5.1 --- .../docs/sources/powerbi/powerbi_pre.md | 2 +- .../ingestion/source/powerbi/config.py | 17 ++- .../ingestion/source/powerbi/powerbi.py | 124 +++++++++++------- ...olden_test_workspace_apis_field_usage.json | 23 ++-- .../golden_test_workspace_apis_ingest.json | 23 ++-- .../powerbi/test_workspace_apis_mode.py | 47 ++++++- .../test_enrich_from_item_definitions.py | 2 +- .../powerbi/test_workspace_apis_mapper.py | 115 +++++++++++++--- 8 files changed, 265 insertions(+), 88 deletions(-) diff --git a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md index b684b154543b5..273e831e0671b 100644 --- a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md +++ b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md @@ -92,7 +92,7 @@ If the principal only has the `Viewer` role on a workspace, the dataset listing No Microsoft Entra application permissions need to change: both API families are authorized through the tenant settings and workspace roles above. The application requests a second token audience (`https://api.fabric.microsoft.com/.default`) in addition to the Power BI one. -What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report (not a paginated report, which never gets field usage or filters) whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. When field usage is extracted, a page chart and a tile pinned from a report list as inputs only the model tables their fields read: a table counts as read when a field reference names it, even if that field is missing from the fetched schema, and a page (or a report whose pages) that resolves to no table keeps the whole model. Independently of that flag, each page chart links to its URL in the Power BI service, and a tile without a title is named `Tile ` after its 1-based position on the dashboard. +What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report (not a paginated report, which never gets field usage or filters) whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. When field usage is extracted, a page chart and a tile pinned from a report list as inputs only the model tables their fields read: a table counts as read when a field reference names it, even if that field is missing from the fetched schema, and a page (or a report whose pages) that resolves to no table keeps the whole model (counted as `report_pages_inputs_fallback` and surfaced as a `Page Inputs Fell Back To Whole Model` warning), and a visual chart in that state has no table inputs. Independently of that flag, each page chart links to its URL in the Power BI service, and a tile without a title is named `Tile ` after its 1-based order in the dashboard's tile list. **Fabric Lakehouse and Warehouse lineage.** The connector lists each workspace's Fabric items and registers the SQL analytics endpoint of every Lakehouse (one `GET lakehouses/{id}` call per lakehouse) and Warehouse (a warehouse is its own endpoint). A semantic-model table that reads one of them, either in DirectLake mode or through an Import/DirectQuery `Sql.Database(".datawarehouse.fabric.microsoft.com", ...)` query (a table navigation or a native `[Query=...]`), gets upstream lineage to the OneLake table (`fabric-onelake` platform, the same URN the OneLake connector emits) instead of a generic `mssql` one. The `Sql.Database` mapping applies in both metadata modes, since the admin scan also lists the workspace's Lakehouses and Warehouses. Map the workspace id in `server_to_platform_instance` to set the OneLake `platform_instance` and `env`. These OneLake edges are not subject to `dataset_type_mapping`, same as DirectLake lineage, so narrowing that mapping never turns such an edge into none; Dataflow Gen2 entities get the same mapping. The URNs match the OneLake connector's when that source runs with `convert_urns_to_lowercase: true` or this one with `convert_lineage_urns_to_lowercase: false` (by default Power BI lowercases the whole lineage URN while the OneLake connector keeps schema and table casing). A `Sql.Database` query may name the endpoint by id or by the item's display name. In `workspace_apis` mode a display name only matches on the workspace's own endpoint host; the admin scan reports no host, so there a display name matches the workspace's item on any host. A query naming an endpoint that is not among the workspace's items (for example a lakehouse in a workspace outside your workspace patterns) keeps its generic `mssql` edge and is reported as a `Fabric Endpoint Not Resolved` warning, and a display name shared by several items is reported as `Fabric Endpoint Name Ambiguous`. A `Sql.Databases` navigation, a navigation without an `Item`, or an endpoint behind a dataset parameter the connector could not resolve (the server argument is a parameter missing from the dataset) is not mapped: the first two are reported as `Fabric Endpoint M Shape Unsupported`, the last falls through to the generic SQL Server handling. Datamarts, mirrored databases and SQL databases are not covered: the OneLake connector does not ingest their tables, so no edge is emitted for them. diff --git a/metadata-ingestion/src/datahub/ingestion/source/powerbi/config.py b/metadata-ingestion/src/datahub/ingestion/source/powerbi/config.py index 90ade3093d1d4..b77e0e34da4ed 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/powerbi/config.py +++ b/metadata-ingestion/src/datahub/ingestion/source/powerbi/config.py @@ -281,8 +281,12 @@ class Constant: PAGE_NAME = "pageName" VISUAL = "Visual" VISUAL_TITLE_FALLBACK = "{visual_type} on {page}" - # An untitled tile is named by its 1-based position on the dashboard. + # An untitled tile is named by its 1-based order in the dashboard's tile + # list. The scan-fallback tile listing can renumber untitled tiles + # between runs, so this name is not stable across them. TILE_TITLE_FALLBACK = "Tile {position}" + PAGE_CONTEXT = "page {page}" + PAGE_INPUTS_FELL_BACK = "Page Inputs Fell Back To Whole Model" URL_QUERY_SEPARATOR = "?" TOP = "$top" # Scan-API column types reproduced for TMDL-sourced columns @@ -488,7 +492,13 @@ class PowerBiDashboardSourceReport(StaleEntityRemovalSourceReport): report_filters_truncated: int = 0 report_pages_unmatched: int = 0 report_field_references_resolved: int = 0 + # Page references naming a table the model lacks vs. naming a known + # table whose field is missing from its schema. report_field_references_unresolved: int = 0 + report_field_references_field_unresolved: int = 0 + # Pages with field references that named no table of the model, so + # their inputs stayed the whole model. + report_pages_inputs_fallback: int = 0 report_visuals_emitted: int = 0 # Visual charts emitted without inputFields: the visual reads no fields at # all (a text box, say) vs. it reads fields but none resolved. @@ -496,6 +506,7 @@ class PowerBiDashboardSourceReport(StaleEntityRemovalSourceReport): report_visuals_fields_unresolved: int = 0 report_visual_field_references_resolved: int = 0 report_visual_field_references_unresolved: int = 0 + report_visual_field_references_field_unresolved: int = 0 report_visual_groups_skipped: int = 0 report_visuals_skipped_unnamed: int = 0 report_visuals_duplicate_name: int = 0 @@ -1205,6 +1216,10 @@ class PowerBiDashboardSourceConfig( "literal values it compares against, which may be business data. " "Page charts and tiles pinned from the report then list only the model " "tables their fields read as inputs, instead of every table of the model. " + "A table counts as read when a field reference names it, even if that " + "field is missing from the fetched schema; a page or tile whose references " + "match no table keeps the whole model, and a visual in that state has no " + "table inputs. " "Adds one Fabric getDefinition call per report. " "Requires `extract_reports`, `extract_dataset_schema` and either " "`metadata_api_mode: workspace_apis` or `enrich_from_item_definitions`.", diff --git a/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py b/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py index 78908731fab89..69b3f841cde11 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py +++ b/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py @@ -454,9 +454,14 @@ class ResolvedInputFields: mcp: Optional[MetadataChangeProposalWrapper] = None resolved: int = 0 + # References naming a table the model does not have. unresolved: int = 0 - # Datasets the resolved fields belong to, in first-seen order; a visual's - # table-level inputs are exactly these, never the whole model. + # References naming a known table whose field is missing from its schema. + field_unresolved: int = 0 + # Tables a reference named and that exist in the model, first-seen order. + # A table counts even when its field was not found, so this can be + # non-empty while `mcp` is None. Visuals use it as-is; pages and tiles + # fall back to the whole model when it is empty. dataset_urns: List[str] = field(default_factory=list) @@ -2263,6 +2268,21 @@ def transform_tags(tags: List[str]) -> GlobalTagsClass: ] ) + def _tile_inputs( + self, tile: powerbi_data_classes.Tile, ds_input: List[str] + ) -> List[str]: + """The tile's table inputs: a tile pinned from a report shows one of + its visuals, so when the report's pages name the tables they read, + those narrow `ds_input` (the emitted model). An empty `ds_input` means + the model was not emitted (filtered out), so nothing is narrowed.""" + if tile.report is not None and ds_input: + return self._report_used_dataset_urns(tile.report) or ds_input + return ds_input + + @staticmethod + def _tile_title(tile: powerbi_data_classes.Tile, position: int) -> str: + return tile.title or Constant.TILE_TITLE_FALLBACK.format(position=position) + def to_datahub_chart_mcp( self, tile: powerbi_data_classes.Tile, @@ -2274,7 +2294,8 @@ def to_datahub_chart_mcp( ) -> List[MetadataChangeProposalWrapper]: """ Map PowerBi tile to datahub chart. `position` is the tile's 1-based - place on the dashboard, which names a tile that has no title. + order in the dashboard's tile list, which names a tile that has no + title. """ logger.info( f"Converting tile {tile.title or '(untitled)'}(id={tile.id}) to chart" @@ -2288,15 +2309,11 @@ def to_datahub_chart_mcp( logger.info(f"{Constant.CHART_URN}={chart_urn}") - ds_input: List[str] = self.to_urn_set( - [x for x in ds_mcps if x.entityType == Constant.DATASET] + ds_input = self._tile_inputs( + tile, + self.to_urn_set([x for x in ds_mcps if x.entityType == Constant.DATASET]), ) - # A tile pinned from a report shows one of its visuals, so when the - # report's definition told us which tables its pages read, those are - # the tile's inputs rather than every table of the model. - if tile.report is not None: - ds_input = self._report_used_dataset_urns(tile.report) or ds_input - title = tile.title or Constant.TILE_TITLE_FALLBACK.format(position=position) + title = self._tile_title(tile, position) def tile_custom_properties(tile: powerbi_data_classes.Tile) -> dict: custom_properties: dict = { @@ -2850,21 +2867,37 @@ def _filter_properties( self.__reporter.report_filters_truncated += len(filters) - len(kept) return properties + def _resolve_page_fields( + self, page: powerbi_data_classes.Page, report: powerbi_data_classes.Report + ) -> ResolvedInputFields: + """The page's field references matched against the report's model, + counter-free; the inputFields MCP targets the page chart.""" + return self._resolve_input_fields( + page.field_references, + report, + self.make_chart_urn_for_page(page), + Constant.PAGE_CONTEXT.format(page=page.name), + ) + def _page_input_fields( - self, - page: powerbi_data_classes.Page, - report: powerbi_data_classes.Report, - chart_urn: str, + self, page: powerbi_data_classes.Page, report: powerbi_data_classes.Report ) -> ResolvedInputFields: """Model columns and measures the page's visuals read, as inputFields pointing at the semantic-model tables' schema fields, plus the tables they belong to. This page pass is the only place feeding the page counters.""" - resolved = self._resolve_input_fields( - page.field_references, report, chart_urn, f"page {page.name}" - ) - self.__reporter.report_field_references_resolved += resolved.resolved - self.__reporter.report_field_references_unresolved += resolved.unresolved + resolved = self._resolve_page_fields(page, report) + reporter = self.__reporter + reporter.report_field_references_resolved += resolved.resolved + reporter.report_field_references_unresolved += resolved.unresolved + reporter.report_field_references_field_unresolved += resolved.field_unresolved + if page.field_references and not resolved.dataset_urns: + reporter.report_pages_inputs_fallback += 1 + reporter.warning( + title=Constant.PAGE_INPUTS_FELL_BACK, + message="None of the page's field references names a table of the fetched model (the model is unresolved or every referenced table is missing), so the page keeps every table of the model as its inputs.", + context=f"report={report.name}, page={page.name}", + ) return resolved def _report_used_dataset_urns( @@ -2876,21 +2909,14 @@ def _report_used_dataset_urns( already counts these references, and every tile of the report asks.""" cached = self.__report_used_dataset_urns.get(report.id) if cached is not None: - return cached + return list(cached) dataset_urns: List[str] = [] - if self.__config.extract_report_field_usage: - for page in report.pages: - resolved = self._resolve_input_fields( - page.field_references, - report, - self.make_chart_urn_for_page(page), - f"page {page.name}", - ) - for dataset_urn in resolved.dataset_urns: - if dataset_urn not in dataset_urns: - dataset_urns.append(dataset_urn) + for page in report.pages: + for dataset_urn in self._resolve_page_fields(page, report).dataset_urns: + if dataset_urn not in dataset_urns: + dataset_urns.append(dataset_urn) self.__report_used_dataset_urns[report.id] = dataset_urns - return dataset_urns + return list(dataset_urns) def _resolve_input_fields( self, @@ -2940,7 +2966,7 @@ def _resolve_input_fields( None, ) if schema_field is None: - result.unresolved += 1 + result.field_unresolved += 1 logger.debug( "Visual field %s[%s] on %s not found in table schema", reference.table, @@ -3048,12 +3074,16 @@ def visual_to_chart_mcps( page: powerbi_data_classes.Page, report: powerbi_data_classes.Report, workspace: powerbi_data_classes.Workspace, + ds_input: List[str], ) -> List[MetadataChangeProposalWrapper]: """One visual of a report page as a Chart entity carrying exactly the fields that visual reads and its visual-level filters. Its table-level - inputs are the tables those fields belong to; a visual that reads no - resolvable field gets no table inputs rather than the page's whole - model, so a text box never claims lineage from every table.""" + inputs are the tables its references name (a table counts even when + the field is missing from the schema); a visual whose references + match no table gets no table inputs rather than the page's whole + model, so a text box never claims lineage from every table. An empty + `ds_input` means the page's model was not emitted, and then the + visual gets no inputs either.""" chart_urn = builder.make_chart_urn( platform=self.__config.platform_name, platform_instance=self.__config.platform_instance, @@ -3077,13 +3107,16 @@ def visual_to_chart_mcps( lastModified=ChangeAuditStamps(), chartUrl=self._page_url(report, page), type=VISUAL_TYPE_TO_CHART_TYPE.get(visual.visual_type or ""), - inputs=resolved.dataset_urns, + inputs=list(resolved.dataset_urns) if ds_input else [], customProperties=self._visual_properties(visual, page), ), ) reporter = self.__reporter reporter.report_visual_field_references_resolved += resolved.resolved reporter.report_visual_field_references_unresolved += resolved.unresolved + reporter.report_visual_field_references_field_unresolved += ( + resolved.field_unresolved + ) reporter.report_visuals_emitted += 1 if not visual.field_references: reporter.report_visuals_without_fields += 1 @@ -3142,12 +3175,13 @@ def to_chart_mcps( custom_properties[Constant.VISUAL_TYPES] = ", ".join(page.visual_types) custom_properties.update(self._filter_properties(page.filters)) - resolved = self._page_input_fields(page, report, chart_urn) + resolved = self._page_input_fields(page, report) # When the report definition told us which tables the page's - # visuals read, those are the page's inputs; without field usage - # (or when nothing resolved) the whole model stays, as before. - if self.__config.extract_report_field_usage and resolved.dataset_urns: - ds_input = resolved.dataset_urns + # visuals read, those narrow the emitted model; when nothing + # resolved the whole model stays, and an empty `ds_input` means + # the model was not emitted at all, so there is nothing to narrow. + if ds_input and resolved.dataset_urns: + ds_input = list(resolved.dataset_urns) chart_info_instance = ChartInfoClass( title=page.displayName or "", @@ -3177,7 +3211,9 @@ def to_chart_mcps( if self.__config.extract_report_visuals: for visual in page.visuals: list_of_mcps.extend( - self.visual_to_chart_mcps(visual, page, report, workspace) + self.visual_to_chart_mcps( + visual, page, report, workspace, ds_input + ) ) return list_of_mcps diff --git a/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_field_usage.json b/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_field_usage.json index 50918df883c18..08ea46dfb8922 100644 --- a/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_field_usage.json +++ b/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_field_usage.json @@ -1231,8 +1231,10 @@ "createdFrom": "Report", "datasetId": "05169CD2-E713-41E6-9600-1D8066D95445", "datasetWebUrl": "https://app.powerbi.com/groups/64ED5CAD-7C10-4684-8180-826122881108/datasets/05169CD2-E713-41E6-9600-1D8066D95445/details", - "reportId": "5b218778-e7a5-4d73-8187-f10824047715" + "reportId": "584cf13a-1485-41c2-a514-b1bb66fff163", + "reportWebUrl": "https://app.powerbi.com/groups/64ED5CAD-7C10-4684-8180-826122881108/reports/584cf13a-1485-41c2-a514-b1bb66fff163" }, + "externalUrl": "https://app.powerbi.com/groups/64ED5CAD-7C10-4684-8180-826122881108/reports/584cf13a-1485-41c2-a514-b1bb66fff163", "title": "test_tile", "description": "test_tile", "lastModified": { @@ -1246,20 +1248,14 @@ } }, "inputs": [ - { - "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Claims_By_State,DEV)" - }, - { - "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Claims,DEV)" - }, - { - "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Dataflow_Policies,DEV)" - }, { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Insurance_KPIs,DEV)" }, { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Policies,DEV)" + }, + { + "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Claims,DEV)" } ] } @@ -1533,6 +1529,13 @@ "path": "/dashboardUrl", "value": "https://localhost/dashboards/web/1" }, + { + "op": "add", + "path": "/dashboards/urn:li:dashboard:(powerbi,reports.584cf13a-1485-41c2-a514-b1bb66fff163)", + "value": { + "destinationUrn": "urn:li:dashboard:(powerbi,reports.584cf13a-1485-41c2-a514-b1bb66fff163)" + } + }, { "op": "add", "path": "/lastModified", diff --git a/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_ingest.json b/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_ingest.json index 4a83fd647fd30..b4ddc72c1e62c 100644 --- a/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_ingest.json +++ b/metadata-ingestion/tests/integration/powerbi/golden_test_workspace_apis_ingest.json @@ -2080,8 +2080,10 @@ "createdFrom": "Report", "datasetId": "05169CD2-E713-41E6-9600-1D8066D95445", "datasetWebUrl": "https://app.powerbi.com/groups/64ED5CAD-7C10-4684-8180-826122881108/datasets/05169CD2-E713-41E6-9600-1D8066D95445/details", - "reportId": "5b218778-e7a5-4d73-8187-f10824047715" + "reportId": "584cf13a-1485-41c2-a514-b1bb66fff163", + "reportWebUrl": "https://app.powerbi.com/groups/64ED5CAD-7C10-4684-8180-826122881108/reports/584cf13a-1485-41c2-a514-b1bb66fff163" }, + "externalUrl": "https://app.powerbi.com/groups/64ED5CAD-7C10-4684-8180-826122881108/reports/584cf13a-1485-41c2-a514-b1bb66fff163", "title": "test_tile", "description": "test_tile", "lastModified": { @@ -2095,20 +2097,14 @@ } }, "inputs": [ - { - "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Claims_By_State,DEV)" - }, - { - "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Claims,DEV)" - }, - { - "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Dataflow_Policies,DEV)" - }, { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Insurance_KPIs,DEV)" }, { "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Policies,DEV)" + }, + { + "string": "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Claims,DEV)" } ] } @@ -2382,6 +2378,13 @@ "path": "/dashboardUrl", "value": "https://localhost/dashboards/web/1" }, + { + "op": "add", + "path": "/dashboards/urn:li:dashboard:(powerbi,reports.584cf13a-1485-41c2-a514-b1bb66fff163)", + "value": { + "destinationUrn": "urn:li:dashboard:(powerbi,reports.584cf13a-1485-41c2-a514-b1bb66fff163)" + } + }, { "op": "add", "path": "/lastModified", diff --git a/metadata-ingestion/tests/integration/powerbi/test_workspace_apis_mode.py b/metadata-ingestion/tests/integration/powerbi/test_workspace_apis_mode.py index 39c95146aadc8..decaf250c01a4 100644 --- a/metadata-ingestion/tests/integration/powerbi/test_workspace_apis_mode.py +++ b/metadata-ingestion/tests/integration/powerbi/test_workspace_apis_mode.py @@ -42,6 +42,9 @@ WAREHOUSE_ID = "9A8B7C6D-5E4F-4A3B-8C2D-1E0F9A8B7C6D" WAREHOUSE_MODEL_ID = "2B3C4D5E-6F7A-4B8C-9D0E-1F2A3B4C5D6E" REPORT_ID = "584cf13a-1485-41c2-a514-b1bb66fff163" +# The default mock dashboard of the first workspace; its first tile is +# re-pointed at the Loss Report so a report-backed tile exists in this mode. +DASHBOARD_ID = "7D668CAD-7FFC-4505-9215-655BCA5BEBAE" # Second workspace of the default group listing; it hosts a composite model # whose remote tables read the first workspace's Insurance Model. SECOND_WORKSPACE_ID = "64ED5CAD-7C22-4684-8180-826122881108" @@ -233,6 +236,27 @@ def workspace_apis_mock_data(fixtures: Path) -> Dict[str, Dict[str, Any]]: ] }, }, + f"{PBI}/groups/{WORKSPACE_ID}/dashboards/{DASHBOARD_ID}/tiles": { + "method": "GET", + "status_code": 200, + "json": { + "value": [ + { + "id": "B8E293DC-0C83-4AA0-9BB9-0A8738DF24A0", + "title": "test_tile", + "embedUrl": "https://localhost/tiles/embed/1", + "datasetId": IMPORT_MODEL_ID, + "reportId": REPORT_ID, + }, + { + "id": "23212598-23b5-4980-87cc-5fc0ecd84385", + "title": "yearly_sales", + "embedUrl": "https://localhost/tiles/embed/2", + "datasetId": "ba0130a1-5b03-40de-9535-b34e778ea6ed", + }, + ] + }, + }, f"{PBI}/groups/{WORKSPACE_ID}/reports/{REPORT_ID}/pages": { "method": "GET", "status_code": 200, @@ -595,13 +619,33 @@ def test_workspace_apis_ingest_with_enrichment( assert report.report_definitions_parsed == 1 # The page resolves six distinct fields (visuals, visual filters and the # report/page filter targets, deduplicated); the fixture's - # `NotInModel[Ghost]` does not. + # `NotInModel[Ghost]` names a table the model lacks. assert report.report_field_references_resolved == 6 assert report.report_field_references_unresolved == 1 + assert report.report_field_references_field_unresolved == 0 + assert report.report_pages_inputs_fallback == 0 # The visual charts resolve their own fields again (1 + 3 + 1 + 3) and # fail on `NotInModel[Ghost]` once more. assert report.report_visual_field_references_resolved == 8 assert report.report_visual_field_references_unresolved == 1 + assert report.report_visual_field_references_field_unresolved == 0 + # The tile pinned from the Loss Report lists only the tables its page + # reads and links to the report. + tile_info = next( + mcp["aspect"]["json"] + for mcp in mcps + if mcp.get("aspectName") == "chartInfo" + and mcp["entityUrn"] + == "urn:li:chart:(powerbi,charts.B8E293DC-0C83-4AA0-9BB9-0A8738DF24A0)" + ) + assert [i["string"] for i in tile_info["inputs"]] == [ + "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Insurance_KPIs,DEV)", + "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Policies,DEV)", + "urn:li:dataset:(urn:li:dataPlatform:powerbi,Insurance_Model.Claims,DEV)", + ] + assert tile_info["externalUrl"] == ( + f"https://app.powerbi.com/groups/{WORKSPACE_ID}/reports/{REPORT_ID}" + ) # The warehouse model's refresh listing is empty but still fetched. assert report.refresh_history_fetched == 4 # Only the fixture's `'Budget'[Amount]` points outside the model; it is @@ -711,6 +755,7 @@ def test_workspace_apis_field_usage_without_visuals( assert isinstance(report, PowerBiDashboardSourceReport) assert report.report_field_references_resolved == 6 assert report.report_field_references_unresolved == 1 + assert report.report_field_references_field_unresolved == 0 assert report.report_filters_parsed == 2 assert report.report_filters_failed == 0 diff --git a/metadata-ingestion/tests/unit/powerbi/test_enrich_from_item_definitions.py b/metadata-ingestion/tests/unit/powerbi/test_enrich_from_item_definitions.py index 900a1f976300f..ff94c16228bc5 100644 --- a/metadata-ingestion/tests/unit/powerbi/test_enrich_from_item_definitions.py +++ b/metadata-ingestion/tests/unit/powerbi/test_enrich_from_item_definitions.py @@ -723,7 +723,7 @@ def test_report_definition_fills_field_usage_that_resolves_against_scan_columns( reporter=api.reporter, dataplatform_instance_resolver=create_dataplatform_instance_resolver(config), ) - mcp = mapper._page_input_fields(page, report, "urn:li:chart:(powerbi,page)").mcp + mcp = mapper._page_input_fields(page, report).mcp assert mcp is not None assert isinstance(mcp.aspect, InputFieldsClass) assert [f.schemaFieldUrn.rsplit(",", 1)[1] for f in mcp.aspect.fields] == [ diff --git a/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py b/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py index 2af7a3969ad67..c94406ae0e0dd 100644 --- a/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py +++ b/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py @@ -4,6 +4,8 @@ from typing import Any, Dict, List, Optional, Tuple from unittest.mock import MagicMock, patch +import pytest + from datahub.emitter.mcp import MetadataChangeProposalWrapper from datahub.ingestion.source.common.subtypes import BIAssetSubTypes from datahub.ingestion.source.powerbi.config import ( @@ -974,9 +976,7 @@ def test_page_input_fields_resolve_against_dataset_schema() -> None: users=[], tags=[], ) - mcp = mapper._page_input_fields( - page, report, "urn:li:chart:(powerbi,pages.r1.p1)" - ).mcp + mcp = mapper._page_input_fields(page, report).mcp assert mcp is not None assert isinstance(mcp.aspect, InputFieldsClass) policies_urn = _urn(mapper, policies) @@ -988,7 +988,11 @@ def test_page_input_fields_resolve_against_dataset_schema() -> None: "State", "Total", ] - assert mapper._Mapper__reporter.report_field_references_unresolved == 2 # type: ignore[attr-defined] + reporter = mapper._Mapper__reporter # type: ignore[attr-defined] + # `Other` is not a table of the model; `Policies[Gone]` names a known + # table whose field is missing. + assert reporter.report_field_references_unresolved == 1 + assert reporter.report_field_references_field_unresolved == 1 def test_measure_references_match_model_names_case_insensitively() -> None: @@ -1915,6 +1919,12 @@ def _report_with_visuals(dataset: PowerBIDataset, with_visuals: bool = True) -> ), Visual(name="v-text", page_id="r1.p1", visual_type="textbox"), Visual(name="v-custom", page_id="r1.p1"), + Visual( + name="v-renamed", + page_id="r1.p1", + visual_type="card", + field_references=[PageFieldReference("Claims", "Renamed", "column")], + ), ] page = Page( id="r1.p1", @@ -1922,7 +1932,7 @@ def _report_with_visuals(dataset: PowerBIDataset, with_visuals: bool = True) -> name="p1", order=0, field_references=[state, status], - visual_count=4, + visual_count=5, visual_types=["card", "clusteredBarChart", "textbox"], visuals=visuals if with_visuals else [], ) @@ -1952,6 +1962,7 @@ def _aspects_of(mcps: List[Any], urn: str) -> Dict[str, Any]: CARD_URN = "urn:li:chart:(powerbi,prod.visuals.r1.p1.v-card)" TEXT_URN = "urn:li:chart:(powerbi,prod.visuals.r1.p1.v-text)" CUSTOM_URN = "urn:li:chart:(powerbi,prod.visuals.r1.p1.v-custom)" +RENAMED_URN = "urn:li:chart:(powerbi,prod.visuals.r1.p1.v-renamed)" def _visual_charts( @@ -1971,7 +1982,10 @@ def _visual_charts( claims = Table(name="Claims", full_name="Model.Claims", columns=[_column("Status")]) report = _report_with_visuals(_dataset([policies, claims])) chart_mcps = mapper.pages_to_chart( - report.pages, workspace=workspace, ds_mcps=[], report=report + report.pages, + workspace=workspace, + ds_mcps=_model_mcps(mapper, report), + report=report, ) return mapper, report, workspace, chart_mcps @@ -1984,10 +1998,11 @@ def test_visual_chart_urns_and_page_chart_are_emitted_together() -> None: CARD_URN, TEXT_URN, CUSTOM_URN, + RENAMED_URN, } # The page chart keeps its own shape. page_info = _aspects_of(chart_mcps, PAGE_URN)["ChartInfoClass"] - assert page_info.customProperties["visualCount"] == "4" + assert page_info.customProperties["visualCount"] == "5" assert "visualName" not in page_info.customProperties assert [ e.urn for e in _aspects_of(chart_mcps, PAGE_URN)["BrowsePathsV2Class"].path @@ -2072,16 +2087,23 @@ def test_visual_chart_input_fields_and_counters() -> None: assert _aspects_of(chart_mcps, TEXT_URN)["InputFieldsClass"].fields == [] assert _aspects_of(chart_mcps, CARD_URN)["ChartInfoClass"].inputs == [] assert _aspects_of(chart_mcps, TEXT_URN)["ChartInfoClass"].inputs == [] + # A field missing from a known table's schema still proves the visual + # reads that table: table input kept, inputFields empty. + renamed = _aspects_of(chart_mcps, RENAMED_URN) + assert renamed["InputFieldsClass"].fields == [] + assert renamed["ChartInfoClass"].inputs == [_urn(mapper, claims)] reporter = mapper._Mapper__reporter # type: ignore[attr-defined] - assert reporter.report_visuals_emitted == 4 + assert reporter.report_visuals_emitted == 5 assert reporter.report_visuals_without_fields == 2 - assert reporter.report_visuals_fields_unresolved == 1 + assert reporter.report_visuals_fields_unresolved == 2 assert reporter.report_visual_field_references_resolved == 2 assert reporter.report_visual_field_references_unresolved == 1 + assert reporter.report_visual_field_references_field_unresolved == 1 # The page pass keeps its own counters, no double counting. assert reporter.report_field_references_resolved == 2 assert reporter.report_field_references_unresolved == 0 + assert reporter.report_field_references_field_unresolved == 0 def test_visual_charts_are_listed_on_the_dashboard_and_dropped_when_flag_off() -> None: @@ -2107,6 +2129,7 @@ def dashboard_charts(extract_report_visuals: bool) -> List[str]: CARD_URN, TEXT_URN, CUSTOM_URN, + RENAMED_URN, ] # A later run with the flag off rewrites the (non-patched) chart list. assert dashboard_charts(False) == [PAGE_URN] @@ -2190,12 +2213,15 @@ def test_page_inputs_stay_the_whole_model_when_nothing_resolves() -> None: assert report.dataset is not None assert info.inputs == [_urn(mapper, t) for t in report.dataset.tables] assert reporter.report_field_references_unresolved == 1 + assert reporter.report_field_references_field_unresolved == 0 + assert reporter.report_pages_inputs_fallback == 1 + assert Constant.PAGE_INPUTS_FELL_BACK in [w.title for w in reporter.warnings] def test_page_inputs_keep_a_table_whose_field_is_missing_from_the_schema() -> None: """A renamed column proves the page reads the table even though the field itself cannot be matched: the table-level edge stays, the field - is counted as unresolved and gets no inputField.""" + is counted as field-unresolved and gets no inputField.""" mapper = _mapper(_config(extract_report_field_usage=True, platform_instance="prod")) report = _three_table_report() report.pages[0].field_references = [ @@ -2207,7 +2233,9 @@ def test_page_inputs_keep_a_table_whose_field_is_missing_from_the_schema() -> No policies, claims, _ = report.dataset.tables assert info.inputs == [_urn(mapper, policies), _urn(mapper, claims)] assert reporter.report_field_references_resolved == 1 - assert reporter.report_field_references_unresolved == 1 + assert reporter.report_field_references_unresolved == 0 + assert reporter.report_field_references_field_unresolved == 1 + assert reporter.report_pages_inputs_fallback == 0 def _tile( @@ -2280,17 +2308,29 @@ def test_report_tile_inputs_are_the_tables_the_report_pages_read() -> None: reporter = _reporter(mapper) assert reporter.report_field_references_resolved == 0 assert reporter.report_field_references_unresolved == 0 - # Resolved once per report, then served from the memo. - with patch.object( - mapper, "_resolve_input_fields", wraps=mapper._resolve_input_fields - ) as resolve: - assert mapper._report_used_dataset_urns(report) == narrowed - resolve.assert_not_called() + assert reporter.report_pages_inputs_fallback == 0 -def test_report_tile_inputs_stay_the_whole_model_without_field_usage() -> None: - mapper = _mapper(_config(platform_instance="prod")) +@pytest.mark.parametrize( + "extract_report_field_usage, field_references", + [ + (False, []), + (True, [PageFieldReference("Other", "Gone", "column")]), + ], +) +def test_report_tile_inputs_stay_the_whole_model_without_narrowing( + extract_report_field_usage: bool, field_references: List[PageFieldReference] +) -> None: + """Without field usage, or when no reference names a table of the + model, a report tile keeps every table of the model.""" + mapper = _mapper( + _config( + extract_report_field_usage=extract_report_field_usage, + platform_instance="prod", + ) + ) report = _three_table_report(with_field_references=False) + report.pages[0].field_references = field_references assert report.dataset is not None infos = _tile_chart_infos( mapper, [_tile("t1", report.dataset, report, "From report")] @@ -2300,7 +2340,7 @@ def test_report_tile_inputs_stay_the_whole_model_without_field_usage() -> None: ] -def test_untitled_tile_is_named_by_its_position_on_the_dashboard() -> None: +def test_untitled_tile_is_named_by_its_order_in_the_tile_list() -> None: mapper = _mapper(_config(platform_instance="prod")) report = _three_table_report(with_field_references=False) infos = _tile_chart_infos( @@ -2314,3 +2354,38 @@ def test_untitled_tile_is_named_by_its_position_on_the_dashboard() -> None: untitled = infos["urn:li:chart:(powerbi,prod.charts.t2)"] assert untitled.title == "Tile 2" assert untitled.description == "Tile 2" + + +def test_filtered_out_model_leaves_page_tile_and_visual_without_inputs() -> None: + """`filter_dataset_endorsements` emits nothing for an untagged model, so + no chart may name its tables: narrowing only applies to an emitted + model, and a visual gets no inputs either.""" + mapper = _mapper( + _config( + metadata_api_mode="admin_scan", + enrich_from_item_definitions=True, + extract_report_field_usage=True, + extract_report_visuals=True, + filter_dataset_endorsements={"allow": ["Certified"]}, + platform_instance="prod", + ) + ) + workspace = _workspace() + mapper.workspace_key = mapper.make_container_key_for_workspace(workspace) + policies = Table( + name="Policies", full_name="Model.Policies", columns=[_column("State")] + ) + claims = Table(name="Claims", full_name="Model.Claims", columns=[_column("Status")]) + report = _report_with_visuals(_dataset([policies, claims])) + assert report.dataset is not None + ds_mcps = mapper.to_datahub_dataset(report.dataset, workspace) + assert ds_mcps == [] + chart_mcps = mapper.pages_to_chart( + report.pages, workspace=workspace, ds_mcps=ds_mcps, report=report + ) + assert _aspects_of(chart_mcps, PAGE_URN)["ChartInfoClass"].inputs == [] + assert _aspects_of(chart_mcps, BAR_URN)["ChartInfoClass"].inputs == [] + tiles = _tile_chart_infos( + mapper, [_tile("t1", report.dataset, report, "From report")] + ) + assert tiles["urn:li:chart:(powerbi,prod.charts.t1)"].inputs == [] From 8025323246136c508480bb197018bb34fa5ccf9a Mon Sep 17 00:00:00 2001 From: Brock Griffey <52086127+brock-acryl@users.noreply.github.com> Date: Fri, 6 Nov 2026 13:15:34 -0500 Subject: [PATCH 4/7] docs(ingest/powerbi): record Tile names and page chart URLs in both modes Co-Authored-By: Claude Opus 5.5 --- docs/how/breaking-changes.md | 1 + metadata-ingestion/docs/sources/powerbi/powerbi_pre.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/how/breaking-changes.md b/docs/how/breaking-changes.md index 62141550f09e5..877724ed0c74f 100644 --- a/docs/how/breaking-changes.md +++ b/docs/how/breaking-changes.md @@ -88,6 +88,7 @@ Requirements: - [#20842](https://github.com/datahub-project/datahub/pull/20842) **(Ingestion / Power BI)** Column-level lineage now follows the same `dataset_type_mapping` filter as table-level lineage, in both `metadata_api_mode` settings. If you narrowed `dataset_type_mapping` to fewer platforms than the default, a Power BI column no longer gets a lineage edge to a column of an upstream table that the mapping excludes; before, the column edge was emitted even though the table edge was not. Duplicate column-level edges, which were emitted once per upstream table of a Power BI table, are also removed. **Action:** none unless you relied on column lineage to platforms you left out of `dataset_type_mapping`; add those platforms to the mapping to keep it. The dropped edges disappear on the next run. - [#20876](https://github.com/datahub-project/datahub/pull/20876) **(Ingestion / Power BI)** Column-level lineage no longer links a warehouse column to a Power BI _calculated column_ (a column defined by a DAX expression) of the same name, in both `admin_scan` and `workspace_apis` modes; such columns are computed inside the semantic model and the previous edge pointed at a column the warehouse never feeds. For semantic models read through `metadata_api_mode: workspace_apis`, column lineage now follows each column's TMDL `sourceColumn`, so a field renamed in the model points at its real upstream column instead of a same-named one. **Action:** none unless you relied on those edges; the dropped edges disappear on the next run with stateful ingestion. - [#20884](https://github.com/datahub-project/datahub/pull/20884) **(Ingestion / Power BI)** A semantic-model table (or Dataflow Gen2 entity) that reads a Microsoft Fabric Lakehouse or Warehouse through its SQL analytics endpoint (an M query calling `Sql.Database(".datawarehouse.fabric.microsoft.com", ...)`) now gets its upstream lineage edge on the OneLake table (`fabric-onelake` platform, the URN the OneLake connector emits) instead of a generic SQL Server (`mssql`) dataset. This applies in both `metadata_api_mode` settings, because the admin scan also lists the workspace's Lakehouses and Warehouses. The edge is rewritten in place on the next run; no entity is deleted, but the old `mssql` dataset the edge pointed at no longer receives lineage from Power BI. Endpoints that cannot be matched to a Lakehouse or Warehouse of the same workspace keep their `mssql` edge and are reported as warnings. The OneLake edge is kept even if you narrowed `dataset_type_mapping` to leave out SQL Server, the same as DirectLake lineage, so a table that had no upstream edge under such a mapping now gets one. **Action:** none, unless something relied on the `mssql` upstream of such tables; in that case map the workspace id in `server_to_platform_instance` and ingest the Fabric items with the OneLake connector so the new edge lands on an existing dataset. +- [#20885](https://github.com/datahub-project/datahub/pull/20885) **(Ingestion / Power BI)** In both `metadata_api_mode` settings, a dashboard tile without a title is now named `Tile `, after its 1-based position in the dashboard's tile list, instead of having an empty name, and each report page chart now carries a link to the page in the Power BI service. **Action:** none, unless you match charts by an empty title; the new names appear on the next run. Because a tile's number follows its position, reordering a dashboard's tiles can rename its untitled tiles; the chart URNs do not change. - [#21219](https://github.com/datahub-project/datahub/pull/21219) **(Ingestion / Qlik Sense)** On Qlik Sense Enterprise, QVD datasets are now placed in `Folder` containers that follow their file path (server or share, then each folder), and are browsed under those folders instead of the path split at its dots. Their URNs, schemas and lineage are unchanged. **Action:** update any bookmark or saved browse path that pointed at the old QVD hierarchy. diff --git a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md index 273e831e0671b..6690df52a0501 100644 --- a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md +++ b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md @@ -92,7 +92,7 @@ If the principal only has the `Viewer` role on a workspace, the dataset listing No Microsoft Entra application permissions need to change: both API families are authorized through the tenant settings and workspace roles above. The application requests a second token audience (`https://api.fabric.microsoft.com/.default`) in addition to the Power BI one. -What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report (not a paginated report, which never gets field usage or filters) whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. When field usage is extracted, a page chart and a tile pinned from a report list as inputs only the model tables their fields read: a table counts as read when a field reference names it, even if that field is missing from the fetched schema, and a page (or a report whose pages) that resolves to no table keeps the whole model (counted as `report_pages_inputs_fallback` and surfaced as a `Page Inputs Fell Back To Whole Model` warning), and a visual chart in that state has no table inputs. Independently of that flag, each page chart links to its URL in the Power BI service, and a tile without a title is named `Tile ` after its 1-based order in the dashboard's tile list. +What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report (not a paginated report, which never gets field usage or filters) whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. When field usage is extracted, a page chart and a tile pinned from a report list as inputs only the model tables their fields read: a table counts as read when a field reference names it, even if that field is missing from the fetched schema, and a page (or a report whose pages) that resolves to no table keeps the whole model (counted as `report_pages_inputs_fallback` and surfaced as a `Page Inputs Fell Back To Whole Model` warning), and a visual chart in that state has no table inputs. Independently of that flag and of `metadata_api_mode` (so in `admin_scan` too), each page chart links to its URL in the Power BI service, and a tile without a title is named `Tile ` after its 1-based order in the dashboard's tile list. **Fabric Lakehouse and Warehouse lineage.** The connector lists each workspace's Fabric items and registers the SQL analytics endpoint of every Lakehouse (one `GET lakehouses/{id}` call per lakehouse) and Warehouse (a warehouse is its own endpoint). A semantic-model table that reads one of them, either in DirectLake mode or through an Import/DirectQuery `Sql.Database(".datawarehouse.fabric.microsoft.com", ...)` query (a table navigation or a native `[Query=...]`), gets upstream lineage to the OneLake table (`fabric-onelake` platform, the same URN the OneLake connector emits) instead of a generic `mssql` one. The `Sql.Database` mapping applies in both metadata modes, since the admin scan also lists the workspace's Lakehouses and Warehouses. Map the workspace id in `server_to_platform_instance` to set the OneLake `platform_instance` and `env`. These OneLake edges are not subject to `dataset_type_mapping`, same as DirectLake lineage, so narrowing that mapping never turns such an edge into none; Dataflow Gen2 entities get the same mapping. The URNs match the OneLake connector's when that source runs with `convert_urns_to_lowercase: true` or this one with `convert_lineage_urns_to_lowercase: false` (by default Power BI lowercases the whole lineage URN while the OneLake connector keeps schema and table casing). A `Sql.Database` query may name the endpoint by id or by the item's display name. In `workspace_apis` mode a display name only matches on the workspace's own endpoint host; the admin scan reports no host, so there a display name matches the workspace's item on any host. A query naming an endpoint that is not among the workspace's items (for example a lakehouse in a workspace outside your workspace patterns) keeps its generic `mssql` edge and is reported as a `Fabric Endpoint Not Resolved` warning, and a display name shared by several items is reported as `Fabric Endpoint Name Ambiguous`. A `Sql.Databases` navigation, a navigation without an `Item`, or an endpoint behind a dataset parameter the connector could not resolve (the server argument is a parameter missing from the dataset) is not mapped: the first two are reported as `Fabric Endpoint M Shape Unsupported`, the last falls through to the generic SQL Server handling. Datamarts, mirrored databases and SQL databases are not covered: the OneLake connector does not ingest their tables, so no edge is emitted for them. From 9a116a57ef03bf9bde74260f542fa5275526a0c1 Mon Sep 17 00:00:00 2001 From: Brock Griffey <52086127+brock-acryl@users.noreply.github.com> Date: Fri, 4 Dec 2026 14:49:27 -0500 Subject: [PATCH 5/7] fix(ingest/powerbi): keep chart inputs to emitted tables and clear stale page fields - Tile inputs from a report's pages are intersected with the tile's emitted model, so narrowing never names a table this run did not emit. - A page whose field references match no schema field writes an empty InputFields so columns from an earlier run do not outlive the narrowed inputs. - The whole-model fallback is only counted and warned when the model was emitted. - Docs and the breaking-change entry describe the emitted-table rule, the silent fallback for unparsed definitions, input narrowing, and position-based tile names. Co-Authored-By: Claude Opus 5.5 --- docs/how/breaking-changes.md | 2 +- .../docs/sources/powerbi/powerbi_pre.md | 2 +- .../ingestion/source/powerbi/powerbi.py | 39 +++++++++++--- .../test_enrich_from_item_definitions.py | 2 +- .../powerbi/test_workspace_apis_mapper.py | 54 ++++++++++++++++++- 5 files changed, 88 insertions(+), 11 deletions(-) diff --git a/docs/how/breaking-changes.md b/docs/how/breaking-changes.md index 877724ed0c74f..5a46d5bd779ef 100644 --- a/docs/how/breaking-changes.md +++ b/docs/how/breaking-changes.md @@ -88,7 +88,7 @@ Requirements: - [#20842](https://github.com/datahub-project/datahub/pull/20842) **(Ingestion / Power BI)** Column-level lineage now follows the same `dataset_type_mapping` filter as table-level lineage, in both `metadata_api_mode` settings. If you narrowed `dataset_type_mapping` to fewer platforms than the default, a Power BI column no longer gets a lineage edge to a column of an upstream table that the mapping excludes; before, the column edge was emitted even though the table edge was not. Duplicate column-level edges, which were emitted once per upstream table of a Power BI table, are also removed. **Action:** none unless you relied on column lineage to platforms you left out of `dataset_type_mapping`; add those platforms to the mapping to keep it. The dropped edges disappear on the next run. - [#20876](https://github.com/datahub-project/datahub/pull/20876) **(Ingestion / Power BI)** Column-level lineage no longer links a warehouse column to a Power BI _calculated column_ (a column defined by a DAX expression) of the same name, in both `admin_scan` and `workspace_apis` modes; such columns are computed inside the semantic model and the previous edge pointed at a column the warehouse never feeds. For semantic models read through `metadata_api_mode: workspace_apis`, column lineage now follows each column's TMDL `sourceColumn`, so a field renamed in the model points at its real upstream column instead of a same-named one. **Action:** none unless you relied on those edges; the dropped edges disappear on the next run with stateful ingestion. - [#20884](https://github.com/datahub-project/datahub/pull/20884) **(Ingestion / Power BI)** A semantic-model table (or Dataflow Gen2 entity) that reads a Microsoft Fabric Lakehouse or Warehouse through its SQL analytics endpoint (an M query calling `Sql.Database(".datawarehouse.fabric.microsoft.com", ...)`) now gets its upstream lineage edge on the OneLake table (`fabric-onelake` platform, the URN the OneLake connector emits) instead of a generic SQL Server (`mssql`) dataset. This applies in both `metadata_api_mode` settings, because the admin scan also lists the workspace's Lakehouses and Warehouses. The edge is rewritten in place on the next run; no entity is deleted, but the old `mssql` dataset the edge pointed at no longer receives lineage from Power BI. Endpoints that cannot be matched to a Lakehouse or Warehouse of the same workspace keep their `mssql` edge and are reported as warnings. The OneLake edge is kept even if you narrowed `dataset_type_mapping` to leave out SQL Server, the same as DirectLake lineage, so a table that had no upstream edge under such a mapping now gets one. **Action:** none, unless something relied on the `mssql` upstream of such tables; in that case map the workspace id in `server_to_platform_instance` and ingest the Fabric items with the OneLake connector so the new edge lands on an existing dataset. -- [#20885](https://github.com/datahub-project/datahub/pull/20885) **(Ingestion / Power BI)** In both `metadata_api_mode` settings, a dashboard tile without a title is now named `Tile `, after its 1-based position in the dashboard's tile list, instead of having an empty name, and each report page chart now carries a link to the page in the Power BI service. **Action:** none, unless you match charts by an empty title; the new names appear on the next run. Because a tile's number follows its position, reordering a dashboard's tiles can rename its untitled tiles; the chart URNs do not change. +- [#20885](https://github.com/datahub-project/datahub/pull/20885) **(Ingestion / Power BI)** In both `metadata_api_mode` settings, a dashboard tile without a title is now named `Tile `, after its 1-based position in the dashboard's tile list, instead of having an empty name, and each report page chart now carries a link to the page in the Power BI service. **Action:** none, unless you match charts by an empty title; the new names appear on the next run. Because a tile's number follows its position, reordering a dashboard's tiles can rename its untitled tiles; the chart URNs do not change. With `extract_report_field_usage` enabled, a report page chart and a tile pinned from a report now list as inputs only the model tables their fields read, instead of every table of the model, so chart-to-table lineage edges to tables those charts do not read are removed on the next run; only tables emitted in the same run count, so a model left out by `filter_dataset_endorsements` gives its charts no table inputs. - [#21219](https://github.com/datahub-project/datahub/pull/21219) **(Ingestion / Qlik Sense)** On Qlik Sense Enterprise, QVD datasets are now placed in `Folder` containers that follow their file path (server or share, then each folder), and are browsed under those folders instead of the path split at its dots. Their URNs, schemas and lineage are unchanged. **Action:** update any bookmark or saved browse path that pointed at the old QVD hierarchy. diff --git a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md index 6690df52a0501..0ceb45a5ed641 100644 --- a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md +++ b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md @@ -92,7 +92,7 @@ If the principal only has the `Viewer` role on a workspace, the dataset listing No Microsoft Entra application permissions need to change: both API families are authorized through the tenant settings and workspace roles above. The application requests a second token audience (`https://api.fabric.microsoft.com/.default`) in addition to the Power BI one. -What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report (not a paginated report, which never gets field usage or filters) whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. When field usage is extracted, a page chart and a tile pinned from a report list as inputs only the model tables their fields read: a table counts as read when a field reference names it, even if that field is missing from the fetched schema, and a page (or a report whose pages) that resolves to no table keeps the whole model (counted as `report_pages_inputs_fallback` and surfaced as a `Page Inputs Fell Back To Whole Model` warning), and a visual chart in that state has no table inputs. Independently of that flag and of `metadata_api_mode` (so in `admin_scan` too), each page chart links to its URL in the Power BI service, and a tile without a title is named `Tile ` after its 1-based order in the dashboard's tile list. +What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report (not a paginated report, which never gets field usage or filters) whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. When field usage is extracted, a page chart and a tile pinned from a report list as inputs only the model tables their fields read, out of the tables this run emitted: a model left out by `filter_dataset_endorsements` gives its charts no table inputs at all. A table counts as read when a field reference names it, even if that field is missing from the fetched schema. A page (or a report whose pages) whose definition was fetched and parsed but whose field references resolve to no table keeps the whole model (counted as `report_pages_inputs_fallback` and surfaced as a `Page Inputs Fell Back To Whole Model` warning), and a visual chart in that state has no table inputs; a report whose definition is refused or cannot be parsed keeps the whole model without a warning. Independently of that flag and of `metadata_api_mode` (so in `admin_scan` too), each page chart links to its URL in the Power BI service, and a tile without a title is named `Tile ` after its 1-based position in the dashboard's tile list, so adding, removing or reordering tiles can change that name between runs (the chart URN stays the same). **Fabric Lakehouse and Warehouse lineage.** The connector lists each workspace's Fabric items and registers the SQL analytics endpoint of every Lakehouse (one `GET lakehouses/{id}` call per lakehouse) and Warehouse (a warehouse is its own endpoint). A semantic-model table that reads one of them, either in DirectLake mode or through an Import/DirectQuery `Sql.Database(".datawarehouse.fabric.microsoft.com", ...)` query (a table navigation or a native `[Query=...]`), gets upstream lineage to the OneLake table (`fabric-onelake` platform, the same URN the OneLake connector emits) instead of a generic `mssql` one. The `Sql.Database` mapping applies in both metadata modes, since the admin scan also lists the workspace's Lakehouses and Warehouses. Map the workspace id in `server_to_platform_instance` to set the OneLake `platform_instance` and `env`. These OneLake edges are not subject to `dataset_type_mapping`, same as DirectLake lineage, so narrowing that mapping never turns such an edge into none; Dataflow Gen2 entities get the same mapping. The URNs match the OneLake connector's when that source runs with `convert_urns_to_lowercase: true` or this one with `convert_lineage_urns_to_lowercase: false` (by default Power BI lowercases the whole lineage URN while the OneLake connector keeps schema and table casing). A `Sql.Database` query may name the endpoint by id or by the item's display name. In `workspace_apis` mode a display name only matches on the workspace's own endpoint host; the admin scan reports no host, so there a display name matches the workspace's item on any host. A query naming an endpoint that is not among the workspace's items (for example a lakehouse in a workspace outside your workspace patterns) keeps its generic `mssql` edge and is reported as a `Fabric Endpoint Not Resolved` warning, and a display name shared by several items is reported as `Fabric Endpoint Name Ambiguous`. A `Sql.Databases` navigation, a navigation without an `Item`, or an endpoint behind a dataset parameter the connector could not resolve (the server argument is a parameter missing from the dataset) is not mapped: the first two are reported as `Fabric Endpoint M Shape Unsupported`, the last falls through to the generic SQL Server handling. Datamarts, mirrored databases and SQL databases are not covered: the OneLake connector does not ingest their tables, so no edge is emitted for them. diff --git a/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py b/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py index 69b3f841cde11..85551efa7cc6d 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py +++ b/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py @@ -2274,9 +2274,18 @@ def _tile_inputs( """The tile's table inputs: a tile pinned from a report shows one of its visuals, so when the report's pages name the tables they read, those narrow `ds_input` (the emitted model). An empty `ds_input` means - the model was not emitted (filtered out), so nothing is narrowed.""" + the model was not emitted (filtered out), so nothing is narrowed. + `ds_input` comes from the tile's dataset and the report tables from + the report's, so only tables present in both are kept: narrowing must + never add an edge to a table this run did not emit.""" if tile.report is not None and ds_input: - return self._report_used_dataset_urns(tile.report) or ds_input + emitted = set(ds_input) + narrowed = [ + urn + for urn in self._report_used_dataset_urns(tile.report) + if urn in emitted + ] + return narrowed or ds_input return ds_input @staticmethod @@ -2880,18 +2889,23 @@ def _resolve_page_fields( ) def _page_input_fields( - self, page: powerbi_data_classes.Page, report: powerbi_data_classes.Report + self, + page: powerbi_data_classes.Page, + report: powerbi_data_classes.Report, + model_emitted: bool, ) -> ResolvedInputFields: """Model columns and measures the page's visuals read, as inputFields pointing at the semantic-model tables' schema fields, plus the tables they belong to. This page pass is the only place feeding the page - counters.""" + counters. The whole-model fallback is only counted when the model was + emitted (`model_emitted`); otherwise the page has no table inputs to + fall back to.""" resolved = self._resolve_page_fields(page, report) reporter = self.__reporter reporter.report_field_references_resolved += resolved.resolved reporter.report_field_references_unresolved += resolved.unresolved reporter.report_field_references_field_unresolved += resolved.field_unresolved - if page.field_references and not resolved.dataset_urns: + if model_emitted and page.field_references and not resolved.dataset_urns: reporter.report_pages_inputs_fallback += 1 reporter.warning( title=Constant.PAGE_INPUTS_FELL_BACK, @@ -3175,7 +3189,9 @@ def to_chart_mcps( custom_properties[Constant.VISUAL_TYPES] = ", ".join(page.visual_types) custom_properties.update(self._filter_properties(page.filters)) - resolved = self._page_input_fields(page, report) + resolved = self._page_input_fields( + page, report, model_emitted=bool(ds_input) + ) # When the report definition told us which tables the page's # visuals read, those narrow the emitted model; when nothing # resolved the whole model stays, and an empty `ds_input` means @@ -3197,6 +3213,15 @@ def to_chart_mcps( aspect=chart_info_instance, ) + input_fields_mcp = resolved.mcp + if input_fields_mcp is None and page.field_references: + # The definition named fields but none matched the schema: + # write an empty InputFields (upserted whole) so fields from an + # earlier run do not outlive the page's narrowed inputs. + input_fields_mcp = MetadataChangeProposalWrapper( + entityUrn=chart_urn, aspect=InputFieldsClass(fields=[]) + ) + list_of_mcps = [ info_mcp, *self._chart_common_mcps( @@ -3204,7 +3229,7 @@ def to_chart_mcps( BIAssetSubTypes.POWERBI_PAGE, workspace, report, - resolved.mcp, + input_fields_mcp, ), ] diff --git a/metadata-ingestion/tests/unit/powerbi/test_enrich_from_item_definitions.py b/metadata-ingestion/tests/unit/powerbi/test_enrich_from_item_definitions.py index ff94c16228bc5..47f8cd1558648 100644 --- a/metadata-ingestion/tests/unit/powerbi/test_enrich_from_item_definitions.py +++ b/metadata-ingestion/tests/unit/powerbi/test_enrich_from_item_definitions.py @@ -723,7 +723,7 @@ def test_report_definition_fills_field_usage_that_resolves_against_scan_columns( reporter=api.reporter, dataplatform_instance_resolver=create_dataplatform_instance_resolver(config), ) - mcp = mapper._page_input_fields(page, report).mcp + mcp = mapper._page_input_fields(page, report, model_emitted=True).mcp assert mcp is not None assert isinstance(mcp.aspect, InputFieldsClass) assert [f.schemaFieldUrn.rsplit(",", 1)[1] for f in mcp.aspect.fields] == [ diff --git a/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py b/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py index c94406ae0e0dd..a497efdb86bf4 100644 --- a/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py +++ b/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py @@ -976,7 +976,7 @@ def test_page_input_fields_resolve_against_dataset_schema() -> None: users=[], tags=[], ) - mcp = mapper._page_input_fields(page, report).mcp + mcp = mapper._page_input_fields(page, report, model_emitted=True).mcp assert mcp is not None assert isinstance(mcp.aspect, InputFieldsClass) policies_urn = _urn(mapper, policies) @@ -2238,6 +2238,42 @@ def test_page_inputs_keep_a_table_whose_field_is_missing_from_the_schema() -> No assert reporter.report_pages_inputs_fallback == 0 +def test_page_with_unmatched_fields_writes_empty_input_fields() -> None: + """A page whose references name a table but no schema field narrows + its inputs to that table and writes an empty InputFields, so columns + from an earlier run are not left behind.""" + mapper = _mapper(_config(extract_report_field_usage=True, platform_instance="prod")) + report = _three_table_report() + report.pages[0].field_references = [PageFieldReference("Claims", "Gone", "column")] + workspace = _workspace() + mapper.workspace_key = mapper.make_container_key_for_workspace(workspace) + chart_mcps = mapper.pages_to_chart( + report.pages, + workspace=workspace, + ds_mcps=_model_mcps(mapper, report), + report=report, + ) + aspects = _aspects_of(chart_mcps, PAGE_URN) + assert report.dataset is not None + assert aspects["ChartInfoClass"].inputs == [_urn(mapper, report.dataset.tables[1])] + assert aspects["InputFieldsClass"].fields == [] + + +def test_page_fallback_is_not_reported_when_the_model_was_not_emitted() -> None: + mapper = _mapper(_config(extract_report_field_usage=True, platform_instance="prod")) + report = _three_table_report() + report.pages[0].field_references = [PageFieldReference("Other", "Gone", "column")] + workspace = _workspace() + mapper.workspace_key = mapper.make_container_key_for_workspace(workspace) + chart_mcps = mapper.pages_to_chart( + report.pages, workspace=workspace, ds_mcps=[], report=report + ) + assert _aspects_of(chart_mcps, PAGE_URN)["ChartInfoClass"].inputs == [] + reporter = _reporter(mapper) + assert reporter.report_pages_inputs_fallback == 0 + assert Constant.PAGE_INPUTS_FELL_BACK not in [w.title for w in reporter.warnings] + + def _tile( tile_id: str, dataset: Optional[PowerBIDataset], @@ -2340,6 +2376,22 @@ def test_report_tile_inputs_stay_the_whole_model_without_narrowing( ] +def test_report_tile_inputs_never_name_tables_outside_the_tile_model() -> None: + """A tile's emitted model and its report's model are looked up + separately; report tables the tile's model does not hold are dropped, + leaving the tile's own model when none remain.""" + mapper = _mapper(_config(extract_report_field_usage=True, platform_instance="prod")) + report = _three_table_report() + other = _dataset( + [Table(name="Sales", full_name="Other.Sales", columns=[_column("Amount")])] + ) + other.id = "ds-2" + infos = _tile_chart_infos(mapper, [_tile("t1", other, report, "From report")]) + assert infos["urn:li:chart:(powerbi,prod.charts.t1)"].inputs == [ + _urn(mapper, other.tables[0]) + ] + + def test_untitled_tile_is_named_by_its_order_in_the_tile_list() -> None: mapper = _mapper(_config(platform_instance="prod")) report = _three_table_report(with_field_references=False) From 632e81cc4553d550f19a0b867b74e71eab83e5c4 Mon Sep 17 00:00:00 2001 From: Brock Griffey <52086127+brock-acryl@users.noreply.github.com> Date: Fri, 4 Dec 2026 14:59:58 -0500 Subject: [PATCH 6/7] fix(ingest/powerbi): narrow chart inputs only from complete page field usage A page missing from the report definition gets only the report-level filter fields, and a definition with unparsed parts or filters drops some fields, yet both narrowed ChartInfo.inputs to that subset and removed edges to tables the page still reads. Pages now carry field_usage_complete, set only for a page found in a fully parsed definition; page and report-tile narrowing (and the fallback warning) require it. Co-Authored-By: Claude Opus 5.5 --- .../docs/sources/powerbi/powerbi_pre.md | 2 +- .../ingestion/source/powerbi/powerbi.py | 17 +++++- .../powerbi/rest_api_wrapper/data_classes.py | 4 ++ .../powerbi/rest_api_wrapper/powerbi_api.py | 6 ++ .../test_fill_metadata_from_definitions.py | 60 +++++++++++++++++++ .../powerbi/test_workspace_apis_mapper.py | 28 ++++++++- 6 files changed, 113 insertions(+), 4 deletions(-) diff --git a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md index 0ceb45a5ed641..ca8cb4d34ef37 100644 --- a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md +++ b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md @@ -92,7 +92,7 @@ If the principal only has the `Viewer` role on a workspace, the dataset listing No Microsoft Entra application permissions need to change: both API families are authorized through the tenant settings and workspace roles above. The application requests a second token audience (`https://api.fabric.microsoft.com/.default`) in addition to the Power BI one. -What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report (not a paginated report, which never gets field usage or filters) whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. When field usage is extracted, a page chart and a tile pinned from a report list as inputs only the model tables their fields read, out of the tables this run emitted: a model left out by `filter_dataset_endorsements` gives its charts no table inputs at all. A table counts as read when a field reference names it, even if that field is missing from the fetched schema. A page (or a report whose pages) whose definition was fetched and parsed but whose field references resolve to no table keeps the whole model (counted as `report_pages_inputs_fallback` and surfaced as a `Page Inputs Fell Back To Whole Model` warning), and a visual chart in that state has no table inputs; a report whose definition is refused or cannot be parsed keeps the whole model without a warning. Independently of that flag and of `metadata_api_mode` (so in `admin_scan` too), each page chart links to its URL in the Power BI service, and a tile without a title is named `Tile ` after its 1-based position in the dashboard's tile list, so adding, removing or reordering tiles can change that name between runs (the chart URN stays the same). +What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report (not a paginated report, which never gets field usage or filters) whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. When field usage is extracted, a page chart and a tile pinned from a report list as inputs only the model tables their fields read, out of the tables this run emitted: a model left out by `filter_dataset_endorsements` gives its charts no table inputs at all. A table counts as read when a field reference names it, even if that field is missing from the fetched schema. A page (or a report whose pages) whose definition was fetched and parsed but whose field references resolve to no table keeps the whole model (counted as `report_pages_inputs_fallback` and surfaced as a `Page Inputs Fell Back To Whole Model` warning), and a visual chart in that state has no table inputs; a report whose definition is refused or cannot be parsed keeps the whole model without a warning, and so does a page missing from the definition or a page of a definition where some part or filter failed to parse (that failure is warned on its own), since its field references would be incomplete. Independently of that flag and of `metadata_api_mode` (so in `admin_scan` too), each page chart links to its URL in the Power BI service, and a tile without a title is named `Tile ` after its 1-based position in the dashboard's tile list, so adding, removing or reordering tiles can change that name between runs (the chart URN stays the same). **Fabric Lakehouse and Warehouse lineage.** The connector lists each workspace's Fabric items and registers the SQL analytics endpoint of every Lakehouse (one `GET lakehouses/{id}` call per lakehouse) and Warehouse (a warehouse is its own endpoint). A semantic-model table that reads one of them, either in DirectLake mode or through an Import/DirectQuery `Sql.Database(".datawarehouse.fabric.microsoft.com", ...)` query (a table navigation or a native `[Query=...]`), gets upstream lineage to the OneLake table (`fabric-onelake` platform, the same URN the OneLake connector emits) instead of a generic `mssql` one. The `Sql.Database` mapping applies in both metadata modes, since the admin scan also lists the workspace's Lakehouses and Warehouses. Map the workspace id in `server_to_platform_instance` to set the OneLake `platform_instance` and `env`. These OneLake edges are not subject to `dataset_type_mapping`, same as DirectLake lineage, so narrowing that mapping never turns such an edge into none; Dataflow Gen2 entities get the same mapping. The URNs match the OneLake connector's when that source runs with `convert_urns_to_lowercase: true` or this one with `convert_lineage_urns_to_lowercase: false` (by default Power BI lowercases the whole lineage URN while the OneLake connector keeps schema and table casing). A `Sql.Database` query may name the endpoint by id or by the item's display name. In `workspace_apis` mode a display name only matches on the workspace's own endpoint host; the admin scan reports no host, so there a display name matches the workspace's item on any host. A query naming an endpoint that is not among the workspace's items (for example a lakehouse in a workspace outside your workspace patterns) keeps its generic `mssql` edge and is reported as a `Fabric Endpoint Not Resolved` warning, and a display name shared by several items is reported as `Fabric Endpoint Name Ambiguous`. A `Sql.Databases` navigation, a navigation without an `Item`, or an endpoint behind a dataset parameter the connector could not resolve (the server argument is a parameter missing from the dataset) is not mapped: the first two are reported as `Fabric Endpoint M Shape Unsupported`, the last falls through to the generic SQL Server handling. Datamarts, mirrored databases and SQL databases are not covered: the OneLake connector does not ingest their tables, so no edge is emitted for them. diff --git a/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py b/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py index 85551efa7cc6d..cf063b5c5bdea 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py +++ b/metadata-ingestion/src/datahub/ingestion/source/powerbi/powerbi.py @@ -2905,7 +2905,12 @@ def _page_input_fields( reporter.report_field_references_resolved += resolved.resolved reporter.report_field_references_unresolved += resolved.unresolved reporter.report_field_references_field_unresolved += resolved.field_unresolved - if model_emitted and page.field_references and not resolved.dataset_urns: + if ( + model_emitted + and page.field_usage_complete + and page.field_references + and not resolved.dataset_urns + ): reporter.report_pages_inputs_fallback += 1 reporter.warning( title=Constant.PAGE_INPUTS_FELL_BACK, @@ -2925,6 +2930,11 @@ def _report_used_dataset_urns( if cached is not None: return list(cached) dataset_urns: List[str] = [] + if not all(page.field_usage_complete for page in report.pages): + # A tile may show a visual from any page, so one page with partial + # field usage leaves the report's tables unknown. + self.__report_used_dataset_urns[report.id] = dataset_urns + return [] for page in report.pages: for dataset_urn in self._resolve_page_fields(page, report).dataset_urns: if dataset_urn not in dataset_urns: @@ -3196,7 +3206,10 @@ def to_chart_mcps( # visuals read, those narrow the emitted model; when nothing # resolved the whole model stays, and an empty `ds_input` means # the model was not emitted at all, so there is nothing to narrow. - if ds_input and resolved.dataset_urns: + # Only a page whose field usage is complete narrows: a page missing + # from the definition, or one with unparsed parts, lists a subset + # of what it reads, and narrowing would drop real edges. + if ds_input and page.field_usage_complete and resolved.dataset_urns: ds_input = list(resolved.dataset_urns) chart_info_instance = ChartInfoClass( diff --git a/metadata-ingestion/src/datahub/ingestion/source/powerbi/rest_api_wrapper/data_classes.py b/metadata-ingestion/src/datahub/ingestion/source/powerbi/rest_api_wrapper/data_classes.py index 6f8671b3dd8a9..94471cf22c4a7 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/powerbi/rest_api_wrapper/data_classes.py +++ b/metadata-ingestion/src/datahub/ingestion/source/powerbi/rest_api_wrapper/data_classes.py @@ -630,6 +630,10 @@ class Page: order: int # Populated only when extract_report_field_usage is enabled. field_references: List[PageFieldReference] = field(default_factory=list) + # True only when the page was found in a fully parsed report definition, + # so `field_references` lists every field its visuals and filters read. + # Chart inputs are only narrowed to those tables when this holds. + field_usage_complete: bool = False visual_count: Optional[int] = None visual_types: List[str] = field(default_factory=list) filters: List[ReportFilter] = field(default_factory=list) diff --git a/metadata-ingestion/src/datahub/ingestion/source/powerbi/rest_api_wrapper/powerbi_api.py b/metadata-ingestion/src/datahub/ingestion/source/powerbi/rest_api_wrapper/powerbi_api.py index 628fc02f7a1a7..1419fbf289476 100644 --- a/metadata-ingestion/src/datahub/ingestion/source/powerbi/rest_api_wrapper/powerbi_api.py +++ b/metadata-ingestion/src/datahub/ingestion/source/powerbi/rest_api_wrapper/powerbi_api.py @@ -1549,6 +1549,9 @@ def _fill_report_field_usage(self, workspace: Workspace, report: Report) -> None ) report.filters = parsed.filters self.reporter.report_filters_parsed += len(parsed.filters) + # A part or filter that failed to parse may hold fields any page + # reads, so no page's field usage is complete then. + definition_complete = not failed_parts and not parsed.failed_filters for page in report.pages: parsed_page: Optional[ParsedPage] = parsed.pages.get(page.name) if parsed_page is None and page.displayName: @@ -1571,6 +1574,9 @@ def _fill_report_field_usage(self, workspace: Workspace, report: Report) -> None page.filters = parsed_page.filters self.reporter.report_filters_parsed += len(parsed_page.filters) page.field_references = parsed.page_field_refs(parsed_page) + page.field_usage_complete = definition_complete and not any( + visual.definition_failed for visual in parsed_page.visuals + ) if self.__config.extract_report_visuals: page.visuals = self._visuals_of(page, parsed_page, context) diff --git a/metadata-ingestion/tests/unit/powerbi/test_fill_metadata_from_definitions.py b/metadata-ingestion/tests/unit/powerbi/test_fill_metadata_from_definitions.py index 55569d4fb7866..1d12720d76f3b 100644 --- a/metadata-ingestion/tests/unit/powerbi/test_fill_metadata_from_definitions.py +++ b/metadata-ingestion/tests/unit/powerbi/test_fill_metadata_from_definitions.py @@ -1195,10 +1195,70 @@ def test_report_and_page_filters_are_applied_and_bad_filters_only_warn() -> None assert api.reporter.report_pages_unmatched == 1 assert api.reporter.report_filters_parsed == 2 assert api.reporter.report_filters_failed == 1 + # A filter failed to parse, and p2 is not in the definition: neither + # page's field usage is complete, so neither narrows its chart inputs. + assert not page.field_usage_complete + assert not unmatched.field_usage_complete assert [w.title for w in api.reporter.warnings] == ["Report Filter Not Parsed"] assert not api.reporter.failures +@pytest.mark.parametrize("visual_text, complete", [(None, True), ("{", False)]) +def test_page_field_usage_is_complete_only_when_its_definition_parsed( + visual_text: Optional[str], complete: bool +) -> None: + visual_part = visual_text or json.dumps( + { + "name": "v1", + "visual": { + "visualType": "card", + "query": { + "queryState": { + "Values": { + "projections": [ + {"field": _column_ref("Policies", "WrittenPremium")} + ] + } + } + }, + }, + } + ) + definition = ItemDefinition( + format="PBIR", + parts=[ + DefinitionPart("definition/report.json", json.dumps({})), + DefinitionPart( + "definition/pages/p1/page.json", + json.dumps({"name": "p1", "displayName": "Overview"}), + ), + DefinitionPart("definition/pages/p1/visuals/v1/visual.json", visual_part), + ], + ) + api = _api( + definitions={"r1": definition}, + config=_config(extract_report_field_usage=True), + ) + page = Page(id="r1.p1", displayName="Overview", name="p1", order=0) + report = Report( + id="r1", + name="Loss Report", + type=ReportType.PowerBIReport, + webUrl=None, + embedUrl=None, + description="", + dataset_id=MODEL_A, + dataset=None, + pages=[page], + users=[], + tags=[], + ) + + api._fill_report_field_usage(_workspace(), report) + + assert page.field_usage_complete is complete + + def test_report_definition_parser_crash_is_a_warning_for_that_report_only() -> None: api = _api( definitions={"r1": ItemDefinition(format="PBIR", parts=[])}, diff --git a/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py b/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py index a497efdb86bf4..c8db492d24120 100644 --- a/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py +++ b/metadata-ingestion/tests/unit/powerbi/test_workspace_apis_mapper.py @@ -2153,7 +2153,9 @@ def _three_table_report(with_field_references: bool = True) -> Report: report = _report_with_visuals( _dataset([policies, claims, unused]), with_visuals=False ) - if not with_field_references: + if with_field_references: + report.pages[0].field_usage_complete = True + else: report.pages[0].field_references = [] return report @@ -2218,6 +2220,30 @@ def test_page_inputs_stay_the_whole_model_when_nothing_resolves() -> None: assert Constant.PAGE_INPUTS_FELL_BACK in [w.title for w in reporter.warnings] +def test_page_with_partial_field_usage_keeps_the_whole_model() -> None: + """A page missing from the definition, or one with unparsed parts, has + only some of its field references; narrowing to them would drop edges + to tables it still reads, so the whole model stays and no fallback is + counted (the parse problem is already warned).""" + mapper = _mapper(_config(extract_report_field_usage=True, platform_instance="prod")) + report = _three_table_report() + report.pages[0].field_usage_complete = False + info, reporter = _page_chart_info(mapper, report) + assert report.dataset is not None + assert info.inputs == [_urn(mapper, t) for t in report.dataset.tables] + assert reporter.report_pages_inputs_fallback == 0 + + tile_mapper = _mapper( + _config(extract_report_field_usage=True, platform_instance="prod") + ) + infos = _tile_chart_infos( + tile_mapper, [_tile("t1", report.dataset, report, "From report")] + ) + assert infos["urn:li:chart:(powerbi,prod.charts.t1)"].inputs == [ + _urn(tile_mapper, t) for t in report.dataset.tables + ] + + def test_page_inputs_keep_a_table_whose_field_is_missing_from_the_schema() -> None: """A renamed column proves the page reads the table even though the field itself cannot be matched: the table-level edge stays, the field From 22353dffb0074d0d0ed793e00787710fd79ebe2d Mon Sep 17 00:00:00 2001 From: Brock Griffey <52086127+brock-acryl@users.noreply.github.com> Date: Fri, 4 Dec 2026 15:12:30 -0500 Subject: [PATCH 7/7] docs(ingest/powerbi): name the report definition formats that get field usage Co-Authored-By: Claude Opus 5.5 --- metadata-ingestion/docs/sources/powerbi/powerbi_pre.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md index ca8cb4d34ef37..a81839d700f63 100644 --- a/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md +++ b/metadata-ingestion/docs/sources/powerbi/powerbi_pre.md @@ -92,7 +92,7 @@ If the principal only has the `Viewer` role on a workspace, the dataset listing No Microsoft Entra application permissions need to change: both API families are authorized through the tenant settings and workspace roles above. The application requests a second token audience (`https://api.fabric.microsoft.com/.default`) in addition to the Power BI one. -What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report (not a paginated report, which never gets field usage or filters) whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. When field usage is extracted, a page chart and a tile pinned from a report list as inputs only the model tables their fields read, out of the tables this run emitted: a model left out by `filter_dataset_endorsements` gives its charts no table inputs at all. A table counts as read when a field reference names it, even if that field is missing from the fetched schema. A page (or a report whose pages) whose definition was fetched and parsed but whose field references resolve to no table keeps the whole model (counted as `report_pages_inputs_fallback` and surfaced as a `Page Inputs Fell Back To Whole Model` warning), and a visual chart in that state has no table inputs; a report whose definition is refused or cannot be parsed keeps the whole model without a warning, and so does a page missing from the definition or a page of a definition where some part or filter failed to parse (that failure is warned on its own), since its field references would be incomplete. Independently of that flag and of `metadata_api_mode` (so in `admin_scan` too), each page chart links to its URL in the Power BI service, and a tile without a title is named `Tile ` after its 1-based position in the dashboard's tile list, so adding, removing or reordering tiles can change that name between runs (the chart URN stays the same). +What `workspace_apis` mode ingests: workspaces, dashboards, tiles, reports, report pages, datasets with tables, columns, measures and their descriptions, M expressions, table and column lineage (including DirectLake lineage to Fabric Lakehouses and Warehouses), paginated-report dataset bindings, and owners derived from workspace roles. With `extract_report_field_usage` enabled, a Power BI report in either definition format, PBIR (`definition/pages/*/visuals/*/visual.json`) or PBIR-Legacy (a single `report.json`), whose definition is fetched and parsed gets, on each page chart, the model fields its visuals read, and its report-level and page-level filters as `filters` / `filterCount` properties on the report and its pages, with the filtered fields added to the page's `inputFields`; a report whose definition is refused or cannot be parsed gets neither its filters nor their fields. Paginated reports never get field usage or filters. `filters` holds at most 50 entries: `filterCount` is the full count and `filtersTruncated: true` marks a shortened list. A rendered condition is cut to 500 characters and lists at most 20 `In` values, and a condition shape the connector does not recognize is kept as its raw JSON cut to 200 characters, so `filters` is a summary, not the complete filter definition. A filter's rendered condition includes the literal values it compares against (for example the selected categories or thresholds), so treat these properties as potentially containing business data. When field usage is extracted, a page chart and a tile pinned from a report list as inputs only the model tables their fields read, out of the tables this run emitted: a model left out by `filter_dataset_endorsements` gives its charts no table inputs at all. A table counts as read when a field reference names it, even if that field is missing from the fetched schema. A page (or a report whose pages) whose definition was fetched and parsed but whose field references resolve to no table keeps the whole model (counted as `report_pages_inputs_fallback` and surfaced as a `Page Inputs Fell Back To Whole Model` warning), and a visual chart in that state has no table inputs; a report whose definition is refused or cannot be parsed keeps the whole model without a warning, and so does a page missing from the definition or a page of a definition where some part or filter failed to parse (that failure is warned on its own), since its field references would be incomplete. Independently of that flag and of `metadata_api_mode` (so in `admin_scan` too), each page chart links to its URL in the Power BI service, and a tile without a title is named `Tile ` after its 1-based position in the dashboard's tile list, so adding, removing or reordering tiles can change that name between runs (the chart URN stays the same). **Fabric Lakehouse and Warehouse lineage.** The connector lists each workspace's Fabric items and registers the SQL analytics endpoint of every Lakehouse (one `GET lakehouses/{id}` call per lakehouse) and Warehouse (a warehouse is its own endpoint). A semantic-model table that reads one of them, either in DirectLake mode or through an Import/DirectQuery `Sql.Database(".datawarehouse.fabric.microsoft.com", ...)` query (a table navigation or a native `[Query=...]`), gets upstream lineage to the OneLake table (`fabric-onelake` platform, the same URN the OneLake connector emits) instead of a generic `mssql` one. The `Sql.Database` mapping applies in both metadata modes, since the admin scan also lists the workspace's Lakehouses and Warehouses. Map the workspace id in `server_to_platform_instance` to set the OneLake `platform_instance` and `env`. These OneLake edges are not subject to `dataset_type_mapping`, same as DirectLake lineage, so narrowing that mapping never turns such an edge into none; Dataflow Gen2 entities get the same mapping. The URNs match the OneLake connector's when that source runs with `convert_urns_to_lowercase: true` or this one with `convert_lineage_urns_to_lowercase: false` (by default Power BI lowercases the whole lineage URN while the OneLake connector keeps schema and table casing). A `Sql.Database` query may name the endpoint by id or by the item's display name. In `workspace_apis` mode a display name only matches on the workspace's own endpoint host; the admin scan reports no host, so there a display name matches the workspace's item on any host. A query naming an endpoint that is not among the workspace's items (for example a lakehouse in a workspace outside your workspace patterns) keeps its generic `mssql` edge and is reported as a `Fabric Endpoint Not Resolved` warning, and a display name shared by several items is reported as `Fabric Endpoint Name Ambiguous`. A `Sql.Databases` navigation, a navigation without an `Item`, or an endpoint behind a dataset parameter the connector could not resolve (the server argument is a parameter missing from the dataset) is not mapped: the first two are reported as `Fabric Endpoint M Shape Unsupported`, the last falls through to the generic SQL Server handling. Datamarts, mirrored databases and SQL databases are not covered: the OneLake connector does not ingest their tables, so no edge is emitted for them.