66import pandas
77
88from databricks .sql .backend .sea .backend import SeaDatabricksClient
9+ from databricks .sql .backend .sea .models .base import ExternalLink , ResultData , ResultManifest
910from databricks .sql .cloud_fetch_queue import SeaCloudFetchQueue
11+ from databricks .sql .utils import SeaResultSetQueueFactory
1012
1113try :
1214 import pyarrow
@@ -465,6 +467,77 @@ def __init__(
465467 if execute_response .command_id
466468 else None
467469 )
470+
471+ # Get the response data from the SEA backend
472+ response_data = sea_client .http_client ._make_request (
473+ method = "GET" ,
474+ path = sea_client .STATEMENT_PATH_WITH_ID .format (self .statement_id ),
475+ data = {"statement_id" : self .statement_id },
476+ )
477+
478+ # Build the results queue
479+ results_queue = None
480+
481+ # Extract data from the response
482+ result_data = response_data .get ("result" , {})
483+ manifest_data = response_data .get ("manifest" , {})
484+
485+ if result_data :
486+ # Convert external links
487+ external_links = None
488+ if "external_links" in result_data :
489+ external_links = []
490+ for link_data in result_data ["external_links" ]:
491+ external_links .append (
492+ ExternalLink (
493+ external_link = link_data .get ("external_link" , "" ),
494+ expiration = link_data .get ("expiration" , "" ),
495+ chunk_index = link_data .get ("chunk_index" , 0 ),
496+ byte_count = link_data .get ("byte_count" , 0 ),
497+ row_count = link_data .get ("row_count" , 0 ),
498+ row_offset = link_data .get ("row_offset" , 0 ),
499+ next_chunk_index = link_data .get ("next_chunk_index" ),
500+ next_chunk_internal_link = link_data .get ("next_chunk_internal_link" ),
501+ http_headers = link_data .get ("http_headers" , {}),
502+ )
503+ )
504+
505+ # Create the result data object
506+ result_data_obj = ResultData (
507+ data = result_data .get ("data_array" ), external_links = external_links
508+ )
509+
510+ # Create the manifest object
511+ manifest_obj = ResultManifest (
512+ format = manifest_data .get ("format" , "" ),
513+ schema = manifest_data .get ("schema" , {}),
514+ total_row_count = manifest_data .get ("total_row_count" , 0 ),
515+ total_byte_count = manifest_data .get ("total_byte_count" , 0 ),
516+ total_chunk_count = manifest_data .get ("total_chunk_count" , 0 ),
517+ truncated = manifest_data .get ("truncated" , False ),
518+ chunks = manifest_data .get ("chunks" ),
519+ result_compression = manifest_data .get ("result_compression" ),
520+ )
521+
522+ # Build the queue based on the response data
523+ from typing import cast , List
524+
525+ # Convert description to the expected format
526+ desc = None
527+ if execute_response .description :
528+ desc = cast (List [Tuple [Any , ...]], execute_response .description )
529+
530+ results_queue = SeaResultSetQueueFactory .build_queue (
531+ result_data_obj ,
532+ manifest_obj ,
533+ str (self .statement_id ),
534+ description = desc ,
535+ schema_bytes = execute_response .arrow_schema_bytes if execute_response .arrow_schema_bytes else None ,
536+ max_download_threads = sea_client .max_download_threads ,
537+ ssl_options = sea_client .ssl_options ,
538+ sea_client = sea_client ,
539+ lz4_compressed = execute_response .lz4_compressed ,
540+ )
468541
469542 # Call parent constructor with common attributes
470543 super ().__init__ (
@@ -476,14 +549,12 @@ def __init__(
476549 status = execute_response .status ,
477550 has_been_closed_server_side = execute_response .has_been_closed_server_side ,
478551 has_more_rows = execute_response .has_more_rows ,
479- results_queue = execute_response .results_queue ,
480552 description = execute_response .description ,
481553 is_staging_operation = execute_response .is_staging_operation ,
482554 )
483555
484556 # Initialize queue for result data if not provided
485- if not self .results :
486- self .results = JsonQueue ([])
557+ self .results = results_queue or JsonQueue ([])
487558
488559 def _convert_to_row_objects (self , rows ):
489560 """
0 commit comments