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
38 changes: 9 additions & 29 deletions CONNECTION_PARAMETERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,33 +195,14 @@ Default: `SeaRest`.

`session_conf: HashMap<String, String>` carries **server-bound** SQL /
Spark configuration, forwarded to SEA `session_confs` and applied for
every statement on the session. Keys are matched **case-insensitively**
against an allowlist and **uppercased** before being sent; keys not in
the allowlist are **dropped with a warning**.
every statement on the session. The kernel does not validate,
normalize, uppercase, or drop server-bound keys; caller-supplied entries
are forwarded unchanged. Server-side validation errors, if any, come
from Databricks.

Allowlisted keys (see the [Databricks SQL configuration-parameters
See the [Databricks SQL configuration-parameters
reference](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-parameters)
for per-parameter meaning and accepted values):

| Key | Notes |
|-----|-------|
| `ANSI_MODE` | Enable/disable ANSI SQL behaviour. |
| `COLLATION` | Default collation. |
| `ENABLE_PHOTON` | Toggle the Photon engine. |
| `LEGACY_TIME_PARSER_POLICY` | Legacy datetime parsing behaviour. |
| `MAX_FILE_PARTITION_BYTES` | Max bytes per file partition. |
| `QUERY_TAGS` | Query tags (comma-separated `key:value`). |
| `READ_ONLY_EXTERNAL_METASTORE` | Treat the external metastore as read-only. |
| `STATEMENT_TIMEOUT` | Server-side per-statement timeout (seconds). This is the real query-timeout knob. |
| `TIMEZONE` | Session time zone, e.g. `UTC`. |
| `USE_CACHED_RESULT` | Toggle result caching. |

Dotted `spark.*` confs are matched case-insensitively but sent
**verbatim** (Spark conf keys are case-sensitive):

| Key | Notes |
|-----|-------|
| `spark.sql.thriftserver.metadata.metricview.enabled` | When `"true"`, `SHOW TABLES` returns `METRIC_VIEW` rows and `getColumns` surfaces `measure` columns. Mirrors JDBC `EnableMetricViewMetadata` (default off). |
for supported SQL parameter names and accepted values.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — This doc edit removes the entire table documenting the spark.sql.thriftserver.metadata.metricview.enabled conf and its effect (SHOW TABLES returning METRIC_VIEW rows, getColumns surfacing measure columns). The feature itself is unchanged — the kernel still lists METRIC_VIEW among table types and the server emits those rows only when this conf is set — so the capability now works but is undocumented at the connection-parameter level. Additionally, because the case-insensitive canonicalization is gone, a caller must now supply this key in its exact lowercase-dotted form (Spark conf keys are case-sensitive); any uppercased/mixed-case spelling that previously worked will now be forwarded verbatim and silently ignored server-side. Worth keeping a short note (or a link) so consumers know the exact key and that casing now matters. Not a correctness blocker — the removal is intentional per the PR scope.


Boolean-valued keys should use the exact strings `"true"` / `"false"`;
the kernel does not pre-validate values and forwards them as-is.
Expand All @@ -231,11 +212,10 @@ the kernel does not pre-validate values and forwards them as-is.
Some keys carried in the same `session_conf` map are **client-side**
tuning knobs: the kernel reads them at session creation, applies them to
the typed config above, and then strips them so they never reach the SEA
wire (they are deliberately *not* in the allowlist). They exist so C ABI
(Go / ODBC) consumers can set them through the existing
`session_conf` entry point without a dedicated symbol.
wire. They exist so C ABI (Go / ODBC) consumers can set them through the
existing `session_conf` entry point without a dedicated symbol.

Each key mirrors a field of [`ResultConfig`](#resultconfig--result-handling-optional) and is matched **case-insensitively**. Boolean keys accept exactly `"true"` / `"false"` (case-insensitive); the integer window keys require a positive integer. An unrecognised value is rejected with `InvalidArgument` at session creation.
Each key mirrors a field of [`ResultConfig`](#resultconfig--result-handling-optional) and is matched **case-insensitively**. Boolean keys accept exactly `"true"` / `"false"` (case-insensitive); the integer window keys require a positive integer. When supplied through `session_conf`, an invalid value is ignored with a warning and the key is still stripped from the wire. The typed client-conf setters reject invalid values with `InvalidArgument`.

| Key | Description | Default |
|-----|-------------|---------|
Expand Down
2 changes: 1 addition & 1 deletion include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ kernel_session_config_set_oauth_scopes(KernelSessionConfig* config,
const char* scopes);

/* Add (or overwrite) one session-conf entry. Keys are normally server SET
* parameters forwarded on the SEA wire (allowlist-filtered). A small set of
* parameters forwarded unchanged on the SEA wire. A small set of
* reserved keys are instead CLIENT-ONLY: they tune the kernel locally, are
* consumed before session creation, and NEVER reach the wire. Client-only keys
* (matched case-insensitively):
Expand Down
5 changes: 2 additions & 3 deletions src/c_abi/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,8 @@ pub unsafe extern "C" fn kernel_init_logging_callback(
}
}

/// Add (or overwrite) one server-bound session-conf entry. Unknown keys
/// are filtered against the kernel allowlist at `open()` time, matching
/// the Rust-crate path.
/// Add (or overwrite) one server-bound session-conf entry. Entries pass
/// through unchanged at `open()` time, matching the Rust-crate path.
///
/// # Safety
/// `config` must be a live config handle; `key` / `value` must be
Expand Down
219 changes: 7 additions & 212 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,9 +1245,9 @@ impl ResultConfig {
///
/// Unlike the server `session_conf` map, these knobs are **client-side**
/// and never reach the SEA wire — so this deliberately does NOT accept
/// server conf keys (`ANSI_MODE`, `TIMEZONE`, …); those go through
/// [`filter_session_conf`] instead. Keeping the two channels separate is
/// the point (see #226).
/// server conf keys (`ANSI_MODE`, `TIMEZONE`, …); those remain in
/// `session_conf` and pass through unchanged. Keeping the two channels
/// separate is the point (see #226).
///
/// # Errors
/// Returns `ErrorCode::InvalidArgument` when:
Expand Down Expand Up @@ -1482,9 +1482,7 @@ pub struct SessionConfig {
/// Thrift `configuration`. Typed sub-structs above translate
/// the *client-side* knobs; this map carries everything else.
///
/// The kernel passes user-supplied entries through unchanged,
/// after filtering them against the kernel allowlist (see
/// [`filter_session_conf`] / [`SESSION_CONF_ALLOWLIST`]). The
/// The kernel passes user-supplied entries through unchanged. The
/// kernel does not synthesise any entries here from typed
/// client-side knobs.
///
Expand All @@ -1494,8 +1492,9 @@ pub struct SessionConfig {
/// 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).
/// drivers. A caller-supplied `can_cloud_download` is still forwarded
/// unchanged because the kernel does not validate server-bound
/// `session_conf` keys.
///
/// **Boolean-valued conf keys** should use the exact strings
/// `"true"` / `"false"`. SEA accepts these literally; other forms
Expand All @@ -1516,96 +1515,6 @@ pub struct SessionConfig {
pub transport: Option<TransportMode>,
}

// ─── session_conf allowlist ─────────────────────────────────────────────────

/// Known session-conf keys, sourced from
/// <https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-parameters>
/// plus the additional keys the Java driver accepts (`ENABLE_PHOTON`,
/// `QUERY_TAGS`). Keys are matched case-insensitively against this list
/// and uppercased before being sent.
pub(crate) const SESSION_CONF_ALLOWLIST: &[&str] = &[
"ANSI_MODE",
// 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",
"MAX_FILE_PARTITION_BYTES",
"QUERY_TAGS",
"READ_ONLY_EXTERNAL_METASTORE",
"STATEMENT_TIMEOUT",
"TIMEZONE",
"USE_CACHED_RESULT",
];

/// Case-sensitive session-conf keys that must be sent **verbatim**
/// rather than uppercased. These are dotted `spark.*` Spark confs (as
/// opposed to the short SET-style SQL parameters in
/// [`SESSION_CONF_ALLOWLIST`], which Databricks echoes uppercase).
/// Spark stores `SQLConf` entries under their exact registered
/// lowercase-dotted key, so uppercasing would address the wrong entry.
///
/// Each tuple is `(uppercased_lookup_key, canonical_verbatim_key)`:
/// callers are matched case-insensitively (via the uppercased lookup)
/// but the canonical form is what we send on the wire.
///
/// `spark.sql.thriftserver.metadata.metricview.enabled` enables UC
/// Metric View metadata — when set to `"true"`, `SHOW TABLES`
/// (`Metadata::tables`) returns `METRIC_VIEW` rows and `getColumns`
/// surfaces `measure` columns. Opt-in: the connector sets it from its
/// `enable_metric_view_metadata` kwarg (default off), matching the
/// JDBC driver's `EnableMetricViewMetadata` (default `0`). The kernel
/// already lists `METRIC_VIEW` among its table types; this lets the
/// enabling conf through so the server actually emits the rows.
pub(crate) const SESSION_CONF_CASE_SENSITIVE_ALLOWLIST: &[(&str, &str)] = &[(
"SPARK.SQL.THRIFTSERVER.METADATA.METRICVIEW.ENABLED",
"spark.sql.thriftserver.metadata.metricview.enabled",
)];

/// Filter a caller-supplied `session_conf` map against the allowlists.
/// Unknown keys are dropped with a `tracing::warn!`.
///
/// - Keys in [`SESSION_CONF_ALLOWLIST`] are normalized to **uppercase**
/// (the server echoes uppercase for these SET-style params, so
/// SET-readback matches).
/// - Keys in [`SESSION_CONF_CASE_SENSITIVE_ALLOWLIST`] (dotted
/// `spark.*` confs) are matched case-insensitively but emitted in
/// their **canonical verbatim** form — Spark conf keys are
/// case-sensitive and must not be uppercased.
pub(crate) fn filter_session_conf(
raw: std::collections::HashMap<String, String>,
) -> std::collections::HashMap<String, String> {
use std::collections::HashMap;
let mut out: HashMap<String, String> = HashMap::with_capacity(raw.len());
for (k, v) in raw {
let upper = k.to_ascii_uppercase();
if SESSION_CONF_ALLOWLIST.contains(&upper.as_str()) {
out.insert(upper, v);
} else if let Some((_, canonical)) = SESSION_CONF_CASE_SENSITIVE_ALLOWLIST
.iter()
.find(|(lookup, _)| *lookup == upper.as_str())
{
// Send the canonical lowercase-dotted form verbatim, not
// the caller's casing and not uppercased.
out.insert((*canonical).to_string(), v);
} else {
crate::klog::warn!(
key = %k,
"dropping unknown session_conf key (not in kernel allowlist); \
see https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-parameters"
);
}
}
out
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -1713,120 +1622,6 @@ mod tests {
assert_eq!(cfg.resolve(), None);
}

// ─── session_conf allowlist ────────────────────────────────────

#[test]
fn session_conf_filter_keeps_known_keys_uppercased() {
let mut raw = std::collections::HashMap::new();
raw.insert("use_cached_result".to_string(), "false".to_string());
raw.insert("ANSI_MODE".to_string(), "true".to_string());
let out = filter_session_conf(raw);
assert_eq!(
out.get("USE_CACHED_RESULT").map(String::as_str),
Some("false")
);
assert_eq!(out.get("ANSI_MODE").map(String::as_str), Some("true"));
assert_eq!(out.len(), 2);
}

#[test]
fn session_conf_filter_drops_unknown_keys() {
let mut raw = std::collections::HashMap::new();
raw.insert("ANSI_MOD".to_string(), "true".to_string()); // typo
raw.insert("NOT_A_REAL_PARAM".to_string(), "x".to_string());
raw.insert("TIMEZONE".to_string(), "UTC".to_string());
let out = filter_session_conf(raw);
assert_eq!(out.len(), 1);
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
// the allowlist AND be emitted lowercase-verbatim (NOT
// uppercased like the SET-style params), because Spark conf
// keys are case-sensitive.
let mut raw = std::collections::HashMap::new();
raw.insert(
"spark.sql.thriftserver.metadata.metricview.enabled".to_string(),
"true".to_string(),
);
let out = filter_session_conf(raw);
assert_eq!(
out.get("spark.sql.thriftserver.metadata.metricview.enabled")
.map(String::as_str),
Some("true"),
);
// It must NOT have been uppercased.
assert!(!out.contains_key("SPARK.SQL.THRIFTSERVER.METADATA.METRICVIEW.ENABLED"));
assert_eq!(out.len(), 1);
}

#[test]
fn session_conf_filter_metricview_match_is_case_insensitive() {
// A caller passing the key in any casing is recognised, but the
// canonical lowercase form is always what we send.
let mut raw = std::collections::HashMap::new();
raw.insert(
"SPARK.SQL.THRIFTSERVER.METADATA.METRICVIEW.ENABLED".to_string(),
"true".to_string(),
);
let out = filter_session_conf(raw);
assert_eq!(
out.get("spark.sql.thriftserver.metadata.metricview.enabled")
.map(String::as_str),
Some("true"),
);
assert_eq!(out.len(), 1);
}

#[test]
fn session_conf_allowlist_covers_jdbc_set() {
// Parity check: every key the Java driver accepts must be
// accepted here too (we add COLLATION which JDBC currently
// lacks but the docs list).
for jdbc_key in [
"ANSI_MODE",
"ENABLE_PHOTON",
"LEGACY_TIME_PARSER_POLICY",
"MAX_FILE_PARTITION_BYTES",
"READ_ONLY_EXTERNAL_METASTORE",
"STATEMENT_TIMEOUT",
"TIMEZONE",
"USE_CACHED_RESULT",
"QUERY_TAGS",
] {
assert!(
SESSION_CONF_ALLOWLIST.contains(&jdbc_key),
"missing JDBC-compatible key: {jdbc_key}"
);
}
}

// ─── AuthConfig validating constructors ───────────────────────

#[test]
Expand Down
Loading
Loading