Repository navigation
feat(c-abi): add kernel_statement_set_query_tags - #314
Conversation
6637ff1 to
a7c8069
Compare
There was a problem hiding this comment.
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.hcorrectly says just "An empty string is a no-op"). The word "clears" could mislead a C consumer into believingset_query_tags(stmt, "")resets tags. Recommend dropping "clears" from the Rustdoc to match the header.
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>
a7c8069 to
6035062
Compare
There was a problem hiding this comment.
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.
| /// 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 |
There was a problem hiding this comment.
🔵 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.
What
Adds a C ABI setter for per-statement 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 ABIconsumers (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_tagsis the serialized wire string — comma-separatedkey:valuepairs, 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/Nodeconnectors already build for the Thrift
confOverlay["query_tags"]path, so aconsumer passes it through unchanged rather than re-serializing.
statement_conf["query_tags"], which the SEAexecute path (
statement::mutable) re-parses into the nativequery_tagsarray —the same seam
Statement::query_tagsand the bindings feed.statement_confsurvivesset_sql, a reused statement handle would otherwise carryan earlier query's tags into later executions — passing
""before re-executingresets 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.include/databricks_kernel.h) — no cbindgen in v0.Tests
tests/c/session_smoke.c):statement_set_query_tags(NULL) → InvalidArgument(runs under themake c-abi-testCI gate).src/statement/mutable.rs): a rawstatement_conf["query_tags"]string — including a bare key and an escaped colon — reaches
ExecuteParams.query_tagsas the native array; and removing the conf (theempty-string clear path) yields an empty array.
src/c_abi/statement.rs): null-handle guard.Verified locally:
cargo fmt --check,cargo build,cargo test(query-tags suitecargo clippy --all-targets -D warnings, andmake c-abi-testall pass.
Follow-ups (separate PRs)
QueryTagsFromContext, serializevia the existing
querytags.Serialize, call this setter at execute) — after thedatabricks-sql-kernel-bindingsmodules are rebuilt at a rev that includes this.SQLSetStmtAttrattribute wired to thissetter (session-level already shipped).
This pull request and its description were written by Isaac.