Skip to content

Commit c505cea

Browse files
nithinkdbJesse
authored andcommitted
[PECO-1137] Reintroduce protocol checking to Python test fw (#248)
* Put in some unit tests, will add e2e Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Added e2e test Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Linted Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * re-bumped thrift files Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Changed structure to store protocol version as feature of connection Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Fixed parameters test Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Fixed comments Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Update src/databricks/sql/client.py Co-authored-by: Jesse <jwhitehouse@airpost.net> Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Fixed comments Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> * Removed extra indent Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> --------- Signed-off-by: nithinkdb <nithin.krishnamurthi@databricks.com> Co-authored-by: Jesse <jwhitehouse@airpost.net> Signed-off-by: Sai Shree Pradhan <saishree.pradhan@databricks.com>
1 parent f0dea6c commit c505cea

File tree

5 files changed

+4052
-329
lines changed

5 files changed

+4052
-329
lines changed

src/databricks/sql/client.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
SessionAlreadyClosedError,
1414
CursorAlreadyClosedError,
1515
)
16+
from databricks.sql.thrift_api.TCLIService import ttypes
1617
from databricks.sql.thrift_backend import ThriftBackend
1718
from databricks.sql.utils import (
1819
ExecuteResponse,
@@ -196,9 +197,11 @@ def read(self) -> Optional[OAuthToken]:
196197
**kwargs,
197198
)
198199

199-
self._session_handle = self.thrift_backend.open_session(
200+
self._open_session_resp = self.thrift_backend.open_session(
200201
session_configuration, catalog, schema
201202
)
203+
self._session_handle = self._open_session_resp.sessionHandle
204+
self.protocol_version = self.get_protocol_version(self._open_session_resp)
202205
self.use_cloud_fetch = kwargs.get("use_cloud_fetch", True)
203206
self.open = True
204207
logger.info("Successfully opened session " + str(self.get_session_id_hex()))
@@ -225,6 +228,30 @@ def __del__(self):
225228
def get_session_id(self):
226229
return self.thrift_backend.handle_to_id(self._session_handle)
227230

231+
@staticmethod
232+
def get_protocol_version(openSessionResp):
233+
"""
234+
Since the sessionHandle will sometimes have a serverProtocolVersion, it takes
235+
precedence over the serverProtocolVersion defined in the OpenSessionResponse.
236+
"""
237+
if (
238+
openSessionResp.sessionHandle
239+
and hasattr(openSessionResp.sessionHandle, "serverProtocolVersion")
240+
and openSessionResp.sessionHandle.serverProtocolVersion
241+
):
242+
return openSessionResp.sessionHandle.serverProtocolVersion
243+
return openSessionResp.serverProtocolVersion
244+
245+
@staticmethod
246+
def server_parameterized_queries_enabled(protocolVersion):
247+
if (
248+
protocolVersion
249+
and protocolVersion >= ttypes.TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V8
250+
):
251+
return True
252+
else:
253+
return False
254+
228255
def get_session_id_hex(self):
229256
return self.thrift_backend.handle_to_hex_id(self._session_handle)
230257

@@ -501,6 +528,13 @@ def execute(
501528
"""
502529
if parameters is None:
503530
parameters = []
531+
532+
elif not Connection.server_parameterized_queries_enabled(
533+
self.connection.protocol_version
534+
):
535+
raise NotSupportedError(
536+
"Parameterized operations are not supported by this server. DBR 14.1 is required."
537+
)
504538
else:
505539
parameters = named_parameters_to_tsparkparams(parameters)
506540

0 commit comments

Comments
 (0)