@@ -1114,17 +1114,24 @@ def get_query_executions(
11141114 return pd .json_normalize (query_executions )
11151115
11161116
1117- def list_query_executions (workgroup : str | None = None , boto3_session : boto3 .Session | None = None ) -> list [str ]:
1117+ def list_query_executions (
1118+ workgroup : str | None = None ,
1119+ max_results : int | None = None ,
1120+ boto3_session : boto3 .Session | None = None ,
1121+ ) -> list [str ]:
11181122 """Fetch list query execution IDs ran in specified workgroup or primary work group if not specified.
11191123
11201124 https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/athena.html#Athena.Client.list_query_executions
11211125
11221126 Parameters
11231127 ----------
1124- workgroup : str
1128+ workgroup: str
11251129 The name of the workgroup from which the query_id are being returned.
11261130 If not specified, a list of available query execution IDs for the queries in the primary workgroup is returned.
1127- boto3_session : boto3.Session(), optional
1131+ max_results: int, optional
1132+ The maximum number of query execution IDs to return in this request.
1133+ If not present, all execution IDs will be returned.
1134+ boto3_session: boto3.Session(), optional
11281135 Boto3 Session. The default boto3 session will be used if boto3_session receive None.
11291136
11301137 Returns
@@ -1139,9 +1146,14 @@ def list_query_executions(workgroup: str | None = None, boto3_session: boto3.Ses
11391146
11401147 """
11411148 client_athena = _utils .client (service_name = "athena" , session = boto3_session )
1142- kwargs : dict [str , Any ] = {"base" : 1 }
1149+
1150+ kwargs : dict [str , Any ] = {}
11431151 if workgroup :
11441152 kwargs ["WorkGroup" ] = workgroup
1153+
1154+ if max_results is not None :
1155+ kwargs ["MaxResults" ] = min (max_results , 50 )
1156+
11451157 query_list : list [str ] = []
11461158 response = _utils .try_it (
11471159 f = client_athena .list_query_executions ,
@@ -1151,8 +1163,16 @@ def list_query_executions(workgroup: str | None = None, boto3_session: boto3.Ses
11511163 ** kwargs ,
11521164 )
11531165 query_list += response ["QueryExecutionIds" ]
1166+
11541167 while "NextToken" in response :
11551168 kwargs ["NextToken" ] = response ["NextToken" ]
1169+
1170+ if max_results is not None :
1171+ if len (query_list ) >= max_results :
1172+ break
1173+
1174+ kwargs ["MaxResults" ] = min (max_results - len (query_list ), 50 )
1175+
11561176 response = _utils .try_it (
11571177 f = client_athena .list_query_executions ,
11581178 ex = botocore .exceptions .ClientError ,
@@ -1161,5 +1181,6 @@ def list_query_executions(workgroup: str | None = None, boto3_session: boto3.Ses
11611181 ** kwargs ,
11621182 )
11631183 query_list += response ["QueryExecutionIds" ]
1184+
11641185 _logger .debug ("Running %d query executions" , len (query_list ))
11651186 return query_list
0 commit comments