Repository navigation
feat(c-abi): typed result-config setters for client-side result knobs - #227
Conversation
The C ABI had no way to reach `ResultConfig`: `KernelSessionConfig` carried none, `build_session` never called `.result(...)`, and the only client-side result knob an ODBC/Go host could influence was `cloudfetch_max_chunks_in_memory`, smuggled as a magic string through `kernel_session_config_set_session_conf` and intercepted by `apply_client_result_overrides`. So `cloudfetch_enabled`, `complex_types_as_json`, `intervals_as_string`, and the prefetch/inline windows were all unreachable from the C ABI — leaving it behind its napi / pyo3 siblings and forcing callers to conflate client knobs with server session confs (the class of bug that produced #196). This adds a typed client-side result-config surface to the C ABI: - `kernel_session_config_set_result_config(cloudfetch_enabled, link_prefetch_window, max_chunks_in_memory, inline_max_chunks_in_memory)` — the CloudFetch / inline tuning group. A `0` on any usize field means "keep the kernel default", and `max_chunks_in_memory` is clamped to the existing `CLOUDFETCH_MAX_CHUNKS_CEILING` (256) with a warn. - `kernel_session_config_set_complex_types_as_json(enabled)` and `kernel_session_config_set_intervals_as_string(enabled)` — the two flat-text rendering booleans (parity with napi/pyo3). `KernelSessionConfig` now carries a `ResultConfig` (defaulted in `_new`), and `build_session` threads it through `.result(...)`. These knobs are client-side only and never reach the SEA wire. The legacy `cloudfetch_max_chunks_in_memory` magic string still works as a fallback, but the typed setter now wins: `apply_client_result_overrides` skips the string value when the field has already been moved off its default (still stripping the key so it can't leak to the wire). Deferred (tracked in #226): the typed `enable_metric_view_metadata` client property (kind-2 client-prop → server-conf mapping) and completing napi/pyo3 to cover all six ResultConfig knobs. Tests: - New `tests/v0_c_abi_result_config_wiremock.rs`: opening a session via the C ABI with `set_result_config(cloudfetch_enabled=false)` makes every ExecuteStatement carry `disposition = INLINE`; enabled / default carry `INLINE_OR_EXTERNAL_LINKS`. Proves the typed path reaches the wire. - `tests/c/session_smoke.c`: new setters compile, link, accept valid input (incl. over-ceiling clamp), and null-guard the handle. - New lib unit test: the typed setter wins over the legacy magic string, and the string key is still stripped. Refs #226 Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
…n-cache Addresses review feedback on the result-config surface: - The split (grouped set_result_config for 4 CloudFetch/inline knobs + two separate boolean setters for complex_types_as_json / intervals_as_string) was inconsistent — all six are fields of the same ResultConfig. Fold complex_types_as_json and intervals_as_string into kernel_session_config_set_result_config as two trailing bool params, so the whole result config is set atomically in one call. Removes kernel_session_config_set_complex_types_as_json and kernel_session_config_set_intervals_as_string. - Rename kernel_session_config_set_token_cache -> kernel_session_config_set_u2m_token_cache_config: the setter configures the U2M (browser-auth) token-cache POLICY (enable + passphrase), which PAT and M2M ignore — the old name implied a generic "token cache" and hid the U2M scope. The _config suffix aligns it with the other grouped policy setters (set_retry_config, set_result_config). Breaking ABI changes (pre-1.0; no external consumers pinned yet). Header, C smoke test, and the C-ABI wiremock test updated accordingly. The grouped setter and renamed symbol both compile and link from C (verified against the cdylib). Refs #226 Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
|
Revised per review feedback (2nd commit):
Breaking ABI changes, but pre-1.0 with no external consumers pinned. Header, C smoke test, and C-ABI wiremock test updated; the grouped setter + renamed symbol both compile and link from C against the cdylib. Full suite + clippy + fmt green. |
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — clean, well-tested addition. The typed ResultConfig C-ABI surface is wired correctly (field names match src/config.rs, builder threads .result(...) before apply_client_result_overrides runs at open, clamp/ceiling reuses the existing policy), the set_token_cache → set_u2m_token_cache_config rename is consistent across header/docs/impl with no dangling references, and coverage spans wiremock (wire disposition), C smoke, and a lib unit test. One low note on the default-value precedence heuristic.
| } | ||
| // The typed setter takes precedence: if the field has already been moved | ||
| // off its default (by `kernel_session_config_set_result_config` or a | ||
| // direct `ResultConfig`), don't let the legacy magic string clobber it. |
There was a problem hiding this comment.
🔵 Low — The typed-setter-wins precedence uses "field != ResultConfig::default()" as the proxy for "the typed setter was applied." This conflates two distinct cases:
- A host calls
kernel_session_config_set_result_config(...)but leavesmax_chunks_in_memory = 0(documented as "keep the kernel default"), so the field stays at 16. If that same host also passes the legacycloudfetch_max_chunks_in_memorymagic string, this guard sees the field still at its default and the legacy string wins — even though the caller explicitly used the typed path. - A host explicitly sets the typed
max_chunks_in_memory = 16(== default); a stray legacy string then silently overrides it.
Both are narrow (a host would have to mix the typed setter with the legacy string on the same knob), and the behavior is documented, so this is a limitation rather than a clear bug. But since set_result_config already writes c.result unconditionally, an explicit "typed setter was called" flag on KernelSessionConfig would make precedence exact rather than value-inferred. Worth considering if the legacy channel is expected to survive alongside the typed one for a while.
Reworks the C-ABI client-result surface twice over, per review:
1. Signature that never churns. A flat positional set_result_config
freezes its argument list, but ResultConfig is #[non_exhaustive] and
expected to grow — every new knob would force a breaking signature
change or a _v2. Replace it with a generic key/value setter:
kernel_session_config_set_client_conf(config, key, value)
This is the client-side counterpart to set_session_conf (server
confs): the signature is stable as knobs are added, and a host that
already has DSN / connection-string attributes can forward them in a
loop. Safety is recovered at runtime — an unknown key or unparseable
value is REJECTED with InvalidArgument (+ stored error), not silently
ignored. Its own key set is client-only, so a server conf like
ANSI_MODE passed here is rejected: the two channels stay separate,
which is the point of #226.
2. Enum, not magic strings. The kernel-side dispatch is now a
ClientConfKey enum (config.rs): the boundary string is parsed once via
ClientConfKey::parse (case-insensitive) and apply_client_conf matches
on the enum exhaustively — adding a variant won't compile until the
new knob is handled, so a knob can't be silently forgotten. as_str()
owns the canonical spellings in one place. The C-ABI boundary stays
const char* (the wire format is strings) and C/test literals are
unchanged — those are the real API input.
Also unifies the legacy path: apply_client_result_overrides now sweeps
session_conf for ANY recognised client key (via ClientConfKey::parse)
and delegates to the same validator, instead of the bespoke
cloudfetch_max_chunks_in_memory string parser. CLOUDFETCH_MAX_CHUNKS_CEILING
moved to config.rs next to ResultConfig.
Breaking ABI (pre-1.0). Header, C smoke test, and the C-ABI wiremock
test updated; set_client_conf's disposition-on-the-wire behaviour and
its reject-unknown-key / reject-bad-value paths are covered. Full suite
+ clippy + fmt green; C smoke test links and passes against the cdylib.
Refs #226
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
|
Reworked again per review (3rd commit) — two related changes: 1. Generic 2. Also unified the legacy path: Breaking ABI, pre-1.0. Coverage: |
There was a problem hiding this comment.
Verdict: 1 Medium · 1 Low
Solid, well-tested change — the generic set_client_conf key/value surface, the exhaustive ClientConfKey enum, and the reworked apply_client_result_overrides are internally consistent and carry good wiremock + C-smoke coverage. Two doc-vs-code mismatches: committed doc comments (source and test) still name three typed setters (set_result_config / set_complex_types_as_json / set_intervals_as_string) that were never implemented after the refactor to the single generic setter. Note also that the PR description's claim that the "typed setter wins over the legacy magic string" (a guard that skips already-moved-off-default fields) is not actually implemented — apply_client_result_overrides unconditionally re-applies any recognized session_conf key onto config.result, so a key present in both channels resolves to the legacy value, not the typed one; harmless for typical C-ABI callers who use only one channel, but worth reconciling with the description.
| token_cache: TokenCacheConfig, | ||
| /// Client-side result-management knobs (CloudFetch / inline streaming | ||
| /// tuning, flat-text rendering). Populated by | ||
| /// `kernel_session_config_set_result_config`, |
There was a problem hiding this comment.
🟡 Medium — The result field doc says it is "Populated by kernel_session_config_set_result_config, ..._set_complex_types_as_json, and ..._set_intervals_as_string", but none of those functions exist. The PR was refactored to a single generic kernel_session_config_set_client_conf(key, value) setter, and these three names were never implemented (a repo-wide grep finds them only inside doc comments). A reader of the source (or someone regenerating/consulting the header) will look for symbols that aren't there. Please update the doc to name the actual setter kernel_session_config_set_client_conf.
| // limitations under the License. | ||
|
|
||
| //! C-ABI wiremock tests for the typed result-config surface | ||
| //! (`kernel_session_config_set_result_config`). |
There was a problem hiding this comment.
🔵 Low — The module doc and the open_session_c_abi helper doc reference kernel_session_config_set_result_config, which does not exist — the tests themselves correctly call kernel_session_config_set_client_conf. Same stale-name issue as the source doc; worth fixing so the test's stated intent matches the API it exercises.
Review bot flagged doc comments that still named three setters removed in the refactor to the single generic `kernel_session_config_set_client_conf`: - `KernelSessionConfig::result` field doc named `set_result_config` / `set_complex_types_as_json` / `set_intervals_as_string`. - The C-ABI result-config wiremock test's module doc and `open_session_c_abi` helper doc named `set_result_config`. All updated to name the actual `set_client_conf`. Docs only — no code or behaviour change. Refs #226 Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
|
Addressed the review-bot findings (commit
Docs-only change; build + full suite + clippy + fmt still green. |
There was a problem hiding this comment.
Verdict: 1 Medium · 1 Low
Sound, well-tested change that gives the C ABI a real path to ResultConfig — the wiremock disposition test is good end-to-end evidence and the field/key parity is guarded by a unit test. Two things to weigh: (1) an unrelated breaking rename of the kernel_session_config_set_token_cache C-ABI symbol is bundled in (F1), and (2) the legacy session_conf channel silently overrides typed set_client_conf values, contrary to the PR description (F2). Separately, note the PR description describes an entirely different API (set_result_config / set_complex_types_as_json / set_intervals_as_string) than the code actually implements (set_client_conf key/value) — the code is internally consistent, but the description is stale and should be reconciled before merge.
| * EncryptedFileTokenCache (given the same passphrase). */ | ||
| KernelStatusCode kernel_session_config_set_token_cache(KernelSessionConfig* config, bool enabled, | ||
| const char* passphrase); | ||
| KernelStatusCode kernel_session_config_set_u2m_token_cache_config(KernelSessionConfig* config, |
There was a problem hiding this comment.
🟡 Medium — This PR renames an exported C-ABI symbol — kernel_session_config_set_token_cache → kernel_session_config_set_u2m_token_cache_config — in both the hand-maintained header and src/c_abi/session.rs:670. This is a breaking ABI change: any ODBC/Go host that links against the old symbol name will fail to resolve at load time.
The rename appears unrelated to this PR's stated purpose (client-side result-config knobs) and isn't mentioned in the PR description. If it's intentional, it deserves its own line in the changelog/description and a note that it breaks the previous symbol; if it slipped in from a rebase, it should be dropped from this PR. The rename itself is applied consistently (no dangling references to the old name remain), so this is a scoping/intent concern rather than a build break.
| key = %spelling, | ||
| value = %value, | ||
| error = %e.message, | ||
| "ignoring invalid client-side result knob in session_conf; keeping current value", |
There was a problem hiding this comment.
🔵 Low — apply_client_result_overrides runs during Session::open (session.rs:254), after the C-ABI typed set_client_conf values have already been folded into config.result. For every recognised client key still present in session_conf, it calls config.result.apply_client_conf(&spelling, &value) unconditionally — so a value smuggled through the legacy session_conf bag silently overwrites a value the host explicitly set via the typed set_client_conf path.
The PR description claims the opposite ("typed setter wins ... apply_client_result_overrides now skips it when the field has already been moved off its default"), and the description also references a set_result_config unit test proving typed-wins — neither the skip logic nor that test exist in the diff. This is only reachable when a host sets the same knob through both channels, and the outcome is just "legacy value applies" (no corruption), hence low. Worth either implementing the documented precedence or correcting the doc/description so the actual last-writer-wins behavior is clear.
(Anchored to the nearest changed line — see the description for the exact location.)
|
Addressed the latest review-bot findings — both were description↔code mismatches, now fixed by rewriting the PR description to match the final shape:
Earlier doc-comment findings (stale |
Summary
Closes the C-ABI half of #226. The C ABI previously had no way to reach
ResultConfig:KernelSessionConfigcarried none,build_sessionnever called.result(...), and the only client-side result knob an ODBC/Go host could influence wascloudfetch_max_chunks_in_memory— smuggled as a magic string throughkernel_session_config_set_session_confand intercepted byapply_client_result_overrides. Socloudfetch_enabled,complex_types_as_json,intervals_as_string, and the prefetch/inline windows were all unreachable from the C ABI (0/6 result knobs), leaving it behind its napi/pyo3 siblings and forcing callers to conflate client knobs with server session confs — the class of bug that produced #196.Changes
New generic client-side result-config setter on the C ABI:
set_session_conf(which carries server confs to the SEA wire).set_client_confsets client-side knobs that tune how the kernel fetches/buffers/post-processes results and are never sent to the server.ResultConfig(which is#[non_exhaustive]) grows new knobs, and so a host can forward DSN attributes in a loop. Safety is recovered at runtime: unknown keys and unparseable values are rejected withInvalidArgument(+ stored error), not silently ignored.ResultConfig:cloudfetch_enabled,cloudfetch_link_prefetch_window,cloudfetch_max_chunks_in_memory(clamped toCLOUDFETCH_MAX_CHUNKS_CEILING= 256 with awarn),inline_max_chunks_in_memory,complex_types_as_json,intervals_as_string. Booleans accept"true"/"false"; windows accept a positive integer. A server conf key (e.g.ANSI_MODE) is rejected here — the two channels stay separate (the Typed client-property surface for bindings: stop conflating client knobs with server session_conf #226 goal).Kernel-side dispatch is an enum, not magic strings. The boundary string is parsed once via
ClientConfKey::parse(case-insensitive) andResultConfig::apply_client_confmatches on the enum exhaustively — adding a variant won't compile until the new knob is handled.ClientConfKey::as_strowns the canonical spellings in one place.KernelSessionConfignow carries aResultConfig(defaulted in_new), threaded throughbuild_sessionvia.result(...).Legacy
session_confchannel, unified.apply_client_result_overridesnow sweepssession_conffor any recognised client key (viaClientConfKey::parse) and delegates to the sameapply_client_confvalidator, replacing the bespokecloudfetch_max_chunks_in_memoryparser. Semantics are last-writer-wins: a recognised client key left insession_confis applied (overwriting a value set viaset_client_conf) and then stripped so it can't reach the wire. This only matters if a host deliberately sets the same knob through both channels —set_client_confitself never touchessession_conf— and the outcome is simply "thesession_confvalue applies" (no corruption).CLOUDFETCH_MAX_CHUNKS_CEILINGmoved toconfig.rsnext toResultConfig.Also in this PR — a breaking C-ABI symbol rename (intentional):
kernel_session_config_set_token_cache→kernel_session_config_set_u2m_token_cache_config. The setter configures the U2M (browser-auth) token-cache policy (enable + passphrase), which PAT/M2M ignore; the old name hid that scope, and the_configsuffix matches the other grouped policy setters. Applied consistently across the header,src/c_abi/session.rs, and docs (no dangling references). Breaks any host linking the old symbol name — acceptable pre-1.0 (no external consumers pinned).Not in this PR (deferred, tracked in #226)
enable_metric_view_metadataclient property (kind-2 client-prop → server-conf mapping — currently callers must hand-type the dottedspark.sql.thriftserver.metadata.metricview.enabledkey).ResultConfigknobs (they currently expose 2).Test plan
tests/v0_c_abi_result_config_wiremock.rs— behavioral proof: a session opened over the C ABI withset_client_conf("cloudfetch_enabled","false")makes everyExecuteStatementcarry SEAdisposition = INLINE; enabled / default carryINLINE_OR_EXTERNAL_LINKS. Plus rejection coverage: unknown key, server-conf key, and unparseable bool all returnInvalidArgument.tests/c/session_smoke.c—set_client_confcompiles + links against the cdylib, accepts valid keys, clamps an over-ceiling value, and rejects unknown/server/bad-bool/null.src/config.rs,src/session.rs) —apply_client_confper-key parsing/validation/clamping and unknown-key rejection;apply_client_result_overridesapplies all six client keys fromsession_confand strips them while leaving server params untouched.cargo test,cargo clippy --all-targets -- -D warnings,cargo fmtall clean. (Run with--no-default-features --features tls-rustlsin this env due to a local OpenSSL 3.x /native-tlslinker mismatch unrelated to this change.)Refs #226
This pull request and its description were written by Isaac.