Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
if self.client.file_client:
self.client.file_client.delete_tmp_files()

def get_org_workspace_data(self) -> Iterable[Optional[Group]]: # noqa: UP045

Check failure on line 130 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZsp&open=AZ4DUPOPqz2fO813SZsp&pullRequest=27970
"""
fetch all the workspace data for non-admin users
"""
Expand Down Expand Up @@ -197,7 +197,7 @@
paginated_include_filters.append(filter_pattern_copy)
return paginated_include_filters

def get_admin_workspace_data(self) -> Iterable[Optional[Group]]: # noqa: UP045

Check failure on line 200 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 29 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZsq&open=AZ4DUPOPqz2fO813SZsq&pullRequest=27970
"""
fetch all the workspace data
"""
Expand Down Expand Up @@ -298,13 +298,13 @@

def get_dashboards_list(
self,
) -> Optional[List[Union[PowerBIDashboard, PowerBIReport]]]: # noqa: UP006, UP007, UP045

Check warning on line 301 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Use a union type expression for this type hint.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZsr&open=AZ4DUPOPqz2fO813SZsr&pullRequest=27970
"""
Get List of all dashboards
"""
return self.context.get().workspace.reports + self.context.get().workspace.dashboards

def get_dashboard_name(self, dashboard: Union[PowerBIDashboard, PowerBIReport]) -> str: # noqa: UP007

Check warning on line 307 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Use a union type expression for this type hint.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZss&open=AZ4DUPOPqz2fO813SZss&pullRequest=27970
"""
Get Dashboard Name
"""
Expand All @@ -314,8 +314,8 @@

def get_dashboard_details(
self,
dashboard: Union[PowerBIDashboard, PowerBIReport], # noqa: UP007

Check warning on line 317 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Use a union type expression for this type hint.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZst&open=AZ4DUPOPqz2fO813SZst&pullRequest=27970
) -> Union[PowerBIDashboard, PowerBIReport]: # noqa: UP007

Check warning on line 318 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Use a union type expression for this type hint.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZsu&open=AZ4DUPOPqz2fO813SZsu&pullRequest=27970
"""
Get Dashboard Details
"""
Expand Down Expand Up @@ -442,7 +442,7 @@
)
)

def yield_dashboard_chart(self, dashboard_details: Group) -> Iterable[Either[CreateChartRequest]]:

Check warning on line 445 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Introduce a new variable or use its initial value before reassigning 'dashboard_details'.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZsw&open=AZ4DUPOPqz2fO813SZsw&pullRequest=27970

Check failure on line 445 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 20 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZsv&open=AZ4DUPOPqz2fO813SZsv&pullRequest=27970
"""Get chart method
Args:
dashboard_details:
Expand Down Expand Up @@ -567,7 +567,7 @@
logger.warning(f"Error to yield datamodel column: {exc}")
return datasource_columns

def _get_dataflow_column_info(self, dataflow_export: DataflowExportResponse) -> Optional[List[Column]]: # noqa: UP006, UP045

Check failure on line 570 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZsx&open=AZ4DUPOPqz2fO813SZsx&pullRequest=27970
"""Build columns from dataflow export response entities"""
datasource_columns = []
for entity in dataflow_export.entities or []:
Expand Down Expand Up @@ -606,13 +606,13 @@
logger.warning(f"Error to yield dataflow entity column: {exc}")
return datasource_columns

def _get_datamodels_list(self) -> List[Union[Dataset, Dataflow]]: # noqa: UP006, UP007

Check warning on line 609 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Use a union type expression for this type hint.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZsy&open=AZ4DUPOPqz2fO813SZsy&pullRequest=27970
"""
Get All the Powerbi Datasets
"""
return self.context.get().workspace.datasets + self.context.get().workspace.dataflows

def yield_datamodel(self, dashboard_details: Group) -> Iterable[Either[CreateDashboardDataModelRequest]]:

Check failure on line 615 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 20 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZsz&open=AZ4DUPOPqz2fO813SZsz&pullRequest=27970
"""
Get All the Powerbi Datasets
"""
Expand Down Expand Up @@ -670,11 +670,12 @@
)
)

def create_report_dashboard_lineage(

Check failure on line 673 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZs0&open=AZ4DUPOPqz2fO813SZs0&pullRequest=27970
self, dashboard_details: PowerBIDashboard
) -> Iterable[Either[CreateDashboardRequest]]:
"""Create lineage between report and dashboard"""
Comment thread
harshsoni2024 marked this conversation as resolved.
try:
logger.debug(f"Processing to create report and dashboard lineage for dashboard: {dashboard_details.id}")
charts = dashboard_details.tiles
dashboard_fqn = fqn.build(
self.metadata,
Expand All @@ -686,9 +687,22 @@
entity=Dashboard,
fqn=dashboard_fqn,
)
if not dashboard_entity:
logger.debug(
f"Dashboard entity not found to create lineage between report and dashboard for dashboard: {dashboard_details.id}"
)
return
for chart in charts or []:
if chart.reportId:
logger.debug(f"Dashboard's chart {chart.id} is linked with report id: {str(chart.reportId)}") # noqa: RUF010
else:
logger.debug(f"Dashboard's chart {chart.id} is not linked with any report")
continue
report = self._fetch_report_from_workspace(chart.reportId)
if report:
logger.debug(
f"Fetched report details for report id: {str(chart.reportId)} from workspace data to create lineage with dashboard: {dashboard_details.id}" # noqa: RUF010
)
report_fqn = fqn.build(
self.metadata,
entity_type=Dashboard,
Expand All @@ -699,9 +713,19 @@
entity=Dashboard,
fqn=report_fqn,
)

if not report_entity:
logger.debug(
f"Report entity not found to create lineage between report={report.id} and dashboard={dashboard_details.id}"
)
if report_entity and dashboard_entity:
logger.debug(
f"Creating lineage between report={report.id} and dashboard={dashboard_details.id}"
)
yield self._get_add_lineage_request(to_entity=dashboard_entity, from_entity=report_entity)
else:
logger.debug(
f"Could not fetch report with report id: {str(chart.reportId)} from workspace data to create lineage with dashboard: {dashboard_details.id}" # noqa: RUF010
)
except Exception as exc: # pylint: disable=broad-except
yield Either(
left=StackTraceError(
Expand Down Expand Up @@ -729,6 +753,8 @@
)
if match:
dataset_ids.append(match.group(1))
if dataset_ids:
logger.debug(f"Extracted dataset IDs from report datasources API call for report_id={report_id}")
return dataset_ids

def create_datamodel_report_lineage(
Expand All @@ -740,6 +766,7 @@
create the lineage between datamodel and report
"""
try:
logger.debug(f"Processing to create datamodel and report lineage for report: {dashboard_details.id}")
report_fqn = fqn.build(
self.metadata,
entity_type=Dashboard,
Expand All @@ -750,10 +777,19 @@
entity=Dashboard,
fqn=report_fqn,
)
if not report_entity:
logger.debug(
f"Report entity not found to create lineage between datamodel and report for report: {dashboard_details.id}"
)
return
dataset_ids = []
if dashboard_details.datasetId:
logger.debug(f"Report linked datasetId is present in api response for report: {dashboard_details.id}")
dataset_ids = [dashboard_details.datasetId]
else:
logger.debug(
f"Processing to get report datasources from API to extract datasetIds for report: {dashboard_details.id} as datasetId is not present in api response"
)
dataset_ids = self._get_dataset_ids_from_report_datasources(report_id=dashboard_details.id)

if dataset_ids:
Expand All @@ -768,6 +804,10 @@
entity=DashboardDataModel,
fqn=datamodel_fqn,
)
if not datamodel_entity:
logger.debug(
f"Data model entity not found for dataset_id={str(dataset_id)} while creating lineage with report={str(dashboard_details.id)}" # noqa: RUF010
)
if datamodel_entity and report_entity:
logger.debug(
f"Creating lineage between datamodel={str(dataset_id)} and report={str(dashboard_details.id)}" # noqa: RUF010
Expand All @@ -778,7 +818,7 @@
)
else:
logger.debug(
f"Skipping datamodel and report lineage for {dashboard_details.id} as datasetId is not found"
f"Skipping datamodel and report lineage for report: {dashboard_details.id} as datasetId is not found on api response and also could not be extracted from report datasources API call"
)

except Exception as exc: # pylint: disable=broad-except
Expand Down Expand Up @@ -838,7 +878,7 @@
logger.debug(traceback.format_exc())
return None

def _parse_expression_regex_exp(self, match: re.Match, datamodel_entity: DashboardDataModel) -> Optional[str]: # noqa: UP045

Check failure on line 881 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 23 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZs1&open=AZ4DUPOPqz2fO813SZs1&pullRequest=27970
"""parse snowflake regex expression"""
try:
if not match:
Expand Down Expand Up @@ -888,7 +928,7 @@
logger.debug(traceback.format_exc())
return None

def _parse_bigquery_query_source(self, source_expression: str) -> Optional[List[dict]]: # noqa: UP006, UP045

Check failure on line 931 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 23 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZs2&open=AZ4DUPOPqz2fO813SZs2&pullRequest=27970
"""
Parse BigQuery Value.NativeQuery source expressions containing inline SQL.

Expand Down Expand Up @@ -1029,7 +1069,7 @@
)
return self._parse_bigquery_query_source(source_expression)

logger.debug(f"Found GoogleBigQuery.Database in expression") # noqa: F541

Check warning on line 1072 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Add replacement fields or use a normal string instead of an f-string.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZs3&open=AZ4DUPOPqz2fO813SZs3&pullRequest=27970
# Extract project, dataset (schema), and table from BigQuery M expression
# Pattern: [Name="project"][Data][Name="dataset",Kind="Schema"][Data][Name="table",Kind="Table"]

Expand Down Expand Up @@ -1073,7 +1113,7 @@
logger.debug(traceback.format_exc())
return None

def _parse_snowflake_query_source(self, source_expression: str) -> Optional[List[dict]]: # noqa: UP006, UP045

Check failure on line 1116 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 56 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZs4&open=AZ4DUPOPqz2fO813SZs4&pullRequest=27970
"""
Parse snowflake query source
source expressions like `Value.NativeQuery(Snowflake.Databases())`
Expand Down Expand Up @@ -1585,7 +1625,7 @@
)
)

def _parse_dataflow_m_document(self, dataflow_export: DataflowExportResponse) -> List[dict]: # noqa: UP006

Check failure on line 1628 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZs5&open=AZ4DUPOPqz2fO813SZs5&pullRequest=27970
"""
Parse Power Query M expressions from the dataflow export document
to extract table references for each entity/query in the dataflow.
Expand Down Expand Up @@ -2062,7 +2102,7 @@
return dataset_data
return None

def _fetch_report_from_workspace(self, report_id: Optional[str]) -> Optional[Dataset]: # noqa: UP045
def _fetch_report_from_workspace(self, report_id: Optional[str]) -> Optional[PowerBIReport]: # noqa: UP045
"""
Method to search the report using id in the workspace dict
"""
Expand All @@ -2087,7 +2127,7 @@
logger.warning(f"Error fetching project name for {dashboard_details.id}: {exc}")
return None

def get_owner_ref( # pylint: disable=unused-argument, useless-return # noqa: C901

Check failure on line 2130 in ingestion/src/metadata/ingestion/source/dashboard/powerbi/metadata.py

View check run for this annotation

SonarQubeCloud / [open-metadata-ingestion] SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 48 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=open-metadata-ingestion&issues=AZ4DUPOPqz2fO813SZs6&open=AZ4DUPOPqz2fO813SZs6&pullRequest=27970
self, dashboard_details: Any
) -> Optional[EntityReferenceList]: # noqa: UP045
"""
Expand Down
Loading