Skip to content

Commit 449e23e

Browse files
feat(kernel): expose HTTPS protocol negotiation
Signed-off-by: Aakash Saravanan <aakash.saravanan@databricks.com>
1 parent 087b2bf commit 449e23e

7 files changed

Lines changed: 71 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Release History
22

33
# Unreleased
4+
- Add kernel-only `enable_http2`: HTTPS negotiates HTTP/2 with HTTP/1.1 fallback; set `enable_http2=False` to force HTTP/1.1 for all kernel-owned HTTPS traffic. Explicit settings require a kernel wheel with HTTP/2 configuration support.
45
- Honor `max_download_threads` on kernel connections, with a default download window of 16 and explicit chunk-setting overrides. Invalid values raise `ValueError` when connecting with `use_kernel=True`.
56
- Fix the kernel backend ignoring `use_cloud_fetch=False`, so complete results can be fetched without cloud-storage downloads.
67
- Fix inline parameters (`use_inline_params=True`) so a sequence directly after `IN` renders as a list again: `x IN %(ids)s` renders as `x IN (1,2,3)` instead of `x IN ARRAY(1,2,3)`, which Spark rejects. Inside the list, tuples render as rows for a multi-column `IN`, and a `set` or `frozenset` is accepted again. Sequences anywhere else still render as `ARRAY(...)` ([#629](https://github.com/databricks/databricks-sql-python/issues/629))

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ Install using `pip install databricks-sql-connector`
3535
Install using `pip install databricks-sql-connector[pyarrow]`
3636

3737
### Installing with the Rust kernel backend (`use_kernel=True`)
38+
39+
The kernel negotiates HTTP/2 for HTTPS requests, with HTTP/1.1 fallback when the
40+
peer does not support HTTP/2. Pass `enable_http2=False` with `use_kernel=True` to
41+
force HTTP/1.1 for authentication, SQL requests, result downloads, and telemetry.
42+
This setting requires a kernel wheel with HTTP/2 configuration support.
43+
3844
Install using `pip install databricks-sql-connector[kernel]`
3945

4046
This adds the optional [`databricks-sql-kernel`](https://pypi.org/project/databricks-sql-kernel/)

‎src/databricks/sql/backend/kernel/client.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,18 @@ def _kernel_session_accepts_kwarg(name: str) -> bool:
218218
return support.accepts_kwargs or name in support.parameters
219219

220220

221+
def _kernel_http2_kwargs(value: Optional[bool]) -> Dict[str, bool]:
222+
if value is None:
223+
return {}
224+
if not isinstance(value, bool):
225+
raise ValueError("enable_http2 must be a bool")
226+
if not _kernel_session_accepts_kwarg("enable_http2"):
227+
raise NotSupportedError(
228+
"enable_http2 requires a databricks-sql-kernel wheel with HTTP/2 configuration support."
229+
)
230+
return {"enable_http2": value}
231+
232+
221233
def _kernel_geospatial_kwargs(value: bool) -> Dict[str, bool]:
222234
"""Build the explicit native geospatial-support kwarg.
223235
@@ -346,6 +358,7 @@ def __init__(
346358
# The kernel binding owns type and range validation.
347359
self._request_timeout_secs = kwargs.get("request_timeout_secs")
348360
self._max_connections = kwargs.get("max_connections")
361+
self._enable_http2 = kwargs.get("enable_http2")
349362
self._use_cloud_fetch = kwargs.get("use_cloud_fetch", True)
350363
self._max_download_threads = kwargs.get("max_download_threads", 16)
351364
if (
@@ -485,6 +498,7 @@ def open_session(
485498
# kernel's ``retry_*`` kwargs. Empty when at defaults.
486499
retry_kwargs = _kernel_retry_kwargs(self._retry_options)
487500
telemetry_kwargs = _kernel_telemetry_kwargs(self._telemetry_options)
501+
http2_kwargs = _kernel_http2_kwargs(self._enable_http2)
488502
geospatial_kwargs = _kernel_geospatial_kwargs(
489503
self._enable_geospatial_support
490504
)
@@ -538,6 +552,7 @@ def open_session(
538552
**geospatial_kwargs,
539553
**max_connections_kwargs,
540554
**http_headers_kwargs,
555+
**http2_kwargs,
541556
)
542557
except Exception as exc:
543558
raise _wrap_kernel_exception("open_session", exc) from exc

‎src/databricks/sql/client.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ def __init__(
193193
decision. This is an intentional divergence from the
194194
Thrift/SEA paths, where an explicit ``True`` can still
195195
be suppressed by the feature flag.
196+
:param enable_http2: `bool`, optional (kernel default is True)
197+
Kernel backend only. Negotiate HTTP/2 for HTTPS requests, with
198+
HTTP/1.1 fallback when the peer does not support HTTP/2. Set
199+
``False`` to force HTTP/1.1 for authentication, SQL requests,
200+
result downloads, and telemetry. Requires a kernel wheel with
201+
HTTP/2 configuration support.
196202
:param enable_geospatial_support: `bool`, optional (default is False)
197203
Kernel backend only. Controls the public representation of
198204
``GEOMETRY`` and ``GEOGRAPHY`` result values. ``True`` returns

‎src/databricks/sql/session.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ def _create_backend(
337337
retry_options=kernel_retry_options,
338338
request_timeout_secs=kwargs.get("_socket_timeout"),
339339
max_connections=kwargs.get("_pool_maxsize") or None,
340+
enable_http2=kwargs.get("enable_http2"),
340341
use_cloud_fetch=kwargs.get("use_cloud_fetch", True),
341342
max_download_threads=kwargs.get("max_download_threads", 16),
342343
enable_geospatial_support=kwargs.get(

‎tests/unit/test_kernel_client.py‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,45 @@ def fake_session(**options):
407407
assert configuration == original
408408

409409

410+
@pytest.mark.parametrize("enabled", [None, True, False])
411+
def test_open_session_preserves_http2_option(monkeypatch, enabled):
412+
captured = {}
413+
414+
def fake_session(**kwargs):
415+
captured.update(kwargs)
416+
session = MagicMock()
417+
session.session_id = "sess-id"
418+
return session
419+
420+
monkeypatch.setattr(kernel_client._kernel, "Session", fake_session)
421+
client = kernel_client.KernelDatabricksClient(
422+
server_hostname="example.cloud.databricks.com",
423+
http_path="/sql/1.0/warehouses/abc",
424+
auth_provider=AccessTokenAuthProvider("dapi-test"),
425+
ssl_options=None,
426+
**({"enable_http2": enabled} if enabled is not None else {}),
427+
)
428+
client.open_session(session_configuration=None, catalog=None, schema=None)
429+
if enabled is None:
430+
assert "enable_http2" not in captured
431+
else:
432+
assert captured["enable_http2"] is enabled
433+
434+
435+
@pytest.mark.parametrize("value", ["false", 0, 1])
436+
def test_http2_option_rejects_non_boolean(value):
437+
with pytest.raises(ValueError, match="enable_http2 must be a bool"):
438+
kernel_client._kernel_http2_kwargs(value)
439+
440+
441+
def test_http2_option_rejects_unsupported_kernel(monkeypatch):
442+
monkeypatch.setattr(kernel_client._kernel, "Session", lambda *, host: None)
443+
assert kernel_client._kernel_http2_kwargs(None) == {}
444+
for enabled in [True, False]:
445+
with pytest.raises(kernel_client.NotSupportedError, match="HTTP/2"):
446+
kernel_client._kernel_http2_kwargs(enabled)
447+
448+
410449
@pytest.mark.parametrize("timeout", [None, 0, 12.5])
411450
def test_open_session_passes_request_timeout_to_kernel(monkeypatch, timeout):
412451
captured = {}

‎tests/unit/test_session.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ def test_retry_and_socket_timeout_threaded_into_kernel_client(self):
540540
_pool_maxsize=41,
541541
use_cloud_fetch=False,
542542
max_download_threads=4,
543+
enable_http2=False,
543544
enable_geospatial_support=False,
544545
)
545546
try:
@@ -553,6 +554,7 @@ def test_retry_and_socket_timeout_threaded_into_kernel_client(self):
553554
assert kwargs["max_connections"] == 41
554555
assert kwargs["use_cloud_fetch"] is False
555556
assert kwargs["max_download_threads"] == 4
557+
assert kwargs["enable_http2"] is False
556558
assert kwargs["enable_geospatial_support"] is False
557559
finally:
558560
conn.close()
@@ -569,6 +571,7 @@ def test_retry_and_socket_timeout_threaded_into_kernel_client(self):
569571
_, kwargs = mock_kernel_client.call_args
570572
assert kwargs["max_connections"] is None
571573
assert kwargs["max_download_threads"] == 16
574+
assert kwargs["enable_http2"] is None
572575
finally:
573576
conn.close()
574577

0 commit comments

Comments
 (0)