Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pyo3/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ impl Session {
catalog=None,
schema=None,
session_conf=None,
complex_types_as_json=false,
intervals_as_string=false,
))]
#[allow(clippy::too_many_arguments)]
fn new(
Expand All @@ -91,6 +93,8 @@ impl Session {
catalog: Option<String>,
schema: Option<String>,
session_conf: Option<HashMap<String, String>>,
complex_types_as_json: bool,
intervals_as_string: bool,
) -> PyResult<Self> {
// Resolve auth_type: default to "pat" only when the caller
// also passed access_token. This keeps existing PAT callers
Expand Down Expand Up @@ -140,6 +144,14 @@ impl Session {
if let Some(conf) = session_conf {
builder = builder.session_conf(conf);
}
// Merge result-config knobs into one `ResultConfig` so two
// toggles don't clobber each other when both are set.
if complex_types_as_json || intervals_as_string {
let mut result = databricks_sql_kernel::ResultConfig::default();
result.complex_types_as_json = complex_types_as_json;
result.intervals_as_string = intervals_as_string;
builder = builder.result(result);
}
builder.open().await
})?;

Expand Down
35 changes: 30 additions & 5 deletions pyo3/src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ impl Statement {
/// to re-encode to a kernel ``TypedValue`` would be a lossy
/// round-trip; the kernel takes the string directly.
///
/// Named bindings, compound types (ARRAY/MAP/STRUCT), and
/// BINARY are not yet supported and raise
/// ``KernelError(code='InvalidArgument', ...)``. Bad value
/// literals (e.g. ``bind_param(1, "abc", "INT")``) also raise
/// at bind time, before ``execute()``.
/// Compound types (ARRAY/MAP/STRUCT) and BINARY are not yet
/// supported and raise ``KernelError(code='InvalidArgument',
/// ...)``. Bad value literals (e.g. ``bind_param(1, "abc",
/// "INT")``) also raise at bind time, before ``execute()``.
#[pyo3(signature = (ordinal, value_str, sql_type))]
fn bind_param(
&mut self,
Expand Down Expand Up @@ -126,6 +125,32 @@ impl Statement {
Ok(())
}

/// Bind a named parameter.
///
/// The SQL must reference the binding as ``:name``. The canonical
/// SEA proto marks ``StatementParameter.name`` as
/// ``openapi_required=true``; named binding is the spec-required
/// public form. ``value_str`` and ``sql_type`` follow the same
/// conventions as ``bind_param``.
#[pyo3(signature = (name, value_str, sql_type))]
fn bind_named_param(
&mut self,
py: Python<'_>,
name: String,
value_str: Option<String>,
sql_type: String,
) -> PyResult<()> {
let inner = alive_mut!(self, "Statement");
let typed =
parse_typed_value(&sql_type, value_str.as_deref()).map_err(|e| to_py_err(py, e))?;
inner
.stmt
.spec()
.param_named(name, typed)
.map_err(|e| to_py_err(py, e))?;
Ok(())
}

/// Wait-for-result execution. Blocks until the kernel finishes
/// polling and returns an `ExecutedStatement` with the result
/// stream ready to drain.
Expand Down
17 changes: 17 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,22 @@ pub struct ResultConfig {
/// ADBC and any other Arrow-native consumer should leave it
/// `false`.
pub complex_types_as_json: bool,

/// When `true`, `Interval(*)` and `Duration(*)` columns are
/// replaced with `Utf8` columns containing the canonical
/// Databricks text form (`"Y-M"` for YEAR-MONTH,
/// `"D HH:MM:SS.nnnnnnnnn"` for DAY-TIME / durations).
///
/// Motivation: pyarrow's Python bindings can't decode Arrow's
/// `month_interval` (id 21) — `.as_py()` / `.to_pylist()` /
/// `cast(string)` / `to_pandas()` all fail with KeyError or
/// `ArrowNotImplementedError`, killing the result set. Bindings
/// that hand Arrow batches to pyarrow Python (the PySQL kernel
/// backend) should set this `true`. Rust consumers and bindings
/// with their own interval decoder can leave it `false`.
///
/// Default `false`.
pub intervals_as_string: bool,
}

impl Default for ResultConfig {
Expand All @@ -399,6 +415,7 @@ impl Default for ResultConfig {
cloudfetch_link_prefetch_window: 10,
cloudfetch_max_chunks_in_memory: 4,
complex_types_as_json: false,
intervals_as_string: false,
}
}
}
Expand Down
Loading