1717 ASYNC_QUERY_STATUS_SUCCESSFUL ,
1818 AsyncQueryInfo ,
1919 BaseConnection ,
20+ _parse_async_query_info_results ,
2021)
2122from firebolt .common .cache import _firebolt_system_engine_cache
2223from firebolt .common .constants import DEFAULT_TIMEOUT_SECONDS
@@ -92,34 +93,41 @@ def cursor(self, **kwargs: Any) -> Cursor:
9293 return c
9394
9495 # Server-side async methods
95- async def _get_async_query_info (self , token : str ) -> AsyncQueryInfo :
96+ async def get_async_query_info (self , token : str ) -> List [AsyncQueryInfo ]:
97+ """
98+ Retrieve information about an asynchronous query using its token.
99+ This method fetches the status and details of an asynchronous query
100+ identified by the provided token.
101+ Args:
102+ token (str): The token identifying the asynchronous query.
103+ Returns:
104+ List[AsyncQueryInfo]: A list of AsyncQueryInfo objects containing
105+ details about the asynchronous query.
106+ """
107+
96108 if self .cursor_type != CursorV2 :
97109 raise FireboltError (
98110 "This method is only supported for connection with service account."
99111 )
100112 cursor = self .cursor ()
101113 await cursor .execute (ASYNC_QUERY_STATUS_REQUEST , [token ])
102- result = await cursor .fetchone ()
103- if cursor . rowcount != 1 or not result :
114+ results = await cursor .fetchall ()
115+ if not results :
104116 raise FireboltError ("Unexpected result from async query status request." )
105117 columns = cursor .description
106- result_dict = dict (zip ([column .name for column in columns ], result ))
118+ columns_names = [column .name for column in columns ]
119+ return _parse_async_query_info_results (results , columns_names )
107120
108- if not result_dict .get ("status" ) or not result_dict .get ("query_id" ):
109- raise FireboltError (
110- "Something went wrong - async query status request returned "
111- "unexpected result with status and/or query id missing. "
112- "Rerun the command and reach out to Firebolt support if "
113- "the issue persists."
121+ def _raise_if_multiple_async_results (
122+ self , async_query_info : List [AsyncQueryInfo ]
123+ ) -> None :
124+ # We expect only one result in current implementation
125+ if len (async_query_info ) != 1 :
126+ raise NotImplementedError (
127+ "Async query status request returned more than one result. "
128+ "This is not supported yet."
114129 )
115130
116- # Only pass the expected keys to AsyncQueryInfo
117- filtered_result_dict = {
118- k : v for k , v in result_dict .items () if k in AsyncQueryInfo ._fields
119- }
120-
121- return AsyncQueryInfo (** filtered_result_dict )
122-
123131 async def is_async_query_running (self , token : str ) -> bool :
124132 """
125133 Check if an async query is still running.
@@ -130,8 +138,10 @@ async def is_async_query_running(self, token: str) -> bool:
130138 Returns:
131139 bool: True if async query is still running, False otherwise
132140 """
133- async_query_details = await self ._get_async_query_info (token )
134- return async_query_details .status == ASYNC_QUERY_STATUS_RUNNING
141+ async_query_info = await self .get_async_query_info (token )
142+ self ._raise_if_multiple_async_results (async_query_info )
143+ # We expect only one result
144+ return async_query_info [0 ].status == ASYNC_QUERY_STATUS_RUNNING
135145
136146 async def is_async_query_successful (self , token : str ) -> Optional [bool ]:
137147 """
@@ -144,10 +154,12 @@ async def is_async_query_successful(self, token: str) -> Optional[bool]:
144154 bool: None if the query is still running, True if successful,
145155 False otherwise
146156 """
147- async_query_details = await self ._get_async_query_info (token )
148- if async_query_details .status == ASYNC_QUERY_STATUS_RUNNING :
157+ async_query_info_list = await self .get_async_query_info (token )
158+ self ._raise_if_multiple_async_results (async_query_info_list )
159+ async_query_info = async_query_info_list [0 ]
160+ if async_query_info .status == ASYNC_QUERY_STATUS_RUNNING :
149161 return None
150- return async_query_details .status == ASYNC_QUERY_STATUS_SUCCESSFUL
162+ return async_query_info .status == ASYNC_QUERY_STATUS_SUCCESSFUL
151163
152164 async def cancel_async_query (self , token : str ) -> None :
153165 """
@@ -156,10 +168,10 @@ async def cancel_async_query(self, token: str) -> None:
156168 Args:
157169 token: Async query token. Can be obtained from Cursor.async_query_token.
158170 """
159- async_query_details = await self ._get_async_query_info (token )
160- async_query_id = async_query_details . query_id
171+ async_query_info = await self .get_async_query_info (token )
172+ self . _raise_if_multiple_async_results ( async_query_info )
161173 cursor = self .cursor ()
162- await cursor .execute (ASYNC_QUERY_CANCEL , [async_query_id ])
174+ await cursor .execute (ASYNC_QUERY_CANCEL , [async_query_info [ 0 ]. query_id ])
163175
164176 # Context manager support
165177 async def __aenter__ (self ) -> Connection :
0 commit comments