Skip to content

feat(napi): accept ExecuteOptions on executeStatement — statementConf + queryTags - #75

Closed
msrathore-db wants to merge 3 commits into
mainfrom
msrathore/krn-statement-options
Closed

msrathore-db wants to merge 3 commits into
mainfrom
msrathore/krn-statement-options

Conversation

@msrathore-db

@msrathore-db msrathore-db commented May 25, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Surfaces two of the kernel StatementSpec knobs through napi so JS callers can pass per-statement Spark conf and query tags on Connection.executeStatement:

  • statementConf (Record<string, string>) — per-statement Spark conf overlay merged on top of the session-level sessionConf at execute time. Routes verbatim into StatementSpec::statement_conf().
  • queryTags (Record<string, string>) — serialised to comma-separated key:value matching the wire shape produced by NodeJS Thrift's serializeQueryTags (k1:v1,k2:v2 with backslash-escapes). Passing both queryTags and an explicit statementConf["query_tags"] raises InvalidArgument.

Implementation

  • New ExecuteOptions napi-object with optional statement_conf + query_tags maps
  • Connection.executeStatement(sql, options?) accepts the new arg; backward-compatible (existing executeStatement(sql) keeps working — napi-rs emits options?: ExecuteOptions | undefined | null on the JS d.ts)
  • build_merged_statement_conf helper merges the two maps and serialises query tags via the same algorithm Thrift uses
  • 13 Rust unit tests covering: no-options, both-empty, conf passthrough, tags serialisation (single + escape chars in keys/values), conflict-rejection, empty-tags-is-ignored, plus 5 byte-shape parity tests vs Thrift's serializeQueryTags algorithm (round 2)

Round 2 fixups (DA findings)

  • H1 clippy: .err().expect() → .expect_err() (commit cb3d989)
  • H2 rustfmt: long assert_eq! line break (commit cb3d989)
  • M1 docs: 3 stale "JSON-encoded" docstring references → "comma-separated key:value" matching Thrift wire shape (commit 9fbc009)
  • M4 parity: 5 new Rust unit tests pinning serialize_query_tags byte shape against Thrift's algorithm (commit 9fbc009)

Round 3 — cargo fmt --all chore-fixup

This PR contains a small chore(fmt): cargo fmt --all commit (e5c53da) covering pre-existing rustfmt drift in src/metadata/type_mapping.rs and src/reader/mod.rs. These files are NOT in F3's scope — they live on the F3 base branch msrathore/krn-status-fields and the same cargo +stable fmt --all -- --check failure reproduces on its tip 5265c75 (verified via fresh clone). The standing policy bars pushing to existing stack branches, so the canonical fix lands here to clear the workspace-wide gate; rustfmt is convergent and idempotent so the eventual upstream merge will reconcile mechanically. Pure mechanical fmt; no semantic change.

Post-fix gate status (workspace-wide, not the prior napi-scoped -p flag which masked these failures):

  • cargo +stable fmt --all -- --check EXIT 0
  • cargo clippy --all-targets -- -D warnings EXIT 0
  • cargo test --lib 37/37 pass

Deferred (separate PRs)

  • Positional / named parameters — need JS↔napi TypedValue mapping
  • Row limit, wait timeout — need kernel-side StatementSpec.row_limit / wait_timeout fields (currently only on internal ExecuteParams)
  • Async execute — kernel has submit() but napi needs new ExecutedAsyncStatement wrapper class
  • TIMESTAMP_NTZ/LTZ/VARIANT — Thrift gap, skip

Stack

PR 10 of the SEA stack, stacks on msrathore/krn-max-connections (PR #74). Corresponding NodeJS side at msrathore/sea-statement-options (PR #393).

Downstream fixes / reviewer note

Test plan

DA round-2 status

Round-2 fixups force-pushed; original approvals dismissed by branch protection. Re-review pending DA verdict.

msrathore-db added a commit that referenced this pull request May 26, 2026
…nf map

Add a Quick-reference section at the top mapping the six implementation
PRs (#74/#75/#76/#392/#393/#394) to features + test counts, plus a
Python comparison table showing how each feature maps to Python's
`use_sea=True` / `use_kernel=True` reference implementations.

Scope-down the Statement conf map + Query tags rows in Section 3 to
clarify the implementation is napi-only — the public NodeJS
`ExecuteStatementOptions` surface does not yet expose them. Wiring to
public API is a follow-up increment. Documented as Note 7. Addresses
DA's round-3 PR #77 review point on Statement conf map scope.

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
@msrathore-db

Copy link
Copy Markdown
Collaborator Author

Re-review requested — round-3 fixups landed; DA round-3 sign-off received.

Round-3 final tip: e5c53dacb261df83480923092a865d97b429edc4

This PR carries the F3 kernel-side work (ExecuteOptions.statementConf + queryTags + serialize_query_tags byte-shape Thrift parity). Three rounds of DA verification; all findings closed:

  • F3-H1 (clippy::err_expect) — fixed in cb3d989, replaced .err().expect(...) with .expect_err(...)
  • F3-H2 (rustfmt drift) — fixed in cb3d989 + final cargo +stable fmt --all sweep in e5c53da covering inherited src/metadata/type_mapping.rs + src/reader/mod.rs drift
  • F3-M1 (docs describing wire format) — replaced all 4 "JSON-encoded" references with accurate "comma-separated key:value with backslash escapes" descriptions
  • F3-M2 (Rust serializer dead-code decision) — option (b): kept Rust serializer + added 5 serialize_query_tags_matches_thrift_byte_shape_* parity tests pinning byte-equivalence with the JS serializeQueryTags
  • F3-M4 (parity-claim overreach) — added explicit "Tag-order caveat (M4 parity note)" doc block disclosing HashMap iteration-order non-determinism vs JS Object.keys insertion order; byte-identical parity scoped to the JS-adapter path

Gates: cargo clippy --all-targets -- -D warnings EXIT 0, cargo +stable fmt --all -- --check EXIT 0, cargo test --lib 37/37.

Co-authored-by: Isaac

@msrathore-db
msrathore-db force-pushed the msrathore/krn-max-connections branch from 0c5ca3f to 9c2ad89 Compare May 26, 2026 10:08
… + queryTags

Surfaces two of the kernel `StatementSpec` knobs through napi so
JS callers can pass per-statement Spark conf and query tags:

- `statementConf: Record<string, string>` — per-statement conf
  overlay; merged on top of the session-level `sessionConf` at
  execute time. The kernel's `StatementSpec::statement_conf()`
  setter accepts this verbatim and forwards to SEA `parameters` /
  Thrift `confOverlay`.
- `queryTags: Record<string, string>` — convenience wrapper that
  JSON-encodes the tag map into the `query_tags` conf overlay key,
  matching NodeJS Thrift's `serializeQueryTags` shape
  (`{"k":"v","k2":"v2"}`). Passing both `queryTags` and an explicit
  `statementConf["query_tags"]` raises `InvalidArgument` to
  surface the ambiguity to the caller.

Deferred (require kernel-side `StatementSpec` extensions or napi
TypedValue mapping — separate PRs):
- Positional / named parameters (TypedValue mapping)
- Row limit, wait timeout (need `StatementSpec.row_limit` /
  `wait_timeout` fields — currently only on internal `ExecuteParams`)
- Async execute (kernel has `submit()`; needs new napi wrapper class)

The new `ExecuteOptions` napi-object is `Option<…>` so existing
callers (`executeStatement(sql)`) keep working — napi-rs emits
`options?: ExecuteOptions | undefined | null` on the JS-side d.ts.
Empty maps (`{statementConf: {}}`) are treated the same as
omission so the wire shape stays stable for the common case.

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
DA round 1 findings on F3:

H1 (clippy `err_expect`): the
`merged_conf_rejects_dual_query_tags_definition` test used
`.err().expect(...)` which clippy 1.95+ flags. Switch to
`.expect_err(...)` per the suggested help text. Behaviour
unchanged; this was a stylistic clippy lint, not a logic
defect.

H2 (rustfmt): the
`merged_conf_query_tags_escape_backslash_in_keys` test
expressed a long `assert_eq!` on one line that exceeded
rustfmt's max width. Break across three lines per the cargo
fmt diff. Behaviour unchanged.

Why I missed these initially: my prior gate verification ran
inside a different worktree on the same branch (the F3b
worktree, which had an in-progress amend), so my local
`cargo clippy` + `cargo fmt --check` both reported green
there. The origin branch (this PR's HEAD `79bba34`) didn't
carry that amend. Lesson: never trust gate verification
across worktrees without confirming the working tree matches
the pushed SHA.

Verified post-fix:
- `cargo clippy --all-targets -- -D warnings` ✓
- `cargo +stable fmt --check` ✓
- `cargo test --lib` ✓ (32/32, same as before the fix)

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
DA round 2 findings on F3 (statement options + query tags):

M1 docs: prior docstring claimed `queryTags` is "JSON-encoded
into the conf overlay" — wrong. The actual implementation
serialises to comma-separated `key:value` matching NodeJS
Thrift's `serializeQueryTags` wire shape (`lib/utils/queryTags.ts`).
Updated three sites that carried the stale "JSON" reference:
- `ExecuteOptions` struct doc
- `query_tags` field doc
- `Connection::execute_statement` method doc + inline comment

M2 dead code: the napi `queryTags` field is intentionally
exported even though the JS adapter today pre-serialises via the
Thrift helper and writes into `statementConf["query_tags"]`
directly. The field stays as an alternate API surface for non-
NodeJS consumers (future pyo3 reuse, direct napi consumers); the
NodeJS adapter path is documented as the byte-identical-Thrift-
parity route. Updated the struct doc to spell out the dual paths
and their parity contracts.

M4 parity: added a struct-level "Tag-order caveat" doc block
that documents the HashMap-iteration-order vs `Object.keys`-
insertion-order divergence between the napi `queryTags` path
and Thrift's `serializeQueryTags`. The SEA server is order-
insensitive on conf values so the two are functionally
equivalent; callers needing byte-identical Thrift parity use the
JS adapter path. Added 5 new Rust unit tests pinning the per-tag
byte shape against the Thrift algorithm:
- single-tag deterministic case
- value-side escape ordering (`\` `:` `,`)
- key-side backslash-only escape (NOT colons/commas — Thrift
  asymmetry pinned so a future "uniformity" refactor fails the
  test)
- empty-map edge case
- multi-tag order-insensitive set equality

M3 lint: already clean — `cargo clippy --all-targets -- -D warnings`
passes locally on this branch's tip.

Test count: 32 → 37 (5 new). All passing.

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
@msrathore-db
msrathore-db changed the base branch from msrathore/krn-max-connections to main May 26, 2026 10:34
@msrathore-db
msrathore-db force-pushed the msrathore/krn-statement-options branch from e5c53da to be45ab2 Compare May 26, 2026 10:34
@msrathore-db

Copy link
Copy Markdown
Collaborator Author

Closing as superseded by #101, which is now the main-based kernel SEA parity mega PR for agent review. The branch is preserved and this can be reopened if we decide to return to smaller stacked reviews.

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