Skip to content

Commit fb165ab

Browse files
committed
Forward kernel telemetry circuit breaker config
1 parent 3cf3655 commit fb165ab

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
SessionId,
4444
)
4545
from databricks.sql.exc import (
46+
Error,
4647
InterfaceError,
4748
NotSupportedError,
4849
ProgrammingError,
@@ -71,6 +72,8 @@
7172
# per-request skip-and-warn.
7273
_KERNEL_MANAGED_HEADERS = frozenset({"authorization", "x-databricks-org-id"})
7374

75+
TIMESTAMP_AS_STRING_CONFIG = "spark.thriftserver.arrowBasedRowSet.timestampAsString"
76+
7477
# Leading verbs of SQL volume/staging statements. Detected by the
7578
# leading token (case-insensitive) so the kernel backend can fail loud
7679
# on staging ops it can't service — see ``execute_command``.
@@ -107,6 +110,18 @@ def _strip_leading_sql_comments(sql: str) -> str:
107110
return sql[i:]
108111

109112

113+
def _check_session_configuration(session_configuration: Dict[str, str]) -> None:
114+
# This client expects timestampAsString to be false, so do not allow overrides.
115+
if session_configuration.get(TIMESTAMP_AS_STRING_CONFIG, "false").lower() != "false":
116+
raise Error(
117+
"Invalid session configuration: {} cannot be changed "
118+
"while using the Databricks SQL connector, it must be false not {}".format(
119+
TIMESTAMP_AS_STRING_CONFIG,
120+
session_configuration[TIMESTAMP_AS_STRING_CONFIG],
121+
)
122+
)
123+
124+
110125
def _is_not_found(exc: BaseException) -> bool:
111126
"""True iff ``exc`` is a kernel ``NotFound`` error (HTTP 404 /
112127
``STATEMENT_NOT_FOUND``).
@@ -362,6 +377,7 @@ def open_session(
362377
session_conf: Optional[Dict[str, str]] = None
363378
if session_configuration:
364379
session_conf = {k: str(v) for k, v in session_configuration.items()}
380+
_check_session_configuration(session_conf)
365381
# The kwarg builds run INSIDE the try so the ``finally`` scrub
366382
# below always fires — including when ``kernel_auth_kwargs``
367383
# itself raises mid-build (e.g. an OAuth token-exchange failure

tests/unit/test_kernel_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def __init__(
8989
from databricks.sql.backend.types import CommandId, CommandState
9090
from databricks.sql.exc import (
9191
DatabaseError,
92+
Error,
9293
InterfaceError,
9394
NotSupportedError,
9495
OperationalError,
@@ -306,6 +307,24 @@ def test_open_session_rejects_double_open(monkeypatch):
306307
c.open_session(session_configuration=None, catalog=None, schema=None)
307308

308309

310+
def test_open_session_rejects_timestamp_as_string_true(monkeypatch):
311+
session_ctor = MagicMock()
312+
monkeypatch.setattr(kernel_client._kernel, "Session", session_ctor)
313+
314+
c = _make_client()
315+
316+
with pytest.raises(Error, match="timestampAsString cannot be changed"):
317+
c.open_session(
318+
session_configuration={
319+
"spark.thriftserver.arrowBasedRowSet.timestampAsString": True
320+
},
321+
catalog=None,
322+
schema=None,
323+
)
324+
325+
session_ctor.assert_not_called()
326+
327+
309328
@pytest.mark.parametrize(
310329
"kwargs, expected_flag",
311330
[

0 commit comments

Comments
 (0)