Skip to content

feat(c-abi): add kernel_statement_set_query_tags - #314

Merged
rahuls-db merged 1 commit into
mainfrom
feat/c-abi-query-tags
Sep 4, 2026
Merged

rahuls-db merged 1 commit into
mainfrom
feat/c-abi-query-tags

Conversation

@rahuls-db

@rahuls-db rahuls-db commented Sep 3, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds a C ABI setter for per-statement query tags:

KernelStatusCode kernel_statement_set_query_tags(kernel_statement_t* stmt,
                                                 const char* query_tags);

Query tags already exist in the kernel's Rust API (StatementSpec::query_tags)
and the PyO3/napi bindings, but the C ABI had no way to set them — the
statement C ABI only exposed set_sql / bind_* / execute. This blocks C ABI
consumers (the ODBC driver, and Go's kernel/SEA backend) from reaching parity
with the Thrift path, which already supports per-statement tags. This PR unblocks
them.

How

  • query_tags is the serialized wire string — comma-separated key:value
    pairs, a bare key (no colon) for a valueless tag, backslash-escaping :/,/\
    in values (e.g. team:eng,job:etl,production). This is exactly what the Go/Node
    connectors already build for the Thrift confOverlay["query_tags"] path, so a
    consumer passes it through unchanged rather than re-serializing.
  • The setter stores it verbatim under statement_conf["query_tags"], which the SEA
    execute path (statement::mutable) re-parses into the native query_tags array —
    the same seam Statement::query_tags and the bindings feed.
  • A non-empty value replaces the tags; an empty string clears them. Because
    statement_conf survives set_sql, a reused statement handle would otherwise carry
    an earlier query's tags into later executions — passing "" before re-executing
    resets them. (A deliberate divergence from the typed StatementSpec::query_tags,
    whose empty map is a no-op: this single C entry point makes empty = clear so the
    C surface can both set and reset without a second function.) A null handle/arg
    returns InvalidArgument.
  • Header is hand-written (include/databricks_kernel.h) — no cbindgen in v0.

Tests

  • C smoke test (tests/c/session_smoke.c): statement_set_query_tags(NULL) → InvalidArgument (runs under the make c-abi-test CI gate).
  • Seam tests (src/statement/mutable.rs): a raw statement_conf["query_tags"]
    string — including a bare key and an escaped colon — reaches
    ExecuteParams.query_tags as the native array; and removing the conf (the
    empty-string clear path) yields an empty array.
  • C ABI unit test (src/c_abi/statement.rs): null-handle guard.

Verified locally: cargo fmt --check, cargo build, cargo test (query-tags suite

  • the two new tests), cargo clippy --all-targets -D warnings, and make c-abi-test
    all pass.

Follow-ups (separate PRs)

  • Go: consume this from the kernel backend (read QueryTagsFromContext, serialize
    via the existing querytags.Serialize, call this setter at execute) — after the
    databricks-sql-kernel-bindings modules are rebuilt at a rev that includes this.
  • ODBC: statement-level tags via a vendor SQLSetStmtAttr attribute wired to this
    setter (session-level already shipped).

This pull request and its description were written by Isaac.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No issues identified by the review bot.

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Low · 1 Nit

Looks good — a clean, well-tested C ABI setter that mirrors the existing StatementSpec::query_tags seam (stores the pre-serialized wire string verbatim under statement_conf["query_tags"], which build_execute_params deserializes into the native SEA array). Null/UTF-8 guards and the storage→wire seam are covered by the new C, Rust-unit, and mutable.rs tests. Only two minor notes: no C-ABI path to clear tags on a reused handle (tags survive set_sql), and slightly misleading "clears" wording in the Rustdoc.

Other findings

  • ⚪ Nit — Minor doc wording: the Rustdoc says an empty string "clears/omits the tags (no-op)", but the implementation does not clear a previously-set value — it is purely a no-op (the header comment in databricks_kernel.h correctly says just "An empty string is a no-op"). The word "clears" could mislead a C consumer into believing set_query_tags(stmt, "") resets tags. Recommend dropping "clears" from the Rustdoc to match the header.

Comment thread src/c_abi/statement.rs Resolved
Comment thread src/c_abi/statement.rs Resolved
Expose per-statement query tags over the C ABI so consumers that go through
it (ODBC, Go's kernel backend) can reach parity with the Rust/PyO3/napi
query_tags surface. Those connectors already serialize tags to the
comma-separated key:value wire form for the Thrift confOverlay path; this
setter takes that same serialized string and stores it under
statement_conf["query_tags"], which the SEA execute path re-parses into the
native query_tags array (matching Statement::query_tags and the bindings).

A non-empty value replaces the statement's tags; an empty string clears them.
statement_conf survives set_sql, so a reused statement handle would otherwise
carry an earlier query's tags into later executions — passing "" resets them
(this is the C ABI's clear path; a deliberate divergence from the typed
StatementSpec::query_tags whose empty map is a no-op).

- src/c_abi/statement.rs: kernel_statement_set_query_tags — set/replace on a
  non-empty string, clear on empty; null handle/arg rejected.
- include/databricks_kernel.h: hand-written declaration.
- tests: C smoke null-guard (session_smoke.c), build_execute_params seam tests
  for both the raw serialized string reaching the native wire array and the
  cleared conf yielding an empty array, and a C ABI null-handle unit test.
- NEXT_CHANGELOG.md entry.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Rahul Singhal <rahul.singhal@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: 1 Low

Looks good — the C ABI setter is correct and well-covered: build_execute_params forwards only statement_conf["query_tags"] (no double-send), deserialize_query_tags is lenient/infallible, and the empty-clears semantics, null-handle guards, and escaping/bare-key seam are all tested. One low doc-lint nit: a public fn's doc links to a private function.

Comment thread src/c_abi/statement.rs
/// serialized wire form: comma-separated `key:value` pairs, with a bare `key`
/// (no colon) for a valueless tag, e.g. `team:eng,job:etl,production`; backslash
/// escapes the separators in a value (`\:`, `\,`, `\\`). This is the same string
/// [`crate::statement::spec::serialize_query_tags`] produces, so a host that

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — The doc comment on the public FFI function kernel_statement_set_query_tags contains an intra-doc link to [crate::statement::spec::serialize_query_tags], but serialize_query_tags is a private (non-pub) function in spec.rs. A public item linking to a private item triggers rustdoc's private_intra_doc_links lint (warn-by-default), so cargo doc (and anything running with RUSTDOCFLAGS=-D warnings) will warn/fail. This won't be caught by the documented CI gates (cargo fmt / cargo clippy / cargo test), since intra-doc link resolution happens during cargo doc, not doc-test compilation. Consider dropping the link to plain code font, or linking a public anchor instead.

@rahuls-db
rahuls-db added this pull request to the merge queue Sep 4, 2026
Merged via the queue into main with commit 21504ea Sep 4, 2026
24 of 26 checks passed

This branch was previously deployed

1 inactive deployment
azure-prod — 60350625 Deployed Sep 4, 2026 by oss-reviewer-bot[bot] via followup #1283
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.

2 participants