Skip to content

feat(napi): TypedValue codec for positional params - #84

Closed
msrathore-db wants to merge 1 commit into
mainfrom
msrathore/krn-napi-typedvalue-codec
Closed

msrathore-db wants to merge 1 commit into
mainfrom
msrathore/krn-napi-typedvalue-codec

Conversation

@msrathore-db

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

Copy link
Copy Markdown
Collaborator

Summary

  • Add a JS↔napi TypedValue codec mirroring pyo3/src/params.rs, so the Node driver can bind positional parameters via Connection.executeStatement(sql, { positional_params }).
  • Expose a new ExecuteOptions napi object carrying positional_params: Option<Vec<TypedValueInput>> — each entry is a { sqlType, value } pair. Future per-statement knobs (named params, conf overlay, result format) can land non-breakingly inside this object.
  • Bind-time validation (DECIMAL precision/scale, non-finite FLOAT/DOUBLE, compound/BINARY rejection) is shared with pyo3, so the two language bindings see the same kernel-side error envelope.

C5 cluster context

This is PR-A of the C5 (params-basic-binding) chain:

  • PR-A (this PR): kernel-napi TypedValue codec + ExecuteOptions.positional_params.
  • PR-B (companion, NodeJS): wire executeStatement(sql, { ordinalParameters }) to this codec — independent open against databricks/databricks-sql-nodejs.
  • PR-C (companion, driver-test): SEA-gated parity tests via BackendComparator.forEachBackend against databricks/databricks-driver-test.

Each PR is independent and can be reviewed in parallel — they only depend on each other for the end-to-end live-warehouse run.

Decisions / scope

  • See `sea-workflow/decisions/2026-05-28-autonomous-parity-decisions.md` (audit rows 2.5-2.10 / 3.18-3.22, cluster C5).
  • The codec is string-in / string-parsed — the JS adapter is expected to stringify before calling. This matches the existing DBSQLParameter.toSparkParameter() shape on the Node side and the pyo3 binding's bind_param(sql_type: str, value: Optional[str]) shape.
  • BINARY is explicitly rejected at bind time with a message containing "BINARY" so the JS-side adapter can synthesize an `unhex(?)` workaround. Mirrors pyo3.
  • Cross-binding parity is asserted in the new `c5_ten_type_matrix_round_trips` unit test.

Quality gates

  • `cargo +stable build` ✅
  • `cargo +stable test` — 56 passed (28 new params + 4 new connection tests; pre-existing 24)
  • `cargo +stable fmt --all -- --check` ✅
  • `cargo +stable clippy --all-targets -- -D warnings` ✅
  • DCO sign-off
  • Conventional commit (`feat(napi): ...`)
  • `Co-authored-by: Isaac` trailer

Downstream fixes / reviewer note

  • databricks-sql-nodejs#399 is the pure TypeScript converter off main; the actual SEA execution wiring for positional params lands downstream in databricks-sql-nodejs#403.
  • Named params are completed by kernel feat(napi): expose named query parameters (param_named) on ExecuteOptions #98 and also consumed in databricks-sql-nodejs#403. The same downstream PR adds the JS-side arity/mixed-param validation reviewers may look for when reading this positional-only codec PR.

Test plan

  • 28 new params codec unit tests covering each of the 10 C5 types (INT, BIGINT, FLOAT, DOUBLE, STRING, BOOLEAN, DATE, TIMESTAMP, DECIMAL, BINARY-rejected) + lowercase / compound-overreach / NTZ / LTZ / VARIANT / INTERVAL / NULL / error-envelope edge cases.
  • 4 new connection-level tests for the `decode_positional_params` helper — empty vec, 10-type matrix, eager short-circuit on first bad entry, null→TypedValue::Null.
  • End-to-end live-warehouse run — covered by PR-C once PR-B wires up the JS adapter.

This pull request and its description were written by Isaac.

@gopalldb

Copy link
Copy Markdown
Collaborator

P0 — Must fix

GEOGRAPHY/GEOMETRY accepted in pyo3 but rejected in napi

  • napi/src/params.rs:65-115 — pyo3 has two arms that napi lacks:
    _ if is_geo_type_name(&upper, geo_wire::GEOGRAPHY) => parse_geography(&upper, s),
    _ if is_geo_type_name(&upper, geo_wire::GEOMETRY) => parse_geometry(&upper, s),
  • In napi these fall through to unsupported parameter SQL type: .... JS caller binding GEOGRAPHY(4326) gets InvalidArgument; equivalent Python caller gets a successful bind. Missing helpers:
    is_geo_type_name, parse_geography, parse_geometry, parse_ewkt_with_type_srid, extract_type_srid, split_ewkt.
  • Contradicts the PR's headline "Mirrors pyo3/src/params.rs line-for-line" + "same kernel-side error envelope" claims. The kernel-side TypedValue::Geography / TypedValue::Geometry enum + SEA payload mapper
    are ready; only the napi bind-side parser is missing.
  • Fix: port the geo arms verbatim from pyo3/src/params.rs:109-110, 124-150, 295-412 + tests 733-839. OR — if dropping geo is intentional — update the module docstring to drop the line-for-line claim and add
    an explicit "geo not yet wired from the JS surface" rejection arm so the user error is actionable.

P1 — Should fix

No regression-pinning test for the exact "BINARY" substring

  • napi/src/params.rs:885-894. PR description explicitly says the Node adapter relies on the message containing "BINARY" (case-sensitive) to synthesize the unhex(?) workaround. Test only does
    e.message.contains("BINARY"). A future refactor to "binary parameters are not supported" (lowercase) would silently break the Node adapter.
  • Fix: assert exact message string, or export pub const BINARY_REJECTION_MARKER: &str = "BINARY" so the contract is explicit.

extract_decimal_precision_scale doesn't reject trailing garbage after )

  • napi/src/params.rs:471-516. "DECIMAL(10,2)bogus" passes starts_with("DECIMAL(") then rfind(')') silently ignores bogus. Same in pyo3 — fix both for parity.
  • Fix: assert rparen + 1 == sql_type.len().

c5_ten_type_matrix_round_trips test only has 9 entries

  • napi/src/params.rs:988-1031 and napi/src/connection.rs:170-233 (decode_positional_params_10_type_matrix also has 9 + asserts len == 9). "10-type matrix" name overstates coverage — BOOLEAN, TIMESTAMP_NTZ,
    TIMESTAMP_LTZ, VARIANT, INTERVAL are tested elsewhere but not in the matrix.
  • Fix: rename to c5_eight_type_matrix_round_trips, OR expand to truly cover all 10 (and geo if P0 lands).

decode_positional_params_10_type_matrix doesn't assert order preservation

  • napi/src/connection.rs:170-233. Asserts len == 9 but doesn't iterate per slot. Positional binding is precisely about ordering — a future refactor with par_iter() wouldn't be caught.
  • Fix: matches! check per slot against expected TypedValue variant.

P2 — Minor

  • Stale module docstring (napi/src/params.rs:15-27 and napi/src/connection.rs:78-94) — claims "Mirrors pyo3 line-for-line"; either port geo (P0) or soften to "Mirrors for non-geo types".
  • Field naming relies on implicit camelCase conversion (napi/src/connection.rs:63-76). Project convention is consistent (mirrors database.rs), but a "JS sees this as positionalParams: Array<{ sqlType, value
    }>" docstring would save JS readers a lookup.
  • ExecuteOptions future-compat docstring could state explicitly that JS callers pass plain object literals so optional-field additions are wire-compatible.

Mirror pyo3/src/params.rs in the napi binding so the JS side can bind
positional parameters via Connection.executeStatement(sql, { positional_params }).
Each parameter is a { sql_type, value } pair — value is the string-encoded
literal or null for SQL NULL. The decoder parses through the same
validation surface pyo3 uses (DECIMAL precision/scale, non-finite
FLOAT/DOUBLE rejection, compound/BINARY rejection), so the two
language bindings stay aligned on what the kernel sees on the wire.

ExecuteOptions is exposed as a JS-visible object so future
statement-level knobs (named params, conf overlay, result format)
can land non-breakingly.

Tests cover the 10-type C5 matrix (INT, BIGINT, FLOAT, DOUBLE,
STRING, BOOLEAN, DATE, TIMESTAMP, DECIMAL, BINARY-rejected) plus
the eager-failure + null-value contracts at the helper level.

Co-authored-by: Isaac
Signed-off-by: Madhavendra Rathore <madhavendra.rathore@databricks.com>
@msrathore-db
msrathore-db force-pushed the msrathore/krn-napi-typedvalue-codec branch from 16b1bec to 88e5e97 Compare June 1, 2026 01:11
@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.

2 participants