Skip to content

aitools: add --param flag for parameterized SQL queries#5336

Open
simonfaltum wants to merge 2 commits into
mainfrom
simonfaltum/aitools-query-params
Open

aitools: add --param flag for parameterized SQL queries#5336
simonfaltum wants to merge 2 commits into
mainfrom
simonfaltum/aitools-query-params

Conversation

@simonfaltum
Copy link
Copy Markdown
Member

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

  • ./task checks clean (tidy, whitespace, links, deadcode)
  • ./task lint-q clean (0 issues)
  • ./task fmt clean (no changes)
  • go test ./experimental/aitools/... passes
  • New unit tests for parser: typed, untyped, value with embedded =/:, decimal types with parens, empty value, whitespace trimming, error cases (no =, empty name, duplicates)
  • 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")

Wires the Statement Execution API's named parameter support into the
experimental aitools query and statement submit commands. Use ":name"
markers in SQL and bind values with "--param name=value" or
"--param name:TYPE=value" (typed). Empty value is sent as NULL.

Co-authored-by: Isaac
@github-actions
Copy link
Copy Markdown
Contributor

Waiting for approval

Based on git history, these people are best suited to review:

  • @pietern -- recent work in experimental/aitools/cmd/

Eligible reviewers: @MarioCadenas, @Shridhad, @arsenyinfo, @atilafassina, @calvarjorge, @ditadi, @fjakobs, @igrekun, @jamesbroadhead, @keugenek, @lennartkats-db, @pffigueiredo, @pkosiec

Suggestions based on git history. See OWNERS for ownership rules.

@simonfaltum simonfaltum temporarily deployed to test-trigger-is May 27, 2026 10:44 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant