扫描
对数据源发起异步扫描,反射 schema、采样、逐字段定级。含任务状态轮询。
扫描是一个异步任务:发起后立即返回 task_id,引擎在后台反射 schema、采样数据、逐字段定级。你通过轮询任务状态拿进度和结果。
发起扫描
text
POST /api/v1/datasources/{ds_id}/scan需 superadmin / admin / dba 角色。
请求体
| 字段 | 类型 | 默认 | 说明 |
|---|---|---|---|
scan_type | string | full | 扫描范围,full 全量 |
scan_mode | string | precise | 模式,precise 精确 |
sample_rows | int | 50 | 每字段采样行数 |
priority | string | normal | 任务优先级 |
响应(202 Accepted)
json
{
"task_id": "a1b2c3d4-...",
"status": "queued",
"estimated_duration_sec": 420,
"tables_to_scan": 48
}202 不是 200
发起扫描返回 202 Accepted,表示任务已入队、尚未完成。拿到 task_id 后去轮询,不要假设结果已经就绪。
查询任务状态
text
GET /api/v1/scan-tasks/{task_id}响应
| 字段 | 类型 | 说明 |
|---|---|---|
task_id | string | 任务 ID |
datasource_id | string | 所属数据源 |
status | string | queued / running / completed / failed |
progress | int | 进度百分比 0–100 |
result_summary | object | 结果摘要(字段数、各级别分布等) |
error_message | string | null | 失败原因 |
started_at | datetime | null | 开始时间 |
completed_at | datetime | null | 完成时间 |
轮询示例
bash
curl https://your-dcg-host/api/v1/scan-tasks/$TASK_ID \
-H "Authorization: Bearer $TOKEN"json
{
"task_id": "a1b2c3d4-...",
"status": "running",
"progress": 63,
"result_summary": { "fields_done": 386, "fields_total": 612 }
}列出任务
text
GET /api/v1/scan-tasks?datasource_id={id}&status=running&page=1&size=20按数据源、状态过滤,分页返回。
扫描完成后,去 读分级结果。