Skip to content

Commit 66a5f73

Browse files
committed
fix: default Python geospatial results to strings
Signed-off-by: Cathleen Yan <58714163+cathleeny@users.noreply.github.com>
1 parent 54fbd76 commit 66a5f73

6 files changed

Lines changed: 46 additions & 8 deletions

File tree

‎CHANGELOG.md‎

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

33
# Unreleased
4-
- Add the default-enabled, kernel-only `enable_geospatial_support` connection option. GEOMETRY / GEOGRAPHY results are exposed as `{"srid": int, "wkb": bytes}` values when true or WKT / EWKT strings when false.
4+
- Add the kernel-only `enable_geospatial_support` connection option (default `False`). GEOMETRY / GEOGRAPHY results are exposed as `{"srid": int, "wkb": bytes}` values when true or WKT / EWKT strings when false.
55
- Add the `escape_catalog_name` connection parameter (default `False`) to opt in to escaping unescaped `_` in metadata catalog names on Thrift and kernel connections. Existing escapes and `%` wildcards are preserved.
66

77
# 4.6.0 (2026-09-24)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def _kernel_session_accepts_kwarg(name: str) -> bool:
171171

172172

173173
def _kernel_geospatial_kwargs(value: bool) -> Dict[str, bool]:
174-
"""Build the default-enabled native geospatial-support kwarg.
174+
"""Build the explicit native geospatial-support kwarg.
175175
176176
The value is always passed explicitly so the driver and kernel contracts
177177
cannot drift. Older kernel wheels do not declare
@@ -283,12 +283,12 @@ def __init__(
283283
# The kernel binding owns type and range validation.
284284
self._request_timeout_secs = kwargs.get("request_timeout_secs")
285285
self._max_connections = kwargs.get("max_connections")
286-
# Default-enabled native GEOMETRY / GEOGRAPHY support. True requests
286+
# Opt-in native GEOMETRY / GEOGRAPHY support. True requests
287287
# the canonical Arrow struct and surfaces as ``{"srid": int, "wkb":
288288
# bytes}`` through pyarrow; False requests WKT / EWKT strings. This is
289289
# intentionally separate from ``session_configuration``: it is never
290290
# forwarded to SEA.
291-
self._enable_geospatial_support = kwargs.get("enable_geospatial_support", True)
291+
self._enable_geospatial_support = kwargs.get("enable_geospatial_support", False)
292292
# Kernel telemetry phase 7 adds binding/runtime identity and
293293
# telemetry config kwargs directly to ``databricks_sql_kernel.Session``.
294294
self._telemetry_options = kwargs.get("telemetry_options") or {}

‎src/databricks/sql/client.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def __init__(
194194
decision. This is an intentional divergence from the
195195
Thrift/SEA paths, where an explicit ``True`` can still
196196
be suppressed by the feature flag.
197-
:param enable_geospatial_support: `bool`, optional (default is True)
197+
:param enable_geospatial_support: `bool`, optional (default is False)
198198
Kernel backend only. Controls the public representation of
199199
``GEOMETRY`` and ``GEOGRAPHY`` result values. ``True`` returns
200200
``{"srid": int, "wkb": bytes}``; ``False`` returns WKT / EWKT

‎src/databricks/sql/session.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,9 @@ def _create_backend(
332332
retry_options=kernel_retry_options,
333333
request_timeout_secs=kwargs.get("_socket_timeout"),
334334
max_connections=kwargs.get("_pool_maxsize") or None,
335-
enable_geospatial_support=kwargs.get("enable_geospatial_support", True),
335+
enable_geospatial_support=kwargs.get(
336+
"enable_geospatial_support", False
337+
),
336338
telemetry_options=kernel_telemetry_options,
337339
escape_catalog_name=kwargs.get("escape_catalog_name", False),
338340
)

‎tests/unit/test_kernel_client.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def fake_session(*, enable_geospatial_support=True, **kw):
418418
assert captured["enable_geospatial_support"] is enabled
419419

420420

421-
def test_open_session_enables_geospatial_support_by_default(monkeypatch):
421+
def test_open_session_disables_native_geospatial_support_by_default(monkeypatch):
422422
captured = {}
423423

424424
def fake_session(**kw):
@@ -437,7 +437,7 @@ def fake_session(**kw):
437437

438438
c.open_session(session_configuration=None, catalog=None, schema=None)
439439

440-
assert captured["enable_geospatial_support"] is True
440+
assert captured["enable_geospatial_support"] is False
441441

442442

443443
def test_open_session_rejects_explicit_geospatial_option_with_old_kernel(

‎tests/unit/test_session.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,42 @@ def _connect(self, **overrides):
877877
args.update(overrides)
878878
return databricks.sql.connect(**args)
879879

880+
@pytest.mark.parametrize("route", ["explicit", "recovery", "cached"])
881+
@pytest.mark.parametrize(
882+
"geospatial_kwargs, expected",
883+
[
884+
pytest.param({}, False, id="default"),
885+
pytest.param({"enable_geospatial_support": False}, False, id="disabled"),
886+
pytest.param({"enable_geospatial_support": True}, True, id="enabled"),
887+
],
888+
)
889+
@patch("%s.session.ThriftDatabricksClient" % PACKAGE)
890+
def test_kernel_routing_preserves_geospatial_representation(
891+
self, mock_thrift, route, geospatial_kwargs, expected
892+
):
893+
from databricks.sql.backend import reyden_warehouse_cache
894+
895+
mock_thrift.return_value.open_session.side_effect = self._reject()
896+
if route == "cached":
897+
reyden_warehouse_cache.mark_reyden(self.HOST, "wh-reyden")
898+
if route == "explicit":
899+
geospatial_kwargs = {**geospatial_kwargs, "use_kernel": True}
900+
901+
with self._fake_kernel() as mock_kernel:
902+
conn = self._connect(**geospatial_kwargs)
903+
try:
904+
assert conn.session.use_kernel is True
905+
assert (
906+
mock_kernel.call_args.kwargs["enable_geospatial_support"]
907+
is expected
908+
)
909+
if route == "recovery":
910+
mock_thrift.return_value.open_session.assert_called_once()
911+
else:
912+
mock_thrift.return_value.open_session.assert_not_called()
913+
finally:
914+
conn.close()
915+
880916
@patch("%s.session.ThriftDatabricksClient" % PACKAGE)
881917
def test_thrift_rejection_recovers_onto_kernel(self, mock_thrift):
882918
mock_thrift.return_value.open_session.side_effect = self._reject()

0 commit comments

Comments
 (0)