@@ -1146,3 +1146,104 @@ def get_query_execution(query_execution_id: str, boto3_session: Optional[boto3.S
11461146 QueryExecutionId = query_execution_id ,
11471147 )
11481148 return cast (Dict [str , Any ], response ["QueryExecution" ])
1149+
1150+
1151+ def get_query_executions (
1152+ query_execution_ids : List [str ], return_unprocessed : bool = False , boto3_session : Optional [boto3 .Session ] = None
1153+ ) -> Union [Tuple [pd .DataFrame , pd .DataFrame ], pd .DataFrame ]:
1154+ """From specified query execution IDs, return a DataFrame of query execution details.
1155+
1156+ https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/athena.html#Athena.Client.batch_get_query_execution
1157+
1158+ Parameters
1159+ ----------
1160+ query_execution_ids : List[str]
1161+ Athena query execution IDs.
1162+ return_unprocessed: bool.
1163+ True to also return query executions id that are unable to be processed.
1164+ False to only return DataFrame of query execution details.
1165+ Default is False
1166+ boto3_session : boto3.Session(), optional
1167+ Boto3 Session. The default boto3 session will be used if boto3_session receive None.
1168+
1169+ Returns
1170+ -------
1171+ DataFrame
1172+ DataFrame contain information about query execution details.
1173+
1174+ DataFrame
1175+ DataFrame contain information about unprocessed query execution ids.
1176+
1177+ Examples
1178+ --------
1179+ >>> import awswrangler as wr
1180+ >>> query_executions_df, unprocessed_query_executions_df = wr.athena.get_query_executions(
1181+ query_execution_ids=['query-execution-id','query-execution-id1']
1182+ )
1183+ """
1184+ chunked_size : int = 50
1185+ query_executions : List [Dict [str , Any ]] = []
1186+ unprocessed_query_execution : List [Dict [str , str ]] = []
1187+ client_athena : boto3 .client = _utils .client (service_name = "athena" , session = boto3_session )
1188+ for i in range (0 , len (query_execution_ids ), chunked_size ):
1189+ response = client_athena .batch_get_query_execution (QueryExecutionIds = query_execution_ids [i : i + chunked_size ])
1190+ query_executions += response ["QueryExecutions" ]
1191+ unprocessed_query_execution += response ["UnprocessedQueryExecutionIds" ]
1192+ if unprocessed_query_execution and not return_unprocessed :
1193+ _logger .warning (
1194+ "Some of query execution ids are unable to be processed."
1195+ "Set return_unprocessed to True to get unprocessed query execution ids"
1196+ )
1197+ if return_unprocessed :
1198+ return pd .json_normalize (query_executions ), pd .json_normalize (unprocessed_query_execution )
1199+ return pd .json_normalize (query_executions )
1200+
1201+
1202+ def list_query_executions (workgroup : Optional [str ] = None , boto3_session : Optional [boto3 .Session ] = None ) -> List [str ]:
1203+ """Fetch list query execution IDs ran in specified workgroup or primary work group if not specified.
1204+
1205+ https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/athena.html#Athena.Client.list_query_executions
1206+
1207+ Parameters
1208+ ----------
1209+ workgroup : str
1210+ The name of the workgroup from which the query_id are being returned.
1211+ If not specified, a list of available query execution IDs for the queries in the primary workgroup is returned.
1212+ boto3_session : boto3.Session(), optional
1213+ Boto3 Session. The default boto3 session will be used if boto3_session receive None.
1214+
1215+ Returns
1216+ -------
1217+ List[str]
1218+ List of query execution IDs.
1219+
1220+ Examples
1221+ --------
1222+ >>> import awswrangler as wr
1223+ >>> res = wr.athena.list_query_executions(workgroup='workgroup-name')
1224+
1225+ """
1226+ client_athena : boto3 .client = _utils .client (service_name = "athena" , session = boto3_session )
1227+ kwargs : Dict [str , Any ] = {"base" : 1 }
1228+ if workgroup :
1229+ kwargs ["WorkGroup" ] = workgroup
1230+ query_list : List [str ] = []
1231+ response : Dict [str , Any ] = _utils .try_it (
1232+ f = client_athena .list_query_executions ,
1233+ ex = botocore .exceptions .ClientError ,
1234+ ex_code = "ThrottlingException" ,
1235+ max_num_tries = 5 ,
1236+ ** kwargs ,
1237+ )
1238+ query_list += response ["QueryExecutionIds" ]
1239+ while "NextToken" in response :
1240+ kwargs ["NextToken" ] = response ["NextToken" ]
1241+ response = _utils .try_it (
1242+ f = client_athena .list_query_executions ,
1243+ ex = botocore .exceptions .ClientError ,
1244+ ex_code = "ThrottlingException" ,
1245+ max_num_tries = 5 ,
1246+ ** kwargs ,
1247+ )
1248+ query_list += response ["QueryExecutionIds" ]
1249+ return query_list
0 commit comments