88 from databricks .sql .result_set import ResultSet
99
1010from databricks .sql .backend .databricks_client import DatabricksClient
11- from databricks .sql .backend .types import SessionId , CommandId , CommandState , BackendType
11+ from databricks .sql .backend .types import SessionId , CommandId , CommandState , BackendType , ExecuteResponse
1212from databricks .sql .exc import Error , NotSupportedError , ServerOperationError
1313from databricks .sql .backend .utils .http_client import CustomHttpClient
1414from databricks .sql .thrift_api .TCLIService import ttypes
1515from databricks .sql .types import SSLOptions
16+ from databricks .sql .utils import SeaResultSetQueueFactory
17+ from databricks .sql .backend .models .base import ResultData
1618
1719from databricks .sql .backend .models import (
1820 ExecuteStatementRequest ,
@@ -227,6 +229,70 @@ def close_session(self, session_id: SessionId) -> None:
227229 params = request .to_dict (),
228230 )
229231
232+ def _results_message_to_execute_response (self , sea_response , command_id ):
233+ """
234+ Convert a SEA response to an ExecuteResponse.
235+
236+ Args:
237+ sea_response: The response from the SEA API
238+ command_id: The command ID
239+
240+ Returns:
241+ ExecuteResponse: The normalized execute response
242+ """
243+ # Extract status
244+ status_data = sea_response .get ("status" , {})
245+ state = CommandState .from_sea_state (status_data .get ("state" , "" ))
246+
247+ # Extract description from manifest
248+ description = None
249+ manifest_data = sea_response .get ("manifest" , {})
250+ schema_data = manifest_data .get ("schema" , {})
251+ columns_data = schema_data .get ("columns" , [])
252+
253+ if columns_data :
254+ columns = []
255+ for col_data in columns_data :
256+ if not isinstance (col_data , dict ):
257+ continue
258+
259+ # Format: (name, type_code, display_size, internal_size, precision, scale, null_ok)
260+ columns .append (
261+ (
262+ col_data .get ("name" , "" ), # name
263+ col_data .get ("type_name" , "" ), # type_code
264+ None , # display_size (not provided by SEA)
265+ None , # internal_size (not provided by SEA)
266+ col_data .get ("precision" ), # precision
267+ col_data .get ("scale" ), # scale
268+ col_data .get ("nullable" , True ), # null_ok
269+ )
270+ )
271+ description = columns if columns else None
272+
273+ # Create results queue
274+ results_queue = None
275+ result_data = sea_response .get ("result" , {})
276+ if result_data :
277+ results_queue = SeaResultSetQueueFactory .build_queue (
278+ ResultData (
279+ data = result_data .get ("data_array" , None ),
280+ external_links = result_data .get ("external_links" , None )
281+ ),
282+ description = description
283+ )
284+
285+ return ExecuteResponse (
286+ command_id = command_id ,
287+ status = state ,
288+ description = description ,
289+ has_more_rows = False ,
290+ results_queue = results_queue ,
291+ has_been_closed_server_side = False ,
292+ lz4_compressed = False , # TODO: extract from response
293+ is_staging_operation = False ,
294+ )
295+
230296 def execute_command (
231297 self ,
232298 operation : str ,
@@ -444,11 +510,14 @@ def get_execution_result(
444510 )
445511
446512 # Create and return a SeaResultSet
447- from databricks .sql .backend .sea_result_set import SeaResultSet
448-
513+ from databricks .sql .result_set import SeaResultSet
514+
515+ # Convert the response to an ExecuteResponse
516+ execute_response = self ._results_message_to_execute_response (response_data , command_id )
517+
449518 return SeaResultSet (
450519 connection = cursor .connection ,
451- sea_response = response_data ,
520+ execute_response = execute_response ,
452521 sea_client = self ,
453522 buffer_size_bytes = cursor .buffer_size_bytes ,
454523 arraysize = cursor .arraysize ,
@@ -599,4 +668,4 @@ def get_columns(
599668 enforce_embedded_schema_correctness = False ,
600669 )
601670 assert result is not None , "execute_command returned None in synchronous mode"
602- return result
671+ return result
0 commit comments