private Amazon.Athena.Model.GetQueryExecutionResponse CallAWSServiceOperation(IAmazonAthena client, Amazon.Athena.Model.GetQueryExecutionRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Athena", "GetQueryExecution");
     try
     {
         #if DESKTOP
         return(client.GetQueryExecution(request));
         #elif CORECLR
         return(client.GetQueryExecutionAsync(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 static 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
            {
                try
                {
                    results = client.GetQueryExecution(qReq); //await client.GetQueryExecutionAsync(qReq);
                    q       = results.QueryExecution;
                    Console.WriteLine("Status: {0}... {1}", q.Status.State, q.Status.StateChangeReason);

                    Console.Write("<script>console.log('" + q.Status.StateChangeReason + "');</script>");

                    //await Task.Delay(5000); //Wait for 5sec before polling again
                }
                catch (InvalidRequestException e)
                {
                    Console.WriteLine("GetQueryExec Error: {0}", e.Message);
                }
            } 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 = client.GetQueryResults(resReq); //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);
        }