fix(schema): escape TDengine 3.4 reserved words 'value'/'label' and use column alias for ANOMALY_WINDOW

- schema: rename label -> is_anomaly, escape `value` as backtick
- detection/forecast: wrap subquery with SELECT ts, `value` AS v
  so ANOMALY_WINDOW/FORECAST receive non-keyword column name
- resolves [0x2600] syntax error and unblocks E2E pipeline on community tsdb 3.4.1
This commit is contained in:
张宗平
2026-06-11 16:08:34 +08:00
parent b05270802d
commit 031aa35604
3 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -28,8 +28,8 @@ def run_anomaly_window(conn, stable: str, algo: str) -> list[tuple[int, int]]:
sql = ( sql = (
f"SELECT _WSTART, _WEND " f"SELECT _WSTART, _WEND "
f"FROM (ANOMALY_WINDOW(value, \"algo={algo}\") " f"FROM (SELECT ts, `value` AS v FROM ds_{stable}) "
f"FROM ds_{stable})" f"ANOMALY_WINDOW(v, 'algo={algo}')"
) )
rows = conn.execute(sql) rows = conn.execute(sql)
+3 -3
View File
@@ -38,8 +38,8 @@ def run_forecast(
""" """
sql = ( sql = (
f"SELECT _FROWTS, _FLOW, _FHIGH " f"SELECT _FROWTS, _FLOW, _FHIGH "
f"FROM (FORECAST(value, \"algo={algo},rows={rows},conf={conf}\") " f"FROM (SELECT ts, `value` AS v FROM ds_{stable}) "
f"FROM ds_{stable})" f"FORECAST(v, 'algo={algo},rows={rows},conf={conf}')"
) )
try: try:
raw = conn.execute(sql) raw = conn.execute(sql)
@@ -83,7 +83,7 @@ def forecast_anomaly(
start_ts = min(frowtses) start_ts = min(frowtses)
end_ts = max(frowtses) end_ts = max(frowtses)
sql = f"SELECT ts, value FROM s_{stable} WHERE ts >= {start_ts} AND ts <= {end_ts}" sql = f"SELECT ts, `value` FROM s_{stable} WHERE ts >= {start_ts} AND ts <= {end_ts}"
raw = conn.execute(sql) raw = conn.execute(sql)
fmap = {f[0]: (f[1], f[2]) for f in forecasts} fmap = {f[0]: (f[1], f[2]) for f in forecasts}
+1 -1
View File
@@ -24,7 +24,7 @@ def create_supertable(conn, stable: str) -> None:
""" """
sql = ( sql = (
f"CREATE STABLE IF NOT EXISTS ds_{stable} " f"CREATE STABLE IF NOT EXISTS ds_{stable} "
f"(ts TIMESTAMP, value DOUBLE, label INT) " f"(ts TIMESTAMP, `value` DOUBLE, is_anomaly INT) "
f"TAGS (series_id INT)" f"TAGS (series_id INT)"
) )
conn.execute_no_result(sql) conn.execute_no_result(sql)