You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: harden sql_explain and altimate_core_validate input handling (#693)
* fix: [#691] harden sql_explain and altimate_core_validate inputs
Reject empty/placeholder SQL and warehouse names in sql_explain before
calling the warehouse. Add dialect-aware EXPLAIN (Snowflake, Postgres,
Redshift, MySQL, DuckDB, Databricks, ClickHouse). Translate driver
errors into actionable guidance.
Remove altimate_core_validate no-schema hard-gate so the engine runs
when schema is absent, with a has_schema flag in metadata.
Closes#691
* fix: address coderabbit review on #693
- translateExplainError now catches $N and :name bind errors too, not
just bare `?`. Detects a syntax-error keyword plus a bind token
delimited by whitespace or quotes, covering PG, Snowflake and Oracle
phrasings. Adds "there is no parameter $N" (PostgreSQL).
- NO_SCHEMA_NOTE documents the flat table-map shape actually accepted
by the tool, not the verbose SchemaDefinition shape.
- Regression tests added for $1, :name, and the NO_SCHEMA wording.
return`Warehouse ${JSON.stringify(warehouseName??"")} is not configured. Available warehouses: ${availableWarehouses.join(", ")}. Pass one of these as the 'warehouse' parameter, or omit it to use the default.`
298
+
}
299
+
return"No warehouses are configured. Run `warehouse_add` to set one up before calling sql_explain."
300
+
}
301
+
302
+
// Unsubstituted-placeholder compilation errors.
303
+
//
304
+
// Bind placeholders come in three flavours: positional `?` (MySQL / JDBC),
305
+
// numbered `$1`, `$2`, ... (PostgreSQL), and named `:name` (Oracle / SQLite /
306
+
// some SQLAlchemy dialects). Drivers phrase the resulting syntax error in
307
+
// many different ways — Snowflake says "unexpected ?", PostgreSQL says
308
+
// `syntax error at or near "$1"`, Oracle says `ORA-00911: invalid character`,
309
+
// etc. Rather than enumerate every phrasing, detect a bind-token next to a
310
+
// syntax-error keyword and translate them all to the same guidance.
return"SQL compilation error: the query contains an unsubstituted bind placeholder (`?`, `$1`, or `:name`). sql_explain does not support parameterized queries — inline the literal values before calling."
// Warehouse does not support EXPLAIN via a simple statement prefix —
444
+
// return a clear error rather than sending a bare statement to the
445
+
// driver. BigQuery needs a dry-run job, SQL Server needs SHOWPLAN_TEXT,
446
+
// Oracle needs DBMS_XPLAN, etc.
447
+
return{
448
+
success: false,
449
+
plan_rows: [],
450
+
error: `sql_explain is not supported for warehouse type ${JSON.stringify(warehouseType)}. This warehouse requires a different plan mechanism (e.g. dry-run API, SET SHOWPLAN_TEXT ON, or DBMS_XPLAN) that sql_explain cannot issue directly.`,
"Validate SQL syntax and schema references. Checks if tables/columns exist in the schema and if SQL is valid for the target dialect. IMPORTANT: Provide schema_context or schema_path — without schema, all table/column references will report as 'not found'.",
8
+
"Validate SQL syntax and schema references. Checks if tables/columns exist in the schema and if SQL is valid for the target dialect. If no schema_path or schema_context is provided, validation still runs but schema-dependent checks (table/column existence) are skipped — syntax and dialect checks still apply. For full validation, run `schema_inspect` first on the referenced tables or pass `schema_context` inline.",
9
9
parameters: z.object({
10
10
sql: z.string().describe("SQL query to validate"),
11
11
schema_path: z.string().optional().describe("Path to YAML/JSON schema file"),
0 commit comments