mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-18 16:41:57 +00:00
覆盖检查:现查没成功(大表全表 MIN / MAX 超时、库一时连不上)也记 LIVE_TTL_S,期间同一张表直接退回剖析、取值观察,不再每次白等 PROBE_TIMEOUT_S 秒(测试 test_a_failed_probe_is_not_retried_for_a_while);方言容器集成测试(scripts/dialect_it.py)加一段覆盖检查:只存当天的滚动表(DATE 列,MySQL / MariaDB 另有按文字 'YYYYMMDD' 存的),按运行当天现算的上周区间判成没有数据、区间包含当天只是别的条件筛空的不报,查询后和助手自查两个入口都核——PostgreSQL 16、MySQL 8.4、MariaDB 11、Oracle Free 23 全过
This commit is contained in:
@@ -52,6 +52,9 @@ MAX_COLUMNS = 12
|
||||
#: MAX。滚动表一天才换一次数据,几分钟的旧不影响判断;查不成的、退回剖析的不记
|
||||
LIVE_TTL_S = 300.0
|
||||
_LIVE: dict[tuple[Any, ...], tuple[float, Any]] = {}
|
||||
#: 现查没成功(大表全表 MIN / MAX 超时、库一时连不上)也记 LIVE_TTL_S:这段时间里同一张表直接退回剖析、取值观察,
|
||||
#: 不然取数 agent 连查几次、每次结果里有整列 0,每次都要白等 PROBE_TIMEOUT_S 秒才退回
|
||||
_PROBE_FAILED = object()
|
||||
|
||||
#: 给人和模型看的说法
|
||||
NO_DATA_MESSAGE = "{columns}查的是 {window},但 {table} 的 {column} {data}:这些 0 不代表这段时间真的是 0,是这段时间表里没有数据{basis}"
|
||||
@@ -398,9 +401,12 @@ async def _range(source: Any, flt: _Filter, read: str | None, cache: Cache, fact
|
||||
return cache.ranges[key]
|
||||
live = (getattr(source, "id", None), getattr(source, "snapshot_id", None), *key)
|
||||
held = _LIVE.get(live)
|
||||
failed_before = False
|
||||
if held is not None and held[0] > time.monotonic():
|
||||
cache.ranges[key] = held[1]
|
||||
return held[1]
|
||||
if held[1] is not _PROBE_FAILED:
|
||||
cache.ranges[key] = held[1]
|
||||
return held[1]
|
||||
failed_before = True
|
||||
table = flt.table.copy()
|
||||
table.set("alias", None)
|
||||
ident = flt.column.this.copy() if isinstance(flt.column.this, exp.Identifier) \
|
||||
@@ -408,7 +414,7 @@ async def _range(source: Any, flt: _Filter, read: str | None, cache: Cache, fact
|
||||
column = exp.Column(this=ident)
|
||||
sql = (f"SELECT {exp.Min(this=column.copy()).sql(dialect=read)} AS lo, "
|
||||
f"{exp.Max(this=column.copy()).sql(dialect=read)} AS hi FROM {table.sql(dialect=read)}")
|
||||
found = await _probe(source, sql)
|
||||
found = None if failed_before else await _probe(source, sql)
|
||||
out: _Range | None = None
|
||||
if found is not None:
|
||||
values, kinds = found
|
||||
@@ -422,13 +428,19 @@ async def _range(source: Any, flt: _Filter, read: str | None, cache: Cache, fact
|
||||
elif facts is not None:
|
||||
out = await _fallback(flt, facts)
|
||||
cache.ranges[key] = out
|
||||
if out is not None and out.basis == "live":
|
||||
if len(_LIVE) > 512:
|
||||
_LIVE.clear()
|
||||
_LIVE[live] = (time.monotonic() + LIVE_TTL_S, out)
|
||||
if found is None and not failed_before:
|
||||
_remember(live, _PROBE_FAILED)
|
||||
elif out is not None and out.basis == "live":
|
||||
_remember(live, out)
|
||||
return out
|
||||
|
||||
|
||||
def _remember(live: tuple[Any, ...], value: Any) -> None:
|
||||
if len(_LIVE) > 512:
|
||||
_LIVE.clear()
|
||||
_LIVE[live] = (time.monotonic() + LIVE_TTL_S, value)
|
||||
|
||||
|
||||
async def _fallback(flt: _Filter, facts: Facts) -> _Range | None:
|
||||
"""现查不成:退回剖析记下的范围(date_ranges),再不然取值观察的最新日期(freshness,只知道最晚那一头)。"""
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user