feat: 完成 issue #29 TDengine 超级表 schema 依据点位字典自动生成
This commit is contained in:
@@ -120,6 +120,49 @@ def generate_subtable_ddls(
|
||||
return out
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 依据点位字典自动生成完整 schema(子任务 #29 交付入口)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def specs_from_point_dict_rows(rows: List[dict]) -> List[PointSpec]:
|
||||
"""把点位字典 CSV 行(edge-gateway 点位字典表头)转换为 PointSpec 列表。
|
||||
|
||||
与 `core/edge-gateway/point_dict/loader.py` 的 CSV 表头对齐:
|
||||
``device_id / point_id / unit / dataType``(兼容小写 ``data_type``)。
|
||||
其余列(name / sampleRate / qualityCode / opcNode / protocol)与
|
||||
schema 生成无关,宽松忽略;非法行按 ``from_dict`` 宽松兜底,
|
||||
不做静默丢弃(保持与点位数一致,便于外层校验定位)。
|
||||
|
||||
Args:
|
||||
rows: 点位字典行(每行一个测点,dict 键为 CSV 表头)。
|
||||
|
||||
Returns:
|
||||
与输入顺序一致的 PointSpec 列表。
|
||||
"""
|
||||
return [PointSpec.from_dict(raw) for raw in rows]
|
||||
|
||||
|
||||
def generate_schema(
|
||||
naming: TemplateNaming,
|
||||
points: List[PointSpec],
|
||||
retention_days: Optional[int] = None,
|
||||
) -> List[str]:
|
||||
"""依据点位字典一次性生成完整 TDengine schema(超级表 + 每测点子表)。
|
||||
|
||||
Args:
|
||||
naming: 模板命名器(决定超级表/子表名)。
|
||||
points: 点位字典(测点维度集合,可由 specs_from_point_dict_rows 得到)。
|
||||
retention_days: 数据保留天数(KEEP,可选)。
|
||||
|
||||
Returns:
|
||||
DDL 语句列表:第 0 条为超级表 CREATE STABLE,其余为子表
|
||||
CREATE TABLE ... USING ... TAGS(...),可直接按序执行。
|
||||
"""
|
||||
return [generate_supertable_ddl(naming, retention_days=retention_days)] + generate_subtable_ddls(
|
||||
naming, points
|
||||
)
|
||||
|
||||
|
||||
def build_batch_insert(
|
||||
naming: TemplateNaming,
|
||||
rows: List[dict],
|
||||
|
||||
Reference in New Issue
Block a user