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
36 changes: 29 additions & 7 deletions src/client/sea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,16 +439,37 @@ impl SeaRestTransport {
) -> Result<ExecuteResponse> {
let url = format!("{}/statements", self.base_url());

// Select the result disposition per statement from the
// connection-level CloudFetch setting, mirroring the reference
// JDBC driver's SEA path (`DatabricksSdkClient.getRequest`:
// `cloudFetch ? INLINE_OR_EXTERNAL_LINKS : INLINE`). This is the
// authoritative mechanism for disabling cloud-fetch on SEA —
// there is NO `CAN_CLOUD_DOWNLOAD` session conf (the server
// rejects it at ExecuteStatement with `CONFIG_NOT_AVAILABLE`,
// issue #196).
//
// `INLINE`: the server serves every result inline (Arrow bytes in
// the response `attachment`), regardless of size. `format` stays
// `ARROW_STREAM` — the kernel's inline reader consumes Arrow IPC
// from the attachment (the SEA inline-Arrow path), so unlike JDBC
// we keep Arrow rather than switching to `JSON_ARRAY`.
//
// `INLINE_OR_EXTERNAL_LINKS` (the CloudFetch-enabled default): not
// a public API disposition but enables returning all chunk links
// in a single response (requires the JDBC user agent). Once
// EXTERNAL_LINKS supports multi-link responses, switch back to it.
let disposition = if self.config.cloudfetch_enabled {
"INLINE_OR_EXTERNAL_LINKS"
} else {
"INLINE"
};
let request_body = ExecuteStatementRequest {
warehouse_id: self.warehouse_id.clone(),
statement: sql.to_string(),
session_id: Some(session_id.to_string()),
catalog: params.catalog.clone(),
schema: params.schema.clone(),
// TODO: INLINE_OR_EXTERNAL_LINKS is not a public API disposition but enables
// returning all chunk links in a single response (requires JDBC user agent).
// Once EXTERNAL_LINKS supports multi-link responses, switch back to it.
disposition: "INLINE_OR_EXTERNAL_LINKS".to_string(),
disposition: disposition.to_string(),
format: "ARROW_STREAM".to_string(),
wait_timeout: params.wait_timeout.clone(),
on_wait_timeout: params.on_wait_timeout.clone(),
Expand Down Expand Up @@ -1052,12 +1073,13 @@ impl Transport for SeaRestTransport {
// Inline-Arrow path: bytes must be present in `attachment`.
// If the server returned an external_links response on what
// we expected to be the inline path, surface a clear error
// (probably the session conf didn't take effect server-side).
// (probably the `disposition = INLINE` on the execute request
// didn't take effect server-side).
let bytes = chunks_response.attachment.ok_or_else(|| {
Error::data_loss().message(format!(
"Inline chunk {} response missing `attachment` field — \
server may have ignored the can_cloud_download session \
conf and returned a CloudFetch response. Body: {}",
server may have ignored the INLINE disposition and \
returned a CloudFetch response. Body: {}",
chunk_index, body
))
})?;
Expand Down
30 changes: 26 additions & 4 deletions src/client/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,35 @@ pub(crate) struct TransportConfig {
pub poll_timeout: Duration,
/// Interval between status polls (default: 500ms).
pub poll_interval: Duration,
/// Whether CloudFetch (cloud-storage-backed result download via
/// external links) is enabled for this session.
///
/// This is a **connection-level** setting — like the reference JDBC
/// driver's `EnableQueryResultDownload`, it is read once at session
/// open and applied to every `ExecuteStatement`, not toggled per
/// statement. It selects the SEA `disposition` sent on each execute:
/// `true` → `INLINE_OR_EXTERNAL_LINKS` (results may come back as
/// external CloudFetch links), `false` → `INLINE` (the server serves
/// every result inline, regardless of size).
///
/// **Why this is `disposition`, not a session conf.** SEA has no
/// `CAN_CLOUD_DOWNLOAD` session conf — sending one is accepted at
/// `CreateSession` but rejected at the first `ExecuteStatement` with
/// `CONFIG_NOT_AVAILABLE` (see issue #196). Both the JDBC and Thrift
/// reference drivers control cloud-fetch per request (SEA
/// `disposition` / Thrift `canDownloadResult`), never via session
/// conf; this mirrors JDBC's SEA path
/// (`DatabricksSdkClient.getRequest`).
pub cloudfetch_enabled: bool,
}

impl Default for TransportConfig {
fn default() -> Self {
Self {
poll_timeout: Duration::from_secs(600),
poll_interval: Duration::from_millis(500),
// Mirror `ResultConfig::default().cloudfetch_enabled`.
cloudfetch_enabled: true,
}
}
}
Expand Down Expand Up @@ -342,10 +364,10 @@ pub(crate) trait Transport: Send + Sync + std::fmt::Debug {
/// `row_offset`).
///
/// Used by the inline-Arrow streaming path that lights up when
/// `ResultConfig.cloudfetch_enabled == false` (i.e. SEA's
/// `can_cloud_download=false` session conf). The server-side
/// response for this path carries Arrow IPC bytes inline in
/// `attachment` rather than emitting `external_links`.
/// `ResultConfig.cloudfetch_enabled == false` (i.e. the execute
/// request was sent with SEA `disposition = INLINE`). The
/// server-side response for this path carries Arrow IPC bytes inline
/// in `attachment` rather than emitting `external_links`.
///
/// Per the bounded SEA API contract for OSS drivers:
/// - `chunk_index` is derived from the *previous* chunk's
Expand Down
99 changes: 63 additions & 36 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,12 +820,18 @@ pub struct ResultConfig {
/// large result sets via presigned URLs). Default: `true`.
///
/// Setting this to `false` mirrors JDBC's `EnableQueryResultDownload=0`
/// behaviour. At session-create time the kernel sets the
/// `can_cloud_download` session conf to `"false"` so SEA serves
/// **all** result sizes via the inline-Arrow path, regardless of
/// result size — see the SEA inline-Arrow design (DD1) for the wire
/// contract. Users who need inline-only behaviour (e.g. workspaces
/// without cloud-storage egress) should set this to `false`.
/// behaviour. It is a **connection-level** setting: read once at
/// [`Session::open`](crate::Session::open) and applied to every
/// statement by selecting the SEA `disposition` on each
/// `ExecuteStatement` (`false` → `INLINE`, so SEA serves **all**
/// result sizes via the inline-Arrow path regardless of size). This
/// matches how the JDBC and Thrift reference drivers control
/// cloud-fetch (per request), and is deliberately **not** expressed
/// as a session conf — SEA has no `CAN_CLOUD_DOWNLOAD` conf and
/// rejects one at ExecuteStatement with `CONFIG_NOT_AVAILABLE`
/// (issue #196). Users who need inline-only behaviour (e.g.
/// workspaces without cloud-storage egress) should set this to
/// `false`.
///
/// Disabling CloudFetch routes results to the inline-Arrow
/// path. The kernel today supports the **single-attachment**
Expand Down Expand Up @@ -967,31 +973,26 @@ pub struct SessionConfig {
/// the *client-side* knobs; this map carries everything else.
///
/// The kernel passes user-supplied entries through unchanged,
/// **except** for keys synthesised from typed client-side
/// knobs that have a wire counterpart:
///
/// - [`ResultConfig::cloudfetch_enabled`] `= false` synthesises
/// `can_cloud_download = "false"` (case-insensitive on the
/// key) so SEA serves results inline. If the user already
/// supplied a non-empty `can_cloud_download` value under
/// any casing, the user's value wins and no synthesis
/// happens. The synthesis path also purges empty-string
/// case-variants the user may have left in the map (the
/// server's behaviour for empty values is undefined) so the
/// wire body carries at most one `can_cloud_download`-shaped
/// key.
/// after filtering them against the kernel allowlist (see
/// [`filter_session_conf`] / [`SESSION_CONF_ALLOWLIST`]). The
/// kernel does not synthesise any entries here from typed
/// client-side knobs.
///
/// Future typed-knob → session_conf synthesis follows the
/// same pattern (the wrapping `inject_default(...)` helper can
/// be lifted out once a second knob lands here).
/// In particular, [`ResultConfig::cloudfetch_enabled`] is **not**
/// expressed as a session conf: SEA has no `CAN_CLOUD_DOWNLOAD`
/// conf (it is accepted at CreateSession but rejected at the first
/// ExecuteStatement with `CONFIG_NOT_AVAILABLE`, issue #196).
/// CloudFetch-disable is instead applied per-statement via the SEA
/// `disposition` field, matching the JDBC / Thrift reference
/// drivers. A stray caller-supplied `can_cloud_download` is dropped
/// by [`filter_session_conf`] (it is not allowlisted).
///
/// **Boolean-valued conf keys** (e.g. `can_cloud_download`)
/// should use the exact strings `"true"` / `"false"`. SEA
/// accepts these literally; other forms (`"True"`, `"yes"`,
/// `"1"`) either fail at session-create or behave as
/// undefined on the server. The kernel does not pre-validate
/// — its posture is "trust the user's session_conf" — so
/// non-canonical values flow to the server as-is.
/// **Boolean-valued conf keys** should use the exact strings
/// `"true"` / `"false"`. SEA accepts these literally; other forms
/// (`"True"`, `"yes"`, `"1"`) either fail at session-create or
/// behave as undefined on the server. The kernel does not
/// pre-validate — its posture is "trust the user's session_conf" —
/// so non-canonical values flow to the server as-is.
pub session_conf: HashMap<String, String>,

pub http: HttpConfig,
Expand All @@ -1014,13 +1015,15 @@ pub struct SessionConfig {
/// and uppercased before being sent.
pub(crate) const SESSION_CONF_ALLOWLIST: &[&str] = &[
"ANSI_MODE",
// `CAN_CLOUD_DOWNLOAD` is the kernel-synthesised flag (set by
// `Session::open` when `ResultConfig::cloudfetch_enabled = false`)
// telling SEA to serve every result via the inline-Arrow path.
// Listed here so a user-supplied value (with any casing) survives
// the allowlist filter and so the kernel's own synthesis passes
// through normalisation without special-casing.
"CAN_CLOUD_DOWNLOAD",
// NOTE: `CAN_CLOUD_DOWNLOAD` is deliberately NOT allowlisted. SEA has
// no such session conf — it is accepted at CreateSession but rejected
// at the first ExecuteStatement with `CONFIG_NOT_AVAILABLE` (issue
// #196). CloudFetch-disable is expressed per-statement via the SEA
// `disposition` (see `SeaRestTransport::call_execute_api` and
// `TransportConfig::cloudfetch_enabled`), matching both the JDBC and
// Thrift reference drivers. A stray caller-supplied `can_cloud_download`
// is therefore dropped by `filter_session_conf` (with a warn) rather
// than forwarded to the wire where it would break the session.
"COLLATION",
"ENABLE_PHOTON",
"LEGACY_TIME_PARSER_POLICY",
Expand Down Expand Up @@ -1227,6 +1230,30 @@ mod tests {
assert_eq!(out.get("TIMEZONE").map(String::as_str), Some("UTC"));
}

#[test]
fn session_conf_filter_drops_can_cloud_download() {
// Regression tripwire for issue #196: `can_cloud_download` is NOT a
// valid SEA session conf (the server rejects it at ExecuteStatement
// with CONFIG_NOT_AVAILABLE). It must be dropped by the allowlist
// filter — never forwarded to the wire — regardless of casing.
// CloudFetch-disable is applied per-statement via the SEA
// disposition instead. If someone re-adds it to the allowlist, this
// test flips RED.
for spelling in [
"can_cloud_download",
"CAN_CLOUD_DOWNLOAD",
"Can_Cloud_Download",
] {
let mut raw = std::collections::HashMap::new();
raw.insert(spelling.to_string(), "false".to_string());
let out = filter_session_conf(raw);
assert!(
out.is_empty(),
"can_cloud_download ({spelling:?}) must be dropped, got {out:?}"
);
}
}

#[test]
fn session_conf_filter_passes_metricview_conf_verbatim() {
// The metric-view conf is a dotted spark.* key: it must survive
Expand Down
4 changes: 2 additions & 2 deletions src/reader/inline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
//! case. The server returns one chunk at a time via
//! `GET /result/chunks/{idx}?row_offset=N`; the kernel maintains a
//! bounded rolling window of pre-decoded chunks ahead of the
//! consumer. Used when CloudFetch is disabled
//! (`can_cloud_download=false` session conf) and the result is
//! consumer. Used when CloudFetch is disabled (the execute request
//! was sent with SEA `disposition = INLINE`) and the result is
//! large enough that the server paginates it.

mod provider;
Expand Down
5 changes: 3 additions & 2 deletions src/reader/inline/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

//! `InlineStreamingProvider` — rolling-window prefetch for multi-chunk inline Arrow.
//!
//! Lights up when the session has `can_cloud_download = false`. The
//! server returns chunks one at a time via `GET /result/chunks/{idx}`
//! Lights up when CloudFetch is disabled (`cloudfetch_enabled = false`,
//! i.e. the execute request was sent with SEA `disposition = INLINE`).
//! The server returns chunks one at a time via `GET /result/chunks/{idx}`
//! with Arrow IPC bytes in `attachment`; this provider keeps a bounded
//! number of those chunks decoded and ready in memory ahead of the
//! consumer so the per-chunk SEA round-trip latency is hidden behind
Expand Down
62 changes: 17 additions & 45 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,15 @@ impl Session {
// OnceLock::set. So: construct, wrap in Arc, build factory,
// install factory.
let defaults = config.defaults.clone().unwrap_or_default();
let transport_config = TransportConfig::default();
let transport_config = TransportConfig {
// Thread the connection-level CloudFetch toggle onto the
// transport so every ExecuteStatement picks the right SEA
// disposition (INLINE_OR_EXTERNAL_LINKS vs INLINE). This is
// how cloud-fetch is disabled on SEA — see TransportConfig
// and issue #196; there is no CAN_CLOUD_DOWNLOAD session conf.
cloudfetch_enabled: config.result.cloudfetch_enabled,
..TransportConfig::default()
};
let sea = Arc::new(SeaRestTransport::new(
http_client.clone(),
host.clone(),
Expand All @@ -303,54 +311,18 @@ impl Session {
"creating session"
);

// When CloudFetch is disabled at the kernel layer, advertise this
// capability to SEA via the `can_cloud_download` session conf.
// Per the SEA inline-Arrow design (go/inline-arrow-sea, DD1), this
// tells the server to fall back to the inline-Arrow path for all
// result sizes instead of attempting cloud-fetch and erroring at
// fetch time.
//
// Don't clobber an explicit non-empty user value — if the caller
// wired `can_cloud_download` directly via `session_conf` for any
// reason (e.g., to force inline-Arrow even with CloudFetch enabled
// at the kernel layer), their value wins.
//
// **Case-insensitive key match** because SEA session-conf keys
// are historically case-insensitive on the wire; without this, a
// stray `"Can_Cloud_Download"` from the user would coexist with
// the kernel's canonical-cased `"can_cloud_download"` and we'd
// ship both keys (potentially with different values) — server
// would pick one non-deterministically.
//
// **Empty-string user values are purged**: an empty value is
// ambiguous (server behaviour undefined) and the kernel prefers
// to inject its canonical `"false"` instead of shipping the
// ambiguous empty. Purge-then-insert guarantees the wire body
// carries at most one `can_cloud_download` key regardless of
// case-variants the caller supplied.
let mut session_conf = config.session_conf.clone();
if !config.result.cloudfetch_enabled {
let has_nonempty_user_value = session_conf
.iter()
.any(|(k, v)| k.eq_ignore_ascii_case("can_cloud_download") && !v.is_empty());
crate::klog::debug!(
cloudfetch_enabled = false,
user_value_present = has_nonempty_user_value,
"evaluating can_cloud_download injection",
);
if !has_nonempty_user_value {
// Drop every case-variant (including empty-value ones)
// before inserting the canonical key so we can't ship
// duplicates that differ only in case.
session_conf.retain(|k, _| !k.eq_ignore_ascii_case("can_cloud_download"));
session_conf.insert("can_cloud_download".to_string(), "false".to_string());
}
}
// CloudFetch-disable is expressed per-statement via the SEA
// `disposition` (threaded onto `TransportConfig` above), NOT via a
// session conf: SEA has no `CAN_CLOUD_DOWNLOAD` conf — sending one
// is accepted at CreateSession but rejected at the first
// ExecuteStatement with `CONFIG_NOT_AVAILABLE` (issue #196). So the
// user's `session_conf` flows to CreateSession untouched; the
// kernel synthesises nothing here.
let session_info = transport
.create_session(
defaults.catalog.as_deref(),
defaults.schema.as_deref(),
crate::config::filter_session_conf(session_conf),
crate::config::filter_session_conf(config.session_conf.clone()),
)
.await?;

Expand Down
4 changes: 2 additions & 2 deletions src/types/cloudfetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ pub struct CloudFetchConfig {
/// of approximately this many rows before being served to consumers.
pub batch_merge_target_rows: usize,
/// Rolling-window bound for the multi-chunk inline-Arrow path
/// (used when CloudFetch is disabled at the session level via
/// `can_cloud_download=false`). Analogue of
/// (used when CloudFetch is disabled, i.e. the execute request is
/// sent with SEA `disposition = INLINE`). Analogue of
/// [`Self::max_chunks_in_memory`] but for sequential inline
/// prefetches rather than parallel cloud downloads.
pub inline_max_chunks_in_memory: usize,
Expand Down
3 changes: 2 additions & 1 deletion src/types/sea.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ pub struct GetChunksResponse {
/// Inline Arrow IPC bytes (base64-decoded by serde) for the
/// inline-Arrow streaming path. Populated when the server
/// returns chunks inline rather than via CloudFetch — i.e. when
/// the session was opened with `can_cloud_download=false`.
/// the execute request was sent with SEA `disposition = INLINE`
/// (`cloudfetch_enabled = false`).
#[serde(default, deserialize_with = "deserialize_base64_attachment")]
pub attachment: Option<Vec<u8>>,
}
Expand Down
Loading
Loading