可导出的类型
支持 看板(Dashboard)、图表(Charts)、数据集(Datasets)、SQL(saved_query)、数据库(Database connection) 单次或批量的导出,和单次导入操作
看板(Dashboard)
图表(Charts)
数据集(Datasets)
SQL (saved_query)
数据库(database connections)
导出内容
导出接口
dashboard | GET | api/v1/dashboard/export/?q=!(dashboard_id)&token=GMsud-wrK |
charts | GET | api/v1/chart/export/?q=!(slice_id)&token=N0PFreRTn |
datasets | GET | api/v1/dataset/export/?q=!(datasource_id)&token=s1GBGju-l |
saved_queries | GET | api/v1/saved_query/export/?q=!(sql_id)&token=2DDFzvjzF |
databases | GET | api/v1/database/export/?q=!(database_id)&token=F45_CB_DB |
导入接口
dashboard | POST | api/v1/dashboard/import |
charts | POST | api/v1/chart/import |
datasets | POST | api/v1/dataset/import |
saved_queries | POST | api/v1/saved_query/import |
databases | POST | /api/v1/database/import/ |
源码解读部分
-
Dashboards 导入核心逻辑
superset/dashboards/api.py
command = ImportDashboardsCommand()
superset/dashboards/commands/importers/dispatcher.py
command_versions = [
v1.ImportDashboardsCommand,
v0.ImportDashboardsCommand,
]superset/dashboards/commands/importers/v1/__init__.py
@staticmethod
def _import(
session: Session, configs: dict[str, Any], overwrite: bool = False
) -> None:
# discover charts and datasets associated with dashboards
'''
1. 发现与仪表板关联的图表和数据集
初始化集合chart_uuids和dataset_uuids,用于存储与仪表板相关联的图表和数据集的UUID。
遍历配置项,对于每个以"dashboards/"开头的文件名,
通过find_chart_uuids函数从仪表板的位置信息中提取图表UUID,
并通过find_native_filter_datasets函数从元数据中提取数据集UUID。
'''
chart_uuids: set[str] = set()
dataset_uuids: set[str] = set()
for file_name, config in configs.items():
if file_name.startswith("dashboards/"):
chart_uuids.update(find_chart_uuids(config["position"]))
dataset_uuids.update(
find_native_filter_datasets(config.get("metadata", {}))
)
# discover datasets associated with charts
'''
2. 发现图表关联的数据集
继续遍历配置项,对于每个以"charts/"开头且UUID在chart_uuids集合中的配置项,提取其数据集UUID,并添加到dataset_uuids集合中。
'''
for file_name, config in configs.items():
if file_name.startswith("charts/") and config["uuid"] in chart_uuids:
dataset_uuids.add(config["dataset_uuid"])
# discover databases associated with datasets
'''
3. 发现数据集关联的数据库
再次遍历配置项,对于每个以"datasets/"开头且UUID在dataset_uuids集合中的配置项,提取其数据库UUID,并添加到集合database_uuids。
'''
dat