Skip to content

Commit bb9a8a0

Browse files
committed
fix(napi): preserve qualified interval parameters
Signed-off-by: cat23123 <58714163+cat23123@users.noreply.github.com>
1 parent 628abd6 commit bb9a8a0

4 files changed

Lines changed: 107 additions & 1 deletion

File tree

‎napi/NEXT_CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ layout, or npm publishing. Pure-kernel changes go in the root
2121

2222
### Fixed
2323

24+
- Added `ExecuteOptions.rawParams`, allowing Node.js callers to preserve
25+
pre-marshalled SQL type names such as `INTERVAL MONTH` and `INTERVAL DAY`
26+
instead of collapsing them through `TypedValue::Interval`.
27+
2428
---
2529
*Note: When making changes, please add your change under the appropriate
2630
section with a brief description. At release time, move the entries here

‎napi/index.d.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
* `rowLimit` (SEA `row_limit`) is exposed here and threaded onto the kernel
2121
* `StatementSpec`. `positionalParams` (`?`) and `namedParams` (`:name`)
2222
* carry bound query parameters, decoded via `params::parse_typed_value`.
23+
* `rawParams` carries pre-marshalled parameters whose SQL type must be
24+
* preserved verbatim on the SEA wire (for example `INTERVAL MONTH`).
2325
* (There is no `queryTimeoutSecs`: it abused the SEA `wait_timeout` inline-hold
2426
* window and was removed — a real per-statement timeout is `STATEMENT_TIMEOUT`.)
2527
*
@@ -85,6 +87,19 @@ export interface ExecuteOptions {
8587
* mutually exclusive at the SQL level (`?` vs `:name`).
8688
*/
8789
namedParams?: Array<NamedTypedValueInput>
90+
/**
91+
* Pre-marshalled SEA parameters. The SQL type and string value are sent
92+
* verbatim through `StatementSpec::param_raw`, bypassing `TypedValue`
93+
* conversion. This preserves qualified types such as `INTERVAL MONTH`
94+
* and `INTERVAL DAY` that the generic `TypedValue::Interval` cannot
95+
* represent.
96+
*
97+
* Omit `name` for positional parameters (ordinals are assigned 1-based
98+
* in array order); include it for named parameters. Raw parameters are
99+
* mutually exclusive with `positionalParams` / `namedParams`, and a raw
100+
* list cannot mix named and positional markers.
101+
*/
102+
rawParams?: Array<RawParameterInput>
88103
}
89104
/**
90105
* A named bound parameter — a [`TypedValueInput`] plus its `:name`. Kept a
@@ -675,6 +690,28 @@ export interface TypedValueInput {
675690
*/
676691
value?: string
677692
}
693+
/**
694+
* JS-visible pre-marshalled SEA parameter.
695+
*
696+
* Unlike [`TypedValueInput`], this shape bypasses the kernel's
697+
* `(sql_type, value) -> TypedValue` codec and preserves `sql_type` verbatim on
698+
* the SEA wire. This is required for qualified types such as
699+
* `INTERVAL MONTH` and `INTERVAL DAY`, whose qualifier cannot be represented
700+
* by the kernel's generic `TypedValue::Interval` variant.
701+
*
702+
* `name: None` denotes a positional marker; the kernel assigns 1-based
703+
* ordinals in array order. `name: Some(...)` denotes a named marker. A single
704+
* statement must not mix named and positional raw parameters, or raw and
705+
* typed parameters; `StatementSpec` enforces both rules before dispatch.
706+
*/
707+
export interface RawParameterInput {
708+
/** Named marker name. Omit for a positional marker. */
709+
name?: string
710+
/** Databricks SQL type name sent verbatim to SEA. */
711+
sqlType: string
712+
/** String-encoded value. `None` represents SQL NULL. */
713+
value?: string
714+
}
678715
/**
679716
* A single Arrow IPC stream payload encoding one record batch (plus
680717
* the schema header so the JS-side reader is stateless).

‎napi/src/connection.rs‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use databricks_sql_kernel::{Error as KernelError, Session, TypedValue};
3535

3636
use crate::async_statement::AsyncStatement;
3737
use crate::error::napi_err_from_kernel;
38-
use crate::params::{parse_typed_value, TypedValueInput};
38+
use crate::params::{parse_typed_value, RawParameterInput, TypedValueInput};
3939
use crate::runtime;
4040
use crate::statement::Statement;
4141
use crate::util::guarded;
@@ -56,6 +56,8 @@ use crate::util::guarded;
5656
/// `rowLimit` (SEA `row_limit`) is exposed here and threaded onto the kernel
5757
/// `StatementSpec`. `positionalParams` (`?`) and `namedParams` (`:name`)
5858
/// carry bound query parameters, decoded via `params::parse_typed_value`.
59+
/// `rawParams` carries pre-marshalled parameters whose SQL type must be
60+
/// preserved verbatim on the SEA wire (for example `INTERVAL MONTH`).
5961
/// (There is no `queryTimeoutSecs`: it abused the SEA `wait_timeout` inline-hold
6062
/// window and was removed — a real per-statement timeout is `STATEMENT_TIMEOUT`.)
6163
///
@@ -115,6 +117,17 @@ pub struct ExecuteOptions {
115117
/// positional is the documented-undocumented variant. The two are
116118
/// mutually exclusive at the SQL level (`?` vs `:name`).
117119
pub named_params: Option<Vec<NamedTypedValueInput>>,
120+
/// Pre-marshalled SEA parameters. The SQL type and string value are sent
121+
/// verbatim through `StatementSpec::param_raw`, bypassing `TypedValue`
122+
/// conversion. This preserves qualified types such as `INTERVAL MONTH`
123+
/// and `INTERVAL DAY` that the generic `TypedValue::Interval` cannot
124+
/// represent.
125+
///
126+
/// Omit `name` for positional parameters (ordinals are assigned 1-based
127+
/// in array order); include it for named parameters. Raw parameters are
128+
/// mutually exclusive with `positionalParams` / `namedParams`, and a raw
129+
/// list cannot mix named and positional markers.
130+
pub raw_params: Option<Vec<RawParameterInput>>,
118131
}
119132

120133
/// A named bound parameter — a [`TypedValueInput`] plus its `:name`. Kept a
@@ -187,6 +200,7 @@ fn build_statement(
187200
row_limit: Option<i64>,
188201
positional_params: Vec<TypedValue>,
189202
named_params: Vec<(String, TypedValue)>,
203+
raw_params: Vec<RawParameterInput>,
190204
) -> napi::Result<databricks_sql_kernel::Statement> {
191205
// Positional/named mutual-exclusivity is enforced in the kernel's
192206
// `build_execute_params` (StatementSpec dispatch), so every binding
@@ -221,6 +235,11 @@ fn build_statement(
221235
.param_named(name, value)
222236
.map_err(napi_err_from_kernel)?;
223237
}
238+
// Bind pre-marshalled params without converting through `TypedValue`, so
239+
// qualified type names (notably INTERVAL MONTH / INTERVAL DAY) survive.
240+
for raw in raw_params {
241+
stmt.spec().param_raw(raw.name, raw.sql_type, raw.value);
242+
}
224243
Ok(stmt)
225244
}
226245

@@ -300,6 +319,10 @@ impl Connection {
300319
.map(decode_named_params)
301320
.transpose()?
302321
.unwrap_or_default();
322+
let raw_params = options
323+
.as_mut()
324+
.and_then(|o| o.raw_params.take())
325+
.unwrap_or_default();
303326
// Pull the explicit `statement_conf` map and the `query_tags`
304327
// convenience map out of `options`. The kernel `StatementSpec`
305328
// owns the merge + serialisation: set the explicit conf first,
@@ -330,6 +353,7 @@ impl Connection {
330353
row_limit,
331354
positional_params,
332355
named_params,
356+
raw_params,
333357
)?
334358
// session lock released here
335359
};
@@ -384,6 +408,10 @@ impl Connection {
384408
.map(decode_named_params)
385409
.transpose()?
386410
.unwrap_or_default();
411+
let raw_params = options
412+
.as_mut()
413+
.and_then(|o| o.raw_params.take())
414+
.unwrap_or_default();
387415
let statement_conf = options.as_mut().and_then(|o| o.statement_conf.take());
388416
let query_tags = options.as_mut().and_then(|o| o.query_tags.take());
389417
guarded(async move {
@@ -398,6 +426,7 @@ impl Connection {
398426
row_limit,
399427
positional_params,
400428
named_params,
429+
raw_params,
401430
)?
402431
};
403432

@@ -452,6 +481,10 @@ impl Connection {
452481
.map(decode_named_params)
453482
.transpose()?
454483
.unwrap_or_default();
484+
let raw_params = options
485+
.as_mut()
486+
.and_then(|o| o.raw_params.take())
487+
.unwrap_or_default();
455488
let statement_conf = options.as_mut().and_then(|o| o.statement_conf.take());
456489
let query_tags = options.as_mut().and_then(|o| o.query_tags.take());
457490
guarded(async move {
@@ -473,6 +506,7 @@ impl Connection {
473506
row_limit,
474507
positional_params,
475508
named_params,
509+
raw_params,
476510
)?
477511
// session lock released here
478512
};
@@ -520,6 +554,10 @@ impl Connection {
520554
.map(decode_named_params)
521555
.transpose()?
522556
.unwrap_or_default();
557+
let raw_params = options
558+
.as_mut()
559+
.and_then(|o| o.raw_params.take())
560+
.unwrap_or_default();
523561
// Same conf + query_tags plumbing as `execute_statement`: the
524562
// kernel `StatementSpec` owns the merge + serialisation.
525563
let statement_conf = options.as_mut().and_then(|o| o.statement_conf.take());
@@ -546,6 +584,7 @@ impl Connection {
546584
row_limit,
547585
positional_params,
548586
named_params,
587+
raw_params,
549588
)?
550589
// session lock released here
551590
};

‎napi/src/params.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,29 @@ pub struct TypedValueInput {
6666
/// `VoidParameter` shape and the pyo3 binding's contract.
6767
pub value: Option<String>,
6868
}
69+
70+
/// JS-visible pre-marshalled SEA parameter.
71+
///
72+
/// Unlike [`TypedValueInput`], this shape bypasses the kernel's
73+
/// `(sql_type, value) -> TypedValue` codec and preserves `sql_type` verbatim on
74+
/// the SEA wire. This is required for qualified types such as
75+
/// `INTERVAL MONTH` and `INTERVAL DAY`, whose qualifier cannot be represented
76+
/// by the kernel's generic `TypedValue::Interval` variant.
77+
///
78+
/// `name: None` denotes a positional marker; the kernel assigns 1-based
79+
/// ordinals in array order. `name: Some(...)` denotes a named marker. A single
80+
/// statement must not mix named and positional raw parameters, or raw and
81+
/// typed parameters; `StatementSpec` enforces both rules before dispatch.
82+
#[allow(
83+
dead_code,
84+
reason = "exported via napi macro codegen; not called from Rust"
85+
)]
86+
#[napi(object)]
87+
pub struct RawParameterInput {
88+
/// Named marker name. Omit for a positional marker.
89+
pub name: Option<String>,
90+
/// Databricks SQL type name sent verbatim to SEA.
91+
pub sql_type: String,
92+
/// String-encoded value. `None` represents SQL NULL.
93+
pub value: Option<String>,
94+
}

0 commit comments

Comments
 (0)