Skip to content

Commit 0a8226c

Browse files
fix typing
Signed-off-by: varun-edachali-dbx <varun.edachali@databricks.com>
1 parent 9b9735e commit 0a8226c

File tree

4 files changed

+10
-80
lines changed

4 files changed

+10
-80
lines changed

src/databricks/sql/backend/thrift_backend.py

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def open_session(self, session_configuration, catalog, schema) -> SessionId:
584584
self._check_initial_namespace(catalog, schema, response)
585585
self._check_protocol_version(response)
586586
if response.sessionHandle is None:
587-
return None
587+
raise DatabaseError("Server returned null session handle")
588588
info = (
589589
{"serverProtocolVersion": response.serverProtocolVersion}
590590
if response.serverProtocolVersion
@@ -875,66 +875,6 @@ def get_execution_result(self, command_id: CommandId, cursor):
875875
arrow_schema_bytes=schema_bytes,
876876
)
877877

878-
def get_execution_result(self, op_handle, cursor):
879-
880-
assert op_handle is not None
881-
882-
req = ttypes.TFetchResultsReq(
883-
operationHandle=ttypes.TOperationHandle(
884-
op_handle.operationId,
885-
op_handle.operationType,
886-
False,
887-
op_handle.modifiedRowCount,
888-
),
889-
maxRows=cursor.arraysize,
890-
maxBytes=cursor.buffer_size_bytes,
891-
orientation=ttypes.TFetchOrientation.FETCH_NEXT,
892-
includeResultSetMetadata=True,
893-
)
894-
895-
resp = self.make_request(self._client.FetchResults, req)
896-
897-
t_result_set_metadata_resp = resp.resultSetMetadata
898-
899-
lz4_compressed = t_result_set_metadata_resp.lz4Compressed
900-
is_staging_operation = t_result_set_metadata_resp.isStagingOperation
901-
has_more_rows = resp.hasMoreRows
902-
description = self._hive_schema_to_description(
903-
t_result_set_metadata_resp.schema
904-
)
905-
906-
if pyarrow:
907-
schema_bytes = (
908-
t_result_set_metadata_resp.arrowSchema
909-
or self._hive_schema_to_arrow_schema(t_result_set_metadata_resp.schema)
910-
.serialize()
911-
.to_pybytes()
912-
)
913-
else:
914-
schema_bytes = None
915-
916-
queue = ResultSetQueueFactory.build_queue(
917-
row_set_type=resp.resultSetMetadata.resultFormat,
918-
t_row_set=resp.results,
919-
arrow_schema_bytes=schema_bytes,
920-
max_download_threads=self.max_download_threads,
921-
lz4_compressed=lz4_compressed,
922-
description=description,
923-
ssl_options=self._ssl_options,
924-
)
925-
926-
return ExecuteResponse(
927-
arrow_queue=queue,
928-
status=resp.status,
929-
has_been_closed_server_side=False,
930-
has_more_rows=has_more_rows,
931-
lz4_compressed=lz4_compressed,
932-
is_staging_operation=is_staging_operation,
933-
command_handle=op_handle,
934-
description=description,
935-
arrow_schema_bytes=schema_bytes,
936-
)
937-
938878
def _wait_until_command_done(self, op_handle, initial_operation_status_resp):
939879
if initial_operation_status_resp:
940880
self._check_command_not_in_error_or_closed_state(
@@ -1165,10 +1105,6 @@ def _handle_execute_response_async(self, resp, cursor):
11651105
cursor.active_command_id = command_id
11661106
self._check_direct_results_for_error(resp.directResults)
11671107

1168-
def _handle_execute_response_async(self, resp, cursor):
1169-
cursor.active_op_handle = resp.operationHandle
1170-
self._check_direct_results_for_error(resp.directResults)
1171-
11721108
def fetch_results(
11731109
self,
11741110
command_id: CommandId,

src/databricks/sql/backend/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def guid_to_hex_id(guid: bytes) -> str:
1818
try:
1919
this_uuid = uuid.UUID(bytes=guid)
2020
except Exception as e:
21-
logger.debug(f"Unable to convert bytes to UUID: {guid} -- {str(e)}")
21+
logger.debug(f"Unable to convert bytes to UUID: {guid!r} -- {str(e)}")
2222
return str(guid)
2323
return str(this_uuid)
2424

src/databricks/sql/client.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,8 @@ def get_query_state(self) -> "TOperationState":
855855
:return:
856856
"""
857857
self._check_not_closed()
858+
if self.active_command_id is None:
859+
raise Error("No active command to get state for")
858860
return self.backend.get_query_state(self.active_command_id)
859861

860862
def is_query_pending(self):
@@ -870,19 +872,6 @@ def is_query_pending(self):
870872
ttypes.TOperationState.PENDING_STATE,
871873
]
872874

873-
def is_query_pending(self):
874-
"""
875-
Checks whether the async executing query is in pending state or not
876-
877-
:return:
878-
"""
879-
operation_state = self.get_query_state()
880-
881-
return not operation_state or operation_state in [
882-
ttypes.TOperationState.RUNNING_STATE,
883-
ttypes.TOperationState.PENDING_STATE,
884-
]
885-
886875
def get_async_execution_result(self):
887876
"""
888877

tests/unit/test_thrift_backend.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class ThriftBackendTestSuite(unittest.TestCase):
5252
open_session_resp = ttypes.TOpenSessionResp(
5353
status=okay_status,
5454
serverProtocolVersion=ttypes.TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V4,
55+
sessionHandle=session_handle,
5556
)
5657

5758
metadata_resp = ttypes.TGetResultSetMetadataResp(
@@ -177,7 +178,9 @@ def test_okay_protocol_versions_succeed(self, tcli_service_client_cass):
177178

178179
for protocol_version in good_protocol_versions:
179180
t_http_client_instance.OpenSession.return_value = ttypes.TOpenSessionResp(
180-
status=self.okay_status, serverProtocolVersion=protocol_version
181+
status=self.okay_status,
182+
serverProtocolVersion=protocol_version,
183+
sessionHandle=self.session_handle,
181184
)
182185

183186
thrift_backend = self._make_fake_thrift_backend()
@@ -2061,6 +2064,7 @@ def _construct_open_session_with_namespace(self, can_use_multiple_cats, cat, sch
20612064
serverProtocolVersion=ttypes.TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V4,
20622065
canUseMultipleCatalogs=can_use_multiple_cats,
20632066
initialNamespace=ttypes.TNamespace(catalogName=cat, schemaName=schem),
2067+
sessionHandle=self.session_handle,
20642068
)
20652069

20662070
@patch("databricks.sql.backend.thrift_backend.TCLIService.Client", autospec=True)
@@ -2160,6 +2164,7 @@ def test_protocol_v3_fails_if_initial_namespace_set(self, tcli_client_class):
21602164
serverProtocolVersion=ttypes.TProtocolVersion.SPARK_CLI_SERVICE_PROTOCOL_V3,
21612165
canUseMultipleCatalogs=True,
21622166
initialNamespace=ttypes.TNamespace(catalogName="cat", schemaName="schem"),
2167+
sessionHandle=self.session_handle,
21632168
)
21642169

21652170
backend = ThriftDatabricksClient(

0 commit comments

Comments
 (0)