Preview SQL Result validates and runs a SQL query, capped at 10,000 rows.
Parameters
----------
query : str
The SQL query to preview
params : dict, optional
Dictionary of parameters to use in the query, when using measure tables
will require AsOfDate or StartDate and EndDate
include_totals_row : bool, optional
When true, append a computed grand-total row to the result and tag it
via row_meta[].is_total. Default false.
Returns
-------
success : bool
True if completely successful, false if not
messages : list of str
List of human-readable error messages
error_code : str, optional
Present only on failure. A stable identifier for *why* the query was
refused, so non-human callers do not have to pattern-match the prose in
``messages``. Messages may be reworded freely; codes are contract.
Faults in the submitted query -- deterministic, so retrying the same
query is pointless: ``SQL_PARSE_ERROR``, ``SQL_DML_DDL_NOT_ALLOWED``,
``SQL_DISALLOWED_FUNCTION``, ``SQL_UNKNOWN_TABLE``,
``SQL_DATED_MEASURE_TABLE`` (the query names a dated measure table,
which measure cleanup drops; query the measure instead),
``SQL_MISSING_PARAMS``, ``SQL_MULTIPLE_STATEMENTS``,
``SQL_NOT_CATALOG_QUERY``, ``SQL_EXECUTION_TIMEOUT`` (the query is too
expensive to preview, though it can still be built and downloaded), and
``SQL_EXECUTION_ERROR``.
Faults on the server -- transient, and the same query may succeed on a
later attempt: ``SQL_EXECUTION_UNAVAILABLE`` (lost connection, deadlock,
lock wait, resource exhaustion) and ``SQL_CATALOG_UNAVAILABLE`` (the
logical catalog could not be read, so table names could not be
validated). Callers must not report these as caller mistakes.
num_rows : int
Number of rows in the result
columns : list of dict
List of columns in the result, each dict with name and type
data : list of list
List of rows in the result, each row is a list of values
Notes
-----
Queries are capped at 10,000 rows and a 180-second server-side execution
time, injected as a MySQL ``MAX_EXECUTION_TIME`` optimizer hint.
Only read-only catalog queries are accepted. Validation rejects DML/DDL and
the functions listed in ``DISALLOWED_FUNCTIONS`` (``SLEEP``, ``BENCHMARK``,
advisory-lock and replication-wait functions, ``LOAD_FILE``). Multiple
statements are refused separately, when the query is run rather than during
validation.
Comments -- including MySQL executable comments (``/*!...*/``) -- and
user-supplied optimizer hints (``/*+ ... */``) are stripped from the parsed
statement rather than rejected, so neither can carry SQL through to the
database. A caller's own ``MAX_EXECUTION_TIME`` value is read before the
hint is dropped, so it still tightens the bound.