Fix #6862: Improve Superset dict handling (#6864)

This commit is contained in:
Mayur Singal 2022-08-23 13:37:09 +05:30 committed by GitHub
parent 3d125d9372
commit f32572c949
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,6 +19,7 @@ from typing import Iterable, List, Optional
from metadata.generated.schema.api.data.createChart import CreateChartRequest from metadata.generated.schema.api.data.createChart import CreateChartRequest
from metadata.generated.schema.api.data.createDashboard import CreateDashboardRequest from metadata.generated.schema.api.data.createDashboard import CreateDashboardRequest
from metadata.generated.schema.api.lineage.addLineage import AddLineageRequest from metadata.generated.schema.api.lineage.addLineage import AddLineageRequest
from metadata.generated.schema.entity.data.chart import ChartType
from metadata.generated.schema.entity.data.dashboard import ( from metadata.generated.schema.entity.data.dashboard import (
Dashboard as Lineage_Dashboard, Dashboard as Lineage_Dashboard,
) )
@ -178,9 +179,9 @@ class SupersetSource(DashboardServiceSource):
if raw_position_data: if raw_position_data:
position_data = json.loads(raw_position_data) position_data = json.loads(raw_position_data)
return [ return [
value.get("meta", {}).get("chartId", "unknown") value.get("meta", {}).get("chartId")
for key, value in position_data.items() for key, value in position_data.items()
if key.startswith("CHART-") if key.startswith("CHART-") and value.get("meta", {}).get("chartId")
] ]
return [] return []
@ -241,18 +242,17 @@ class SupersetSource(DashboardServiceSource):
""" """
for chart_id in self._get_charts_of_dashboard(dashboard_details): for chart_id in self._get_charts_of_dashboard(dashboard_details):
chart_json = self.all_charts.get(chart_id) chart_json = self.all_charts.get(chart_id)
chart_id = chart_json["id"] if not chart_json:
params = json.loads(chart_json["params"]) logger.warning(f"chart details for id: {chart_id} not found, skipped")
group_bys = params.get("groupby", []) or [] continue
if isinstance(group_bys, str):
group_bys = [group_bys]
chart = CreateChartRequest( chart = CreateChartRequest(
name=chart_id, name=chart_json["id"],
displayName=chart_json["slice_name"], displayName=chart_json.get("slice_name"),
description="", description="",
chartType=get_standard_chart_type(chart_json["viz_type"]), chartType=get_standard_chart_type(
chartUrl=chart_json["url"], chart_json.get("viz_type", ChartType.Other.value)
),
chartUrl=chart_json.get("url"),
service=EntityReference( service=EntityReference(
id=self.context.dashboard_service.id.__root__, id=self.context.dashboard_service.id.__root__,
type="dashboardService", type="dashboardService",