async static Task <List <Dictionary <String, String> > > getQueryExecution(IAmazonAthena client, String id) { List <Dictionary <String, String> > items = new List <Dictionary <String, String> >(); GetQueryExecutionResponse results = null; QueryExecution q = null; /* Declare query execution request object */ GetQueryExecutionRequest qReq = new GetQueryExecutionRequest() { QueryExecutionId = id }; /* Poll API to determine when the query completed */ do { results = await client.GetQueryExecutionAsync(qReq); q = results.QueryExecution; await Task.Delay(5000); //Wait for 5sec before polling again } while (q.Status.State == "RUNNING" || q.Status.State == "QUEUED"); Console.WriteLine("Data Scanned for {0}: {1} Bytes", id, q.Statistics.DataScannedInBytes); /* Declare query results request object */ GetQueryResultsRequest resReq = new GetQueryResultsRequest() { QueryExecutionId = id, MaxResults = 10 }; GetQueryResultsResponse resResp = null; /* Page through results and request additional pages if available */ do { resResp = await client.GetQueryResultsAsync(resReq); /* Loop over result set and create a dictionary with column name for key and data for value */ foreach (Row row in resResp.ResultSet.Rows) { Dictionary <String, String> dict = new Dictionary <String, String>(); for (var i = 0; i < resResp.ResultSet.ResultSetMetadata.ColumnInfo.Count; i++) { dict.Add(resResp.ResultSet.ResultSetMetadata.ColumnInfo[i].Name, row.Data[i].VarCharValue); } items.Add(dict); } if (resResp.NextToken != null) { resReq.NextToken = resResp.NextToken; } } while (resResp.NextToken != null); /* Return List of dictionary per row containing column name and value */ return(items); }
async IAsyncEnumerable <GetQueryResultsResponse> IPaginator <GetQueryResultsResponse> .PaginateAsync(CancellationToken cancellationToken = default) { if (Interlocked.Exchange(ref _isPaginatorInUse, 1) != 0) { throw new System.InvalidOperationException("Paginator has already been consumed and cannot be reused. Please create a new instance."); } var nextToken = _request.NextToken; GetQueryResultsResponse response; do { _request.NextToken = nextToken; response = await _client.GetQueryResultsAsync(_request, cancellationToken).ConfigureAwait(false); nextToken = response.NextToken; cancellationToken.ThrowIfCancellationRequested(); yield return(response); }while (nextToken != null); }
private Amazon.Athena.Model.GetQueryResultsResponse CallAWSServiceOperation(IAmazonAthena client, Amazon.Athena.Model.GetQueryResultsRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Athena", "GetQueryResults"); try { #if DESKTOP return(client.GetQueryResults(request)); #elif CORECLR return(client.GetQueryResultsAsync(request).GetAwaiter().GetResult()); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } }
public async Task <List <Dictionary <string, string> > > GetQueryExecution(IAmazonAthena client, string id) { List <Dictionary <String, String> > items = new List <Dictionary <String, String> >(); GetQueryExecutionResponse results = null; QueryExecution queryExecution = null; /* Declare query execution request object */ GetQueryExecutionRequest queryExReq = new GetQueryExecutionRequest() { QueryExecutionId = id }; /* Poll API to determine when the query completed */ do { try { results = await client.GetQueryExecutionAsync(queryExReq); queryExecution = results.QueryExecution; _logger.LogInformation("Status: {0}... {1}", queryExecution.Status.State, queryExecution.Status.StateChangeReason); await Task.Delay(5000); //Wait for 5sec before polling again } catch (InvalidRequestException e) { _logger.LogInformation("GetQueryExec Error: {0}", e.Message); } } while (queryExecution.Status.State == "RUNNING" || queryExecution.Status.State == "QUEUED"); _logger.LogInformation("Data Scanned for {0}: {1} Bytes", id, queryExecution.Statistics.DataScannedInBytes); /* Declare query results request object */ GetQueryResultsRequest queryResultRequest = new GetQueryResultsRequest() { QueryExecutionId = id, MaxResults = 10 }; GetQueryResultsResponse queryResult = null; /* Page through results and request additional pages if available */ do { queryResult = await client.GetQueryResultsAsync(queryResultRequest); /* Loop over result set and create a dictionary with column name for key and data for value */ foreach (Row row in queryResult.ResultSet.Rows) { Dictionary <String, String> dict = new Dictionary <String, String>(); for (var i = 0; i < queryResult.ResultSet.ResultSetMetadata.ColumnInfo.Count; i++) { dict.Add(queryResult.ResultSet.ResultSetMetadata.ColumnInfo[i].Name, row.Data[i].VarCharValue); } items.Add(dict); } if (queryResult.NextToken != null) { queryResultRequest.NextToken = queryResult.NextToken; } } while (queryResult.NextToken != null); /* Return List of dictionary per row containing column name and value */ return(items); }
async static Task <List <Dictionary <String, String> > > getQueryExecution(IAmazonAthena client, String id) { List <Dictionary <String, String> > items = new List <Dictionary <String, String> >(); GetQueryExecutionResponse results = null; QueryExecution q = null; /* Declare query execution request object */ GetQueryExecutionRequest qReq = new GetQueryExecutionRequest() { QueryExecutionId = id }; /* Poll API to determine when the query completed */ do { List <Dictionary <string, string> > lists = new List <Dictionary <string, string> >(); try { results = await client.GetQueryExecutionAsync(qReq); if (results == null) { Dictionary <string, string> dic1 = new Dictionary <string, string>(); dic1.Add("error", "results is null"); lists.Add(dic1); return(lists); } q = results.QueryExecution; if (q == null) { Dictionary <string, string> dic3 = new Dictionary <string, string>(); dic3.Add("error", "q is null"); lists.Add(dic3); return(lists); } Console.WriteLine("Status: {0}... {1}", q.Status.State, q.Status.StateChangeReason); await Task.Delay(5000); //Wait for 5sec before polling again } catch (InvalidRequestException e) { Dictionary <string, string> dic2 = new Dictionary <string, string>(); dic2.Add("error", "exception : " + " (Run method) " + " : " + e.Message); lists.Add(dic2); Console.WriteLine("GetQueryExec Error: {0}", e.Message); return(lists); } } while (q.Status.State == "RUNNING" || q.Status.State == "QUEUED"); Console.WriteLine("Data Scanned for {0}: {1} Bytes", id, q.Statistics.DataScannedInBytes); /* Declare query results request object */ GetQueryResultsRequest resReq = new GetQueryResultsRequest() { QueryExecutionId = id, MaxResults = 20 }; GetQueryResultsResponse resResp = null; /* Page through results and request additional pages if available */ Dictionary <String, String> dic = new Dictionary <String, String>(); List <Dictionary <String, String> > l = new List <Dictionary <String, String> >(); do { resResp = await client.GetQueryResultsAsync(resReq); //l.Add(dict); /* Loop over result set and create a dictionary with column name for key and data for value */ foreach (Row row in resResp.ResultSet.Rows) { Dictionary <String, String> dict = new Dictionary <String, String>(); for (var i = 0; i < resResp.ResultSet.ResultSetMetadata.ColumnInfo.Count; i++) { dict.Add(resResp.ResultSet.ResultSetMetadata.ColumnInfo[i].Name, row.Data[i].VarCharValue); } items.Add(dict); } if (resResp.NextToken != null) { resReq.NextToken = resResp.NextToken; } } while (resResp.NextToken != null); if (items == null) { dic.Add("error", "items are null here"); l.Add(dic); return(l); } /* Return List of dictionary per row containing column name and value */ return(items); }