fix(harness): correct truncated signalling for sql preview offset>0
When offset>0 the wrapper added an outer LIMIT N, so run_controlled's _inject_limit bailed (a LIMIT IS present) and truncated was always False — AGGrid could never detect more rows. Fix: for offset>0 probe with LIMIT (N+1) OFFSET M, then compute truncated = len(rows) > N in do_run and slice back to N. offset==0 path unchanged (delegates to extracted _run_transport helper). JSON still reports the user's requested limit N and correct truncated. Adds 3 tests exercising the real do_run offset>0 path (N+1 -> truncated True, N -> False, offset==0 verbatim). 222/222 passing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -102,15 +102,8 @@ def do_explain(cfg, sql: str):
|
||||
return explain(_ro_engine(cfg), sql, timeout_ms=cfg.execution.statement_timeout_ms)
|
||||
|
||||
|
||||
def do_run(cfg, sql: str, *, limit: int, offset: int = 0):
|
||||
"""Esecuzione controllata secondo il transport configurato (direct|rest)."""
|
||||
from tht.execute.limit import inject_limit_offset
|
||||
|
||||
# Inject OFFSET (and an outer LIMIT) via subquery wrapping when offset > 0.
|
||||
# When offset == 0 we let the inner runners apply LIMIT directly (existing path).
|
||||
if offset:
|
||||
sql = inject_limit_offset(sql, limit=limit, offset=offset)
|
||||
|
||||
def _run_transport(cfg, sql: str, *, limit: int):
|
||||
"""Dispatch all'esecutore controllato secondo il transport (direct|rest)."""
|
||||
if cfg.database.transport == "rest":
|
||||
from tht.rest.execute import run_controlled_rest
|
||||
|
||||
@@ -122,6 +115,34 @@ def do_run(cfg, sql: str, *, limit: int, offset: int = 0):
|
||||
)
|
||||
|
||||
|
||||
def do_run(cfg, sql: str, *, limit: int, offset: int = 0):
|
||||
"""Esecuzione controllata secondo il transport configurato (direct|rest).
|
||||
|
||||
Per offset == 0: path invariato (LIMIT iniettato dall'esecutore via AST, +1 per
|
||||
rilevare il troncamento).
|
||||
|
||||
Per offset > 0: la query viene wrappata in `SELECT * FROM (...) LIMIT (N+1) OFFSET M`.
|
||||
Il +1 e' essenziale: l'esecutore vede gia' un LIMIT esterno, quindi il suo
|
||||
`_inject_limit` non inietta nulla (bail perche' un LIMIT E' PRESENTE, non assente) e
|
||||
non rileverebbe mai il troncamento. Recuperando N+1 righe qui calcoliamo noi
|
||||
`truncated = len(rows) > N` e ritagliamo a N. NON rimuovere il LIMIT del wrapper
|
||||
pensando sia ridondante: e' l'unico cap effettivo per il path con offset.
|
||||
"""
|
||||
if offset == 0:
|
||||
return _run_transport(cfg, sql, limit=limit)
|
||||
|
||||
from dataclasses import replace
|
||||
|
||||
from tht.execute.limit import inject_limit_offset
|
||||
|
||||
probe_limit = limit + 1
|
||||
wrapped = inject_limit_offset(sql, limit=probe_limit, offset=offset)
|
||||
# limit=probe_limit cosi' l'esecutore ritaglia a N+1 (non a N) e ci lascia la riga sonda.
|
||||
result = _run_transport(cfg, wrapped, limit=probe_limit)
|
||||
truncated = len(result.rows) > limit
|
||||
return replace(result, rows=result.rows[:limit], truncated=truncated)
|
||||
|
||||
|
||||
@sql_app.command("validate")
|
||||
def validate_cmd(
|
||||
file: Path = typer.Argument(..., help="File SQL da validare."),
|
||||
|
||||
Reference in New Issue
Block a user