Skip to content

Commit db23442

Browse files
fix(results): fetch paged results with CloudFetch disabled (#436)
Setting the existing `ResultConfig.cloudfetch_enabled` option to `false` currently makes queries fail because the kernel requests an unsupported inline Arrow format. Applications that cannot access cloud storage therefore cannot fetch their results. This PR applies the option when opening the session and keeps the result format that supports multiple inline pages. Applications can consume the complete result through the SQL connection, including large results. An explicit disable takes precedence over conflicting settings, and the kernel rejects unexpected storage links before downloading them. **Server dependency:** The warehouse must support paged inline Arrow results. A warehouse that does not support this capability returns its configuration error to the caller. **Validation:** Kernel tests, formatting, and Clippy pass. Wire tests cover option precedence, initial and continuation responses, pagination offsets, and missing upfront result totals. A locally built Rust ADBC driver fetched all 250,000 rows and 32 MB of payload with the expected result hash and zero storage downloads. Enabled delivery, query errors, session reuse, and close also passed. --------- Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
1 parent 453017f commit db23442

16 files changed

Lines changed: 360 additions & 170 deletions

‎adbc/README.md‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,11 @@ operation is pending. Client query deadlines and rows-per-block slicing apply
159159
equally to synchronous and submitted execution. Dropping a submitted handle or
160160
an incompletely consumed reader triggers best-effort server cleanup.
161161

162-
`adbc.databricks.cloudfetch.enabled` is wired to the kernel result
163-
configuration. The current kernel/server combination does not yet support the
164-
`false` path because SEA rejects inline Arrow results; disabling CloudFetch is
165-
therefore not a production-supported configuration in this release.
162+
Set `adbc.databricks.cloudfetch.enabled` to `false` to fetch results through
163+
the SQL connection when the application cannot access cloud storage directly.
164+
Large results are read in pages.
165+
The warehouse must support paged inline delivery; otherwise session creation
166+
or the first statement returns the server's configuration error.
166167

167168
## ADBC behavior
168169

‎include/databricks_kernel.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,12 +595,12 @@ KernelStatusCode kernel_session_config_set_u2m_token_cache_config(KernelSessionC
595595
*
596596
* Recognised keys (case-insensitive):
597597
* - "cloudfetch_enabled" = "true"|"false" — false serves every result
598-
* inline (SEA disposition = INLINE), mirroring JDBC EnableQueryResultDownload=0.
598+
* through paged inline delivery without cloud-storage downloads.
599599
* - "cloudfetch_link_prefetch_window" = positive integer.
600600
* - "cloudfetch_max_chunks_in_memory" = positive integer (bounds peak RSS;
601601
* values above the kernel ceiling of 256 are clamped with a warning).
602602
* - "inline_max_chunks_in_memory" = positive integer (inline-Arrow prefetch
603-
* window, used when cloudfetch_enabled = false).
603+
* window for paged inline results).
604604
* - "complex_types_as_json" = "true"|"false" — render ARRAY / MAP / STRUCT /
605605
* VARIANT / GEOMETRY / GEOGRAPHY as JSON text (PySQL
606606
* _use_arrow_native_complex_types=False, JDBC complexDatatypeSupport=false).

‎src/c_abi/session.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,15 +1378,14 @@ pub unsafe extern "C" fn kernel_session_config_set_u2m_token_cache_config(
13781378
/// Recognised keys (matched case-insensitively), mapping to
13791379
/// [`ResultConfig`]:
13801380
/// - `cloudfetch_enabled` = `"true"` / `"false"` — `false` serves every
1381-
/// result inline (SEA `disposition = INLINE`), mirroring JDBC's
1382-
/// `EnableQueryResultDownload=0`.
1381+
/// result through paged inline delivery without cloud-storage downloads.
13831382
/// - `cloudfetch_link_prefetch_window` = positive integer — presigned URLs
13841383
/// prefetched ahead of the consumer.
13851384
/// - `cloudfetch_max_chunks_in_memory` = positive integer — decompressed
13861385
/// CloudFetch chunks held at once (bounds peak RSS). Values above the
13871386
/// kernel ceiling (256) are **clamped** with a warning, not rejected.
13881387
/// - `inline_max_chunks_in_memory` = positive integer — inline-Arrow
1389-
/// prefetch window (used when `cloudfetch_enabled = false`).
1388+
/// prefetch window for paged inline results.
13901389
/// - `complex_types_as_json` = `"true"` / `"false"` — render `ARRAY` /
13911390
/// `MAP` / `STRUCT` / `VARIANT` / `GEOMETRY` / `GEOGRAPHY` as JSON text
13921391
/// (PySQL `_use_arrow_native_complex_types=False`, JDBC

‎src/client/sea.rs‎

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -658,30 +658,6 @@ impl SeaRestTransport {
658658
) -> Result<ExecuteResponse> {
659659
let url = format!("{}/statements", self.base_url());
660660

661-
// Select the result disposition per statement from the
662-
// connection-level CloudFetch setting, mirroring the reference
663-
// JDBC driver's SEA path (`DatabricksSdkClient.getRequest`:
664-
// `cloudFetch ? INLINE_OR_EXTERNAL_LINKS : INLINE`). This is the
665-
// authoritative mechanism for disabling cloud-fetch on SEA —
666-
// there is NO `CAN_CLOUD_DOWNLOAD` session conf (the server
667-
// rejects it at ExecuteStatement with `CONFIG_NOT_AVAILABLE`,
668-
// issue #196).
669-
//
670-
// `INLINE`: the server serves every result inline (Arrow bytes in
671-
// the response `attachment`), regardless of size. `format` stays
672-
// `ARROW_STREAM` — the kernel's inline reader consumes Arrow IPC
673-
// from the attachment (the SEA inline-Arrow path), so unlike JDBC
674-
// we keep Arrow rather than switching to `JSON_ARRAY`.
675-
//
676-
// `INLINE_OR_EXTERNAL_LINKS` (the CloudFetch-enabled default): not
677-
// a public API disposition but enables returning all chunk links
678-
// in a single response (requires the JDBC user agent). Once
679-
// EXTERNAL_LINKS supports multi-link responses, switch back to it.
680-
let disposition = if self.config.cloudfetch_enabled {
681-
"INLINE_OR_EXTERNAL_LINKS"
682-
} else {
683-
"INLINE"
684-
};
685661
let (warehouse_id, session_id) = match self.session_route.get() {
686662
Some(SessionRoute::Standard { .. }) | None => (
687663
Some(self.warehouse_id.clone()),
@@ -696,7 +672,7 @@ impl SeaRestTransport {
696672
session_version: self.current_session_version(),
697673
catalog: params.catalog.clone(),
698674
schema: params.schema.clone(),
699-
disposition: disposition.to_string(),
675+
disposition: "INLINE_OR_EXTERNAL_LINKS".to_string(),
700676
format: "ARROW_STREAM".to_string(),
701677
wait_timeout: params.wait_timeout.clone(),
702678
on_wait_timeout: params.on_wait_timeout.clone(),
@@ -1156,10 +1132,15 @@ impl Transport for SeaRestTransport {
11561132
&self,
11571133
catalog: Option<&str>,
11581134
schema: Option<&str>,
1159-
session_config: HashMap<String, String>,
1135+
mut session_config: HashMap<String, String>,
11601136
) -> Result<SessionInfo> {
11611137
let url = self.warehouse_sessions_url();
11621138

1139+
if !self.config.cloudfetch_enabled {
1140+
session_config.retain(|key, _| !key.eq_ignore_ascii_case("can_cloud_download"));
1141+
session_config.insert("can_cloud_download".to_string(), "false".to_string());
1142+
}
1143+
11631144
let request_body = CreateSessionRequest {
11641145
warehouse_id: None,
11651146
catalog: catalog.map(|s| s.to_string()),
@@ -1537,18 +1518,12 @@ impl Transport for SeaRestTransport {
15371518
))
15381519
})?;
15391520

1540-
// Inline-Arrow path: bytes must be present in `attachment`.
1541-
// If the server returned an external_links response on what
1542-
// we expected to be the inline path, surface a clear error
1543-
// (probably the `disposition = INLINE` on the execute request
1544-
// didn't take effect server-side).
15451521
let bytes = chunks_response.attachment.ok_or_else(|| {
15461522
Error::data_loss().message(format!(
15471523
"Inline chunk {} response missing `attachment` field — \
1548-
server may have ignored the INLINE disposition and \
1549-
returned a CloudFetch response. Body: {}",
1550-
chunk_index,
1551-
String::from_utf8_lossy(&body)
1524+
server did not return inline Arrow data and \
1525+
returned a CloudFetch response",
1526+
chunk_index
15521527
))
15531528
})?;
15541529

‎src/client/transport.rs‎

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,8 @@ pub(crate) struct TransportConfig {
6767
/// Whether CloudFetch (cloud-storage-backed result download via
6868
/// external links) is enabled for this session.
6969
///
70-
/// This is a **connection-level** setting — like the reference JDBC
71-
/// driver's `EnableQueryResultDownload`, it is read once at session
72-
/// open and applied to every `ExecuteStatement`, not toggled per
73-
/// statement. It selects the SEA `disposition` sent on each execute:
74-
/// `true` → `INLINE_OR_EXTERNAL_LINKS` (results may come back as
75-
/// external CloudFetch links), `false` → `INLINE` (the server serves
76-
/// every result inline, regardless of size).
77-
///
78-
/// **Why this is `disposition`, not a session conf.** SEA has no
79-
/// `CAN_CLOUD_DOWNLOAD` session conf — sending one is accepted at
80-
/// `CreateSession` but rejected at the first `ExecuteStatement` with
81-
/// `CONFIG_NOT_AVAILABLE` (see issue #196). Both the JDBC and Thrift
82-
/// reference drivers control cloud-fetch per request (SEA
83-
/// `disposition` / Thrift `canDownloadResult`), never via session
84-
/// conf; this mirrors JDBC's SEA path
85-
/// (`DatabricksSdkClient.getRequest`).
70+
/// When false, session creation requests paged inline results without
71+
/// cloud-storage downloads. The value is fixed for the session lifetime.
8672
pub cloudfetch_enabled: bool,
8773
}
8874

@@ -404,10 +390,7 @@ pub(crate) trait Transport: Send + Sync + std::fmt::Debug {
404390
/// Fetch one inline-Arrow chunk by `chunk_index` (+ server-side
405391
/// `row_offset`).
406392
///
407-
/// Used by the inline-Arrow streaming path that lights up when
408-
/// `ResultConfig.cloudfetch_enabled == false` (i.e. the execute
409-
/// request was sent with SEA `disposition = INLINE`). The
410-
/// server-side response for this path carries Arrow IPC bytes inline
393+
/// Used for paged inline results. The response carries Arrow IPC bytes inline
411394
/// in `attachment` rather than emitting `external_links`.
412395
///
413396
/// Per the bounded SEA API contract for OSS drivers:

‎src/config.rs‎

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,30 +1090,9 @@ pub struct ResultConfig {
10901090
/// Whether to opt into CloudFetch (cloud-storage-backed download of
10911091
/// large result sets via presigned URLs). Default: `true`.
10921092
///
1093-
/// Setting this to `false` mirrors JDBC's `EnableQueryResultDownload=0`
1094-
/// behaviour. It is a **connection-level** setting: read once at
1095-
/// [`Session::open`](crate::Session::open) and applied to every
1096-
/// statement by selecting the SEA `disposition` on each
1097-
/// `ExecuteStatement` (`false` → `INLINE`, so SEA serves **all**
1098-
/// result sizes via the inline-Arrow path regardless of size). This
1099-
/// matches how the JDBC and Thrift reference drivers control
1100-
/// cloud-fetch (per request), and is deliberately **not** expressed
1101-
/// as a session conf — SEA has no `CAN_CLOUD_DOWNLOAD` conf and
1102-
/// rejects one at ExecuteStatement with `CONFIG_NOT_AVAILABLE`
1103-
/// (issue #196). Users who need inline-only behaviour (e.g.
1104-
/// workspaces without cloud-storage egress) should set this to
1105-
/// `false`.
1106-
///
1107-
/// Disabling CloudFetch routes results to the inline-Arrow
1108-
/// path. The kernel today supports the **single-attachment**
1109-
/// inline path; the multi-chunk inline path is on the SEA
1110-
/// inline-Arrow rollout (DD1) and is tracked as a follow-up
1111-
/// (`InlineArrowProvider::new` consumes one attachment, and
1112-
/// `src/reader/mod.rs` returns `Error::not_implemented` for
1113-
/// inline responses that carry a `next_chunk_internal_link`).
1114-
/// Once multi-chunk lands, this path will not match
1115-
/// CloudFetch's concurrent chunk-download pipeline
1116-
/// (`cloudfetch_max_chunks_in_memory`).
1093+
/// Set to `false` for applications without direct access to cloud storage.
1094+
/// This connection-level setting requests paged inline Arrow results.
1095+
/// Servers without this capability may reject session creation or the first statement.
11171096
pub cloudfetch_enabled: bool,
11181097

11191098
/// Number of presigned URLs to prefetch ahead of the consumer.
@@ -1125,8 +1104,7 @@ pub struct ResultConfig {
11251104

11261105
/// Maximum number of decompressed Arrow chunks the inline-Arrow
11271106
/// streaming reader holds in memory at once. Analogue of
1128-
/// [`Self::cloudfetch_max_chunks_in_memory`] for the inline path
1129-
/// (used when [`Self::cloudfetch_enabled`] is `false`).
1107+
/// [`Self::cloudfetch_max_chunks_in_memory`] for paged inline results.
11301108
///
11311109
/// The inline path is sequential per the SEA contract — one
11321110
/// `GetResultData` call at a time — so this knob bounds the
@@ -1565,19 +1543,9 @@ pub struct SessionConfig {
15651543
/// Thrift `configuration`. Typed sub-structs above translate
15661544
/// the *client-side* knobs; this map carries everything else.
15671545
///
1568-
/// The kernel passes user-supplied entries through unchanged. The
1569-
/// kernel does not synthesise any entries here from typed
1570-
/// client-side knobs.
1571-
///
1572-
/// In particular, [`ResultConfig::cloudfetch_enabled`] is **not**
1573-
/// expressed as a session conf: SEA has no `CAN_CLOUD_DOWNLOAD`
1574-
/// conf (it is accepted at CreateSession but rejected at the first
1575-
/// ExecuteStatement with `CONFIG_NOT_AVAILABLE`, issue #196).
1576-
/// CloudFetch-disable is instead applied per-statement via the SEA
1577-
/// `disposition` field, matching the JDBC / Thrift reference
1578-
/// drivers. A caller-supplied `can_cloud_download` is still forwarded
1579-
/// unchanged because the kernel does not validate server-bound
1580-
/// `session_conf` keys.
1546+
/// User-supplied entries are passed through, except that disabling
1547+
/// CloudFetch in [`ResultConfig`] takes precedence over its corresponding
1548+
/// session setting.
15811549
///
15821550
/// **Boolean-valued conf keys** should use the exact strings
15831551
/// `"true"` / `"false"`. SEA accepts these literally; other forms

‎src/reader/inline/mod.rs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@
3030
//! case. The server returns one chunk at a time via
3131
//! `GET /result/chunks/{idx}?row_offset=N`; the kernel maintains a
3232
//! bounded rolling window of pre-decoded chunks ahead of the
33-
//! consumer. Used when CloudFetch is disabled (the execute request
34-
//! was sent with SEA `disposition = INLINE`) and the result is
35-
//! large enough that the server paginates it.
33+
//! consumer. Used when the result is large enough that the server
34+
//! paginates inline delivery.
3635
3736
mod provider;
3837
mod streaming;

‎src/reader/inline/streaming.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414

1515
//! `InlineStreamingProvider` — rolling-window prefetch for multi-chunk inline Arrow.
1616
//!
17-
//! Lights up when CloudFetch is disabled (`cloudfetch_enabled = false`,
18-
//! i.e. the execute request was sent with SEA `disposition = INLINE`).
17+
//! Used for paged inline results, including when CloudFetch is disabled.
1918
//! The server returns chunks one at a time via `GET /result/chunks/{idx}`
2019
//! with Arrow IPC bytes in `attachment`; this provider keeps a bounded
2120
//! number of those chunks decoded and ready in memory ahead of the

‎src/reader/mod.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ impl ResultReaderFactory {
199199
// Priority 1: CloudFetch (external_links present)
200200
if let Some(ref external_links) = result.external_links {
201201
if !external_links.is_empty() {
202+
if !self.config.enabled {
203+
return Err(Error::data_loss().message(
204+
"CloudFetch is disabled, but the server returned cloud-storage result links",
205+
));
206+
}
202207
// `total_chunk_count` is forwarded purely as a
203208
// transition-period guard. The link fetcher uses
204209
// it only when the server hasn't yet rolled out

‎src/session.rs‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,6 @@ impl Session {
391391
// install factory.
392392
let defaults = config.defaults.clone().unwrap_or_default();
393393
let transport_config = TransportConfig {
394-
// Thread the connection-level CloudFetch toggle onto the
395-
// transport so every ExecuteStatement picks the right SEA
396-
// disposition (INLINE_OR_EXTERNAL_LINKS vs INLINE). This is
397-
// how cloud-fetch is disabled on SEA — see TransportConfig
398-
// and issue #196; there is no CAN_CLOUD_DOWNLOAD session conf.
399394
cloudfetch_enabled: config.result.cloudfetch_enabled,
400395
..TransportConfig::default()
401396
};
@@ -423,10 +418,8 @@ impl Session {
423418
"creating session"
424419
);
425420

426-
// CloudFetch-disable is expressed per-statement via the SEA
427-
// `disposition` (threaded onto `TransportConfig` above), not via a
428-
// session conf. The kernel synthesises no geospatial session-conf
429-
// entry; caller-supplied server-bound entries pass through unchanged.
421+
// The kernel synthesises no geospatial session-conf entry;
422+
// caller-supplied server-bound entries pass through unchanged.
430423
// Resolve connector-service flags after authentication and immediately
431424
// before CreateSession. The resolver populates the process-wide
432425
// workspace cache; the session retains no private snapshot.
@@ -1254,9 +1247,11 @@ fn build_retry_configs_for_session(
12541247
/// Matched case-insensitively. If a host sets two spellings of the same key
12551248
/// differing only in case, the lexicographically-last spelling wins
12561249
/// deterministically and all variants are stripped.
1250+
/// An explicit typed CloudFetch disable takes precedence over the mixed bag.
12571251
fn apply_client_result_overrides(config: &mut SessionConfig) {
12581252
use crate::config::ClientConfKey;
12591253

1254+
let cloudfetch_disabled = !config.result.cloudfetch_enabled;
12601255
// Recognised client keys currently present in session_conf. A key is
12611256
// "recognised" iff it parses to a ClientConfKey (case-insensitive).
12621257
let mut present: Vec<String> = config
@@ -1288,6 +1283,12 @@ fn apply_client_result_overrides(config: &mut SessionConfig) {
12881283
);
12891284
}
12901285
}
1286+
if cloudfetch_disabled && config.result.cloudfetch_enabled {
1287+
crate::klog::warn!(
1288+
"Ignoring cloudfetch_enabled=true in session configuration because the client option disables CloudFetch"
1289+
);
1290+
config.result.cloudfetch_enabled = false;
1291+
}
12911292
}
12921293

12931294
/// Project the public [`ResultConfig`] (today only carries
@@ -2048,6 +2049,23 @@ mod retry_config_tests {
20482049
);
20492050
}
20502051

2052+
#[test]
2053+
fn typed_cloudfetch_disable_takes_precedence_over_session_conf() {
2054+
for key in ["cloudfetch_enabled", "CLOUDFETCH_ENABLED"] {
2055+
let mut cfg = config_with_session_conf(HashMap::from([
2056+
(key.to_string(), "true".to_string()),
2057+
("TIMEZONE".to_string(), "UTC".to_string()),
2058+
]));
2059+
cfg.result.cloudfetch_enabled = false;
2060+
apply_client_result_overrides(&mut cfg);
2061+
assert!(!cfg.result.cloudfetch_enabled);
2062+
assert_eq!(
2063+
cfg.session_conf,
2064+
HashMap::from([("TIMEZONE".to_string(), "UTC".to_string())])
2065+
);
2066+
}
2067+
}
2068+
20512069
/// All six client-side result knobs are recognised in session_conf,
20522070
/// applied to the typed ResultConfig, and stripped so none reach the
20532071
/// wire. Guards the parity between `ClientConfKey::ALL` and the

0 commit comments

Comments
 (0)