Skip to content
Closed
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
2 changes: 2 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ changes go in their respective binding's NEXT_CHANGELOG.
- Added Thrift-native metadata routing with compatible public-schema casts and one-based `getColumns` ordinals.
- Add connector-service feature-flag resolution with authenticated requests,
JSON-serialized per-driver values, and bounded process-wide caching.
- Add a C ABI client-identity setter so native drivers can use kernel-owned
connector-service feature flags without duplicate calls.

### Changed

Expand Down
19 changes: 19 additions & 0 deletions include/databricks_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ typedef struct kernel_statement_canceller_t kernel_statement_canceller_t;
* stream is permanently aborted (every later next_batch returns Cancelled). */
typedef struct kernel_result_stream_canceller_t kernel_result_stream_canceller_t;

/* Outer driver family used by connector-service feature-flag evaluation.
* This is an integer rather than a C enum so every value crosses the FFI
* boundary safely; the setter returns InvalidArgument for unknown values. */
Comment thread
oss-reviewer-bot[bot] marked this conversation as resolved.
Resolved
typedef uint32_t KernelClientType;
enum {
KernelClientType_Go = 1,
KernelClientType_NodeJs = 2,
KernelClientType_Python = 5,
};

/* ─── Session config ──────────────────────────────────────────────────
*
* Build a config, set exactly one connection form and exactly one auth
Expand All @@ -237,6 +247,15 @@ typedef struct kernel_result_stream_canceller_t kernel_result_stream_canceller_t
KernelStatusCode kernel_session_config_new(KernelSessionConfig** out);
void kernel_session_config_free(KernelSessionConfig* config);

/* Optional outer-driver identity for connector-service feature flags. Omitting
* this setter preserves legacy behavior and performs no feature-flag request.
* `version` must be non-NULL UTF-8 containing at least one non-whitespace
* character. The kernel owns fetching and caching; callers must not issue a
* duplicate request on the kernel path. */
KernelStatusCode kernel_session_config_set_client_identity(KernelSessionConfig* config,
KernelClientType client_type,
const char* version);

/* Connection identity — call exactly one; the last one wins. */
KernelStatusCode kernel_session_config_set_warehouse(KernelSessionConfig* config,
const char* host,
Expand Down
3 changes: 3 additions & 0 deletions napi/NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ layout, or npm publishing. Pure-kernel changes go in the root

### Changed

- Use a non-empty `driverVersion` as the Node.js client identity for
connector-service feature flags.

### Updated

### Fixed
Expand Down
5 changes: 3 additions & 2 deletions napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,9 @@ export interface ConnectionOptions {
*/
driverName?: string
/**
* Driver version reported in telemetry system configuration. Omitted ⇒
* kernel default.
* Driver version reported in telemetry system configuration and used for
* connector-service feature-flag evaluation. Omitted ⇒ kernel default and
* no feature-flag request.
*/
driverVersion?: string
/**
Expand Down
31 changes: 27 additions & 4 deletions napi/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ use napi::bindgen_prelude::Buffer;
type Buffer = Vec<u8>;

use databricks_sql_kernel::{
AuthConfig, DefaultOpts, DriverSystemConfiguration, Error as KernelError, HttpConfig,
ProxyConfig, ResultConfig, Session, TelemetryConfig, TlsConfig, TokenCacheConfig,
AuthConfig, ClientIdentity, ClientType, DefaultOpts, DriverSystemConfiguration,
Error as KernelError, HttpConfig, ProxyConfig, ResultConfig, Session, TelemetryConfig,
TlsConfig, TokenCacheConfig,
};

/// NodeJS-driver-appropriate default for `pool_max_idle_per_host`.
Expand Down Expand Up @@ -234,8 +235,9 @@ pub struct ConnectionOptions {
/// Driver name reported in telemetry system configuration. Omitted ⇒
/// kernel default.
pub driver_name: Option<String>,
/// Driver version reported in telemetry system configuration. Omitted ⇒
/// kernel default.
/// Driver version reported in telemetry system configuration and used for
/// connector-service feature-flag evaluation. Omitted ⇒ kernel default and
/// no feature-flag request.
pub driver_version: Option<String>,
/// Runtime name reported in telemetry system configuration. Omitted ⇒
/// kernel default.
Expand Down Expand Up @@ -763,6 +765,12 @@ fn build_driver_system_configuration(
})
}

fn build_client_identity(driver_version: Option<&str>) -> Option<ClientIdentity> {
driver_version
.filter(|version| !version.trim().is_empty())
.map(|version| ClientIdentity::new(ClientType::NodeJs, version))
}

/// Open a Databricks SQL session and return an opaque `Connection`
/// wrapping the kernel `Session`. Authentication is selected by
/// `options.auth_mode` (PAT / OAuth M2M / OAuth U2M) — see
Expand Down Expand Up @@ -798,6 +806,7 @@ pub async fn open_session(mut options: ConnectionOptions) -> napi::Result<Connec
// `options` to avoid cloning the header strings.
let http_config = build_http_config(&mut options);
let telemetry_config = build_telemetry_config(&options)?;
let client_identity = build_client_identity(options.driver_version.as_deref());
let driver_system_configuration = build_driver_system_configuration(&options);

// SessionConfig is `#[non_exhaustive]` — go through the
Expand Down Expand Up @@ -847,6 +856,9 @@ pub async fn open_session(mut options: ConnectionOptions) -> napi::Result<Connec
if let Some(system_configuration) = driver_system_configuration {
builder = builder.driver_system_configuration(system_configuration);
}
if let Some(identity) = client_identity {
builder = builder.client_identity(identity);
}
// Programmatic HTTP/HTTPS proxy. Only wire a `ProxyConfig` when a
// proxy is supplied; otherwise leave it unset so the kernel keeps
// reqwest's env-var behaviour (HTTPS_PROXY / NO_PROXY).
Expand Down Expand Up @@ -1699,4 +1711,15 @@ mod tests {
);
assert_eq!(system_configuration.process_name.as_deref(), Some("node"));
}

#[test]
fn driver_version_builds_node_client_identity() {
assert!(build_client_identity(None).is_none());
assert!(build_client_identity(Some("")).is_none());
assert!(build_client_identity(Some(" \t")).is_none());

let identity = build_client_identity(Some("1.2.3")).unwrap();
assert_eq!(identity.client_type(), ClientType::NodeJs);
assert_eq!(identity.version(), "1.2.3");
}
}
3 changes: 3 additions & 0 deletions pyo3/NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ changes go in the root `NEXT_CHANGELOG.md`.

### Changed

- Use a non-empty `driver_version` as the Python client identity for
connector-service feature flags.

### Updated

### Fixed
Expand Down
37 changes: 31 additions & 6 deletions pyo3/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::auth::{build_auth_config, OAuthParams};
use crate::executed_async::ExecutedAsyncStatement;
use crate::metadata::Metadata;
use crate::statement::Statement;
use databricks_sql_kernel::Session as KSession;
use databricks_sql_kernel::{ClientIdentity, ClientType, Session as KSession};
use pyo3::prelude::*;
use std::collections::HashMap;
use std::sync::Arc;
Expand Down Expand Up @@ -258,6 +258,12 @@ fn build_driver_system_configuration(
})
}

fn build_client_identity(driver_version: Option<&str>) -> Option<ClientIdentity> {
Comment thread
oss-reviewer-bot[bot] marked this conversation as resolved.
Resolved
driver_version
.filter(|version| !version.trim().is_empty())
.map(|version| ClientIdentity::new(ClientType::Python, version))
}

#[pymethods]
impl Session {
/// Open a new session against the given workspace.
Expand Down Expand Up @@ -325,6 +331,9 @@ impl Session {
/// presets, etc. The kernel does not validate keys; the server
/// rejects unknown ones with a `KernelError(code='SqlError')`
/// when it picks them up.
///
/// A non-empty `driver_version` also identifies the Python driver for
/// connector-service feature flags. Omitting it performs no flag request.
#[new]
#[pyo3(signature = (
host,
Expand Down Expand Up @@ -545,6 +554,7 @@ impl Session {
http_headers,
)?;

let client_identity = build_client_identity(driver_version.as_deref());
let driver_system_configuration = build_driver_system_configuration(
driver_name,
driver_version,
Expand Down Expand Up @@ -616,6 +626,9 @@ impl Session {
if let Some(system_configuration) = driver_system_configuration {
builder = builder.driver_system_configuration(system_configuration);
}
if let Some(identity) = client_identity {
builder = builder.client_identity(identity);
}
if catalog.is_some() || schema.is_some() {
let mut defaults = databricks_sql_kernel::DefaultOpts::default();
defaults.catalog = catalog;
Expand Down Expand Up @@ -771,6 +784,17 @@ mod send_sync_tests {
);
}

#[test]
fn driver_version_builds_python_client_identity() {
assert!(build_client_identity(None).is_none());
assert!(build_client_identity(Some("")).is_none());
assert!(build_client_identity(Some(" \t")).is_none());

let identity = build_client_identity(Some("1.2.3")).unwrap();
assert_eq!(identity.client_type(), ClientType::Python);
assert_eq!(identity.version(), "1.2.3");
}

#[test]
fn telemetry_kwargs_reject_zero_required_fields() {
assert!(build_telemetry_config(TelemetryKwargs {
Expand Down Expand Up @@ -819,9 +843,11 @@ mod send_sync_tests {
assert!(build_http_config(None, None, None, None, None, None, None)
.unwrap()
.is_none());
assert!(build_http_config(Some(0.0), None, None, None, None, None, None)
.unwrap()
.is_none());
assert!(
build_http_config(Some(0.0), None, None, None, None, None, None)
.unwrap()
.is_none()
);

let http = build_http_config(Some(0.5), None, None, None, None, None, None)
.unwrap()
Expand All @@ -832,8 +858,7 @@ mod send_sync_tests {

let one_ns = std::time::Duration::from_nanos(1).as_secs_f64();
assert!(
build_http_config(Some(one_ns / 1_000.0), None, None, None, None, None, None)
.is_err()
build_http_config(Some(one_ns / 1_000.0), None, None, None, None, None, None).is_err()
);
let http = build_http_config(Some(one_ns), None, None, None, None, None, None)
.unwrap()
Expand Down
Loading
Loading