Repository navigation
feat(c-abi): statement parameter binding + executed-statement query id - #165
Merged
Merged
Conversation
mani-mathur-arch
force-pushed
the
mani/c-abi-pupr-statement-surface
branch
from
July 14, 2026 12:29
53171cd to
518bd02
Compare
… bind)
Matches the shape a C-ABI host driver already produces (stringified value +
Databricks type name + optional name), building a SEA StatementParameter
directly instead of round-tripping through TypedValue — the binding path for a
host like the Go driver, whose backend.Param{Name, Type, Value} maps 1:1 to it
and covers every Databricks type (DECIMAL/TIMESTAMP/INTERVAL/VARIANT/GEOMETRY/
BINARY) and named params, which the typed positional binders cannot.
StatementSpec gains raw_params + param_raw; build_execute_params emits them
(positional ordinals assigned 1-based in push order, named passed through), with
raw-vs-typed and positional-vs-named-raw mutual exclusion enforced at build time
so a mixed markers array is rejected before the wire. Unit tests cover positional
ordinal assignment, named + NULL (VOID), and both exclusion rejections.
Co-authored-by: Isaac
Signed-off-by: Mani Kaustubh Mathur <mani.mathur@databricks.com>
The server statement (query) id crossed the C ABI only on the error path (KernelError.query_id). A host driver needs it on success too — for EXECUTE_STATEMENT telemetry and query-history correlation — so add kernel_executed_statement_query_id, returning the id as a borrowed NUL-terminated C string valid for the executed handle's lifetime (no per-call allocation, nothing for the caller to free; copy out to outlive the handle). NULL on a null or re-execute/close-invalidated handle, with a stored last error, matching the num_modified_rows staleness rule. The id is snapshotted as a CString on the C-ABI executed handle at construction (a server UUID, interior NULs stripped defensively). Adds an inherent ExecutedStatement::statement_id() so a concrete-handle consumer need not import the ExecutedStatementHandle trait. Covered by a wiremock success test (returns the server id, NULL after close) and C-smoke null-handle checks. Co-authored-by: Isaac Signed-off-by: Mani Kaustubh Mathur <mani.mathur@databricks.com>
Review-hardening pass on the PuPr statement surface (bind_parameter +
query_id), addressing the code-review findings:
- set_sql now clears ALL bound params (raw + typed positional/named), not
just raw_params, so a reused statement handle can never leak stale binds
into the next query. Previously a typed-then-raw reuse tripped the new
raw-vs-typed exclusion on leftover typed slots, and a shrinking-arity
typed reuse emitted stale high-ordinal markers — the "fresh parameter
set" contract now holds for every binding style. (Isaac MAJOR.)
- bind_parameter rejects an empty sql_type at bind with InvalidArgument,
symmetric with the NULL guard and param_named's empty-name reject,
rather than emitting "type":"" and failing opaquely at the server.
- query_id: drop the dead .replace('\0') so the CString fallback is live;
clarify the fallback contract in the comment.
- header: document the raw-bind lifecycle (accumulate; set_sql is the sole
reset, clears all binds; exclusion enforced at execute, bind returns
Success), define "typed params" by cross-referencing the bind_* family.
- fix the misleading query_id success-test comment (close(exec) frees the
handle; staleness comes from re-execute / parent close).
Tests: real re-execute invalidation test (query_id -> NULL +
InvalidStatementHandle); bind_parameter through the real C entry point
(empty-name -> positional, null -> NULL, null/empty type -> InvalidArgument)
+ positive bind->execute->query_id flow asserting normalization on the wire;
raw-vs-named-typed exclusion; empty-string-value-vs-NULL; set_sql clears
typed params on reuse. make check green (687 lib + 11 wiremock + C smoke).
Co-authored-by: Isaac
Signed-off-by: Mani Kaustubh Mathur <mani.mathur@databricks.com>
mani-mathur-arch
force-pushed
the
mani/c-abi-pupr-statement-surface
branch
from
July 14, 2026 18:25
518bd02 to
d22a8b6
Compare
mani-mathur-arch
changed the base branch from
mani/c-abi-statement-canceller
to
main
July 14, 2026 18:25
Empty commit to fire a fresh synchronize event so the pull_request:[main] gated workflows (Unit + doc tests) evaluate now that the PR base was retargeted from mani/c-abi-statement-canceller (landed as #163) to main. No content change; squashed away at merge. Co-authored-by: Isaac Signed-off-by: Mani Kaustubh Mathur <mani.mathur@databricks.com>
mani-mathur-arch
temporarily deployed
to
azure-prod
July 14, 2026 18:50 — with
GitHub Actions
Inactive
mani-mathur-arch
temporarily deployed
to
azure-prod
July 14, 2026 18:50 — with
GitHub Actions
Inactive
Contributor
Author
Code Review Squad — ReviewScore: 86/100 — MODERATE RISK Two new C-ABI surfaces for the Go driver's PuPr milestone: |
Second /full-review pass on PR #165 raised 6 quality findings (0 critical, score 86/100). All addressed here: - raw_params -> pub(crate): it holds the raw SEA wire struct StatementParameter (Serialize, not #[non_exhaustive]), so a public field would make evolving the wire a breaking change to the kernel crate. param_raw (strings only) stays the public surface. - statement_id_c now built via to_cstring_lossy (promoted to pub(crate)), so the success-path query id and the error-path KernelError.query_id share identical interior-NUL semantics (strip -> '?', never discard the whole id); corrected the contradictory field doc. - param_raw docstring now states the append-only / one-shot-per-query contract and notes duplicate-named-raw dedup is deferred to PR5 in lockstep with param_named (kept accumulate-by-design; push-time rejection intentionally not added). - sql() docstring narrowed to "bound parameters" with a scope note that statement_conf / row_limit survive a sql() call. - New wiremock tests: named raw param reaches the wire with a name key and no ordinal; non-UTF-8 rejected at bind for each of sql_type / name / value. make check clean (fmt + clippy -D warnings + full suite + C smoke); the two new wiremock tests pass. Isaac Review re-run on the changes: 0 findings. Co-authored-by: Isaac Signed-off-by: Mani Kaustubh Mathur <mani.mathur@databricks.com>
mani-mathur-arch
temporarily deployed
to
azure-prod
July 15, 2026 07:46 — with
GitHub Actions
Inactive
mani-mathur-arch
temporarily deployed
to
azure-prod
July 15, 2026 07:46 — with
GitHub Actions
Inactive
vikrantpuppala
approved these changes
Jul 17, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the two C-ABI surfaces the Go driver's PuPr milestone needs, as reviewable feature commits (originally stacked on #163; that has since landed on
main, so this now targetsmaindirectly).Commits
kernel_statement_bind_parameter— pre-marshalled generic parameter bind (host-supplied Databricks type name + stringified value, positional or named). Maps 1:1 to a C-ABI host's already-stringified params (e.g. the Go driver'sbackend.Param{Name, Type, Value}) and covers every Databricks type + named params, unlike the typed positional binders.StatementSpec.raw_params+param_raw;build_execute_paramsemits them with raw-vs-typed and positional-vs-named-raw mutual exclusion.set_sqlclearsraw_paramsso statement reuse doesn't accumulate stale binds.kernel_executed_statement_query_id— success-path accessor for the server statement/query id (the counterpart toKernelError.query_id, which crosses only on failure). Returns a borrowed C string valid for the executed handle's lifetime; NULL on a null/invalidated handle. A host uses it for EXECUTE_STATEMENT telemetry and query-history correlation.Testing
make checkclean (fmt + clippy -D warnings + full suite + C smoke). Coverage: raw-param build/exclusion/reset unit tests; wiremock success test forquery_id(returns the server id, NULL after re-execute invalidation); a positive-flow bind→execute→query_id wiremock reference; named-raw-param wire assertion (namekey, noordinal); non-UTF-8 rejection at bind for each of sql_type / name / value; and C-smoke null-handle checks for both new entry points.Review history
First pass (Isaac Review): 1 MAJOR — raw params accumulated across statement re-execute (
param_rawappends, no ordinal to overwrite by, no reset), so a reused statement handle would duplicate positional markers. Fixed by clearing all bind collections inset_sql(documented reuse contract + regression test). Re-ranmake checkclean.Second pass (
/full-review, score 86/100 — no critical/major/minor): 6 quality findings, all addressed ine91b1ed:raw_params→pub(crate)— it holds the raw SEA wire structStatementParameter(not#[non_exhaustive]), so a public field would make evolving the wire a breaking crate change;param_raw(strings only) stays the public surface.statement_id_cnow built viato_cstring_lossy(promoted topub(crate)), so the success-path query id and the error-pathKernelError.query_idshare identical interior-NUL semantics; corrected the contradictory field doc.param_rawdocstring now states the append-only / one-shot-per-query contract. Duplicate-named-raw dedup is deferred to PR5 in lockstep withparam_named(kept accumulate-by-design; push-time rejection intentionally not added — the consumer binds once per execute on a fresh handle).sql()docstring narrowed to "bound parameters" with a scope note thatstatement_conf/row_limitsurvive asql()call.Isaac Review re-run on the second-pass fixes: 0 findings.
This pull request and its description were written by Isaac.