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
aitools: add --param flag for parameterized SQL queries (#5336)
## Why
The Databricks SQL Statement Execution API supports named parameters
(`:name` markers in SQL plus a `parameters` payload), but the
experimental aitools `query` and `statement submit` commands never set
that field. Users who want to avoid SQL injection, sidestep
shell-quoting issues with dates and strings, or run typed bindings
(`DATE`, `INT`, `DECIMAL(...)`, etc.) currently have to drop down to raw
HTTP. This wires the field through.
## Changes
**Before:** no way to pass parameters. SQL had to inline every value as
a literal, with all the quoting and injection risk that implies.
**Now:** `--param` is a repeatable flag on `query`, `statement submit`,
and the multi-query batch path. Format:
- `--param name=value` (default type, server-side STRING)
- `--param name:TYPE=value` for typed bindings, e.g. `--param
since:DATE=2026-01-01`
Empty value (`--param opt=`) is sent as NULL via `omitempty`. Duplicate
names and missing `=` are rejected at flag-parse time. In batch mode the
same parameter set is applied to every statement.
Implementation:
- New `parseParams` helper in `experimental/aitools/cmd/params.go`, plus
parser unit tests.
- Plumbed `[]sql.StatementParameterListItem` through `executeAndPoll`,
`submitStatement`, `executeBatch`, and `runOneBatchQuery`.
- `--param` flag registered on both `newQueryCmd` and
`newStatementSubmitCmd`.
- Help text and examples updated.
No `NEXT_CHANGELOG.md` entry: this is still under `experimental aitools
tools`.
## Test plan
- [x] `./task checks` clean (tidy, whitespace, links, deadcode)
- [x] `./task lint-q` clean (0 issues)
- [x] `./task fmt` clean (no changes)
- [x] `go test ./experimental/aitools/...` passes
- [x] New unit tests for parser: typed, untyped, value with embedded
`=`/`:`, decimal types with parens, empty value, whitespace trimming,
error cases (no `=`, empty name, duplicates)
- [x] New mock-based tests confirming `Parameters` reaches
`ExecuteStatement` for `executeAndPoll`, `submitStatement`, and
`executeBatch`
- [ ] Manual smoke test against a real warehouse (`databricks
experimental aitools tools query --param name=alice "SELECT :name"`)
@@ -185,6 +201,7 @@ interactive table browser. Use --output csv to export results as CSV.`,
185
201
cmd.Flags().StringVarP(&warehouseID, "warehouse", "w", "", "SQL warehouse ID to use for execution")
186
202
cmd.Flags().StringSliceVarP(&filePaths, "file", "f", nil, "Path to a SQL file to execute (repeatable; pair with positional SQLs to run a batch)")
187
203
cmd.Flags().IntVar(&concurrency, "concurrency", defaultBatchConcurrency, "Maximum in-flight statements when running a batch of queries")
204
+
cmd.Flags().StringArrayVar(¶mFlags, "param", nil, "Named parameter, repeatable. Format: name=value (STRING) or name:TYPE=value (e.g. name:DATE=2026-01-01). Empty value is sent as NULL.")
188
205
// Local --output flag shadows the root command's persistent --output flag,
189
206
// adding csv support for this command only.
190
207
cmd.Flags().StringVarP(&outputFormat, "output", "o", string(sqlcli.OutputText), "Output format: text, json, or csv")
0 commit comments