mirror of
https://github.com/ThearchyHelios/AgentLab.git
synced 2026-11-20 22:02:00 +00:00
按行号取多行查询里的一格,重跑、核对时行序不定的照实标出来:sql_semantics.ordered / row_stable 认这一行重跑时还是不是同一行(最外层带 ORDER BY 的按位置认,一定只出一行的第 0 行认得住,别的行序不定)。口径账本的比对记下 ordered、one_row,指标标签按「同一行」认来自口径只在行认得住时成立,行序不定的标相关、写明原因;口径召回里两版都按行号取一格、查询又没有 ORDER BY 的指标记行序不定(changed 为空),召回待办上写「行序不定」,不按位置硬比;对账的多行对齐每一组先核对那一行的维度就是它,重跑时缺了一行、多出一行错位的记空值,不拿别的维度的数冒充
This commit is contained in:
@@ -9387,6 +9387,30 @@ def one_row(sql: str, dialect: str | None = None) -> bool:
|
||||
return _aggregating(root)
|
||||
|
||||
|
||||
def ordered(sql: str, dialect: str | None = None) -> bool:
|
||||
"""这条查询最外层带 ORDER BY(一段 SELECT 或 UNION 整体的):结果的行序由查询定,按行号取的那一格重跑时还是那一行(排序键
|
||||
相同的几行之间的先后另说,按位置认)。认不出的为假。"""
|
||||
from sqlglot import exp
|
||||
|
||||
read = _read(dialect)
|
||||
try:
|
||||
root, _ = _parse(_mysql_dashes(sql) if read == "mysql" and isinstance(sql, str) else sql, read)
|
||||
except Exception: # noqa: BLE001 - 解析不了就是认不出
|
||||
return False
|
||||
if not isinstance(root, (exp.Select, exp.Union)):
|
||||
return False
|
||||
order = root.args.get("order")
|
||||
return order is not None and bool(order.expressions)
|
||||
|
||||
|
||||
def row_stable(sql: str, row: int, dialect: str | None = None) -> bool:
|
||||
"""按行号取这条查询的第 row 行,重跑、核对时还是不是同一行:最外层带 ORDER BY 的按位置认;一定只出一行的(one_row)第 0 行
|
||||
认得住;别的(多行、又没有 ORDER BY)行序不定——库可以按任何顺序交回这些行,第 2 行重跑时可能是另一行。"""
|
||||
if ordered(sql, dialect):
|
||||
return True
|
||||
return row == 0 and one_row(sql, dialect)
|
||||
|
||||
|
||||
def output_names(sql: str, dialect: str | None = None, *, template: bool = False) -> list[str] | None:
|
||||
"""最外层选择列表各项的输出名(按位置;同 _result_columns,不展开 *:有 * 的为 None)。template 为真时 sql 是口径
|
||||
模板,按哨兵渲染之后认。解析不了、不是一段 SELECT 的为 None。"""
|
||||
|
||||
Reference in New Issue
Block a user