async static Task run(IAmazonAthena client, QueryExecutionContext qContext, ResultConfiguration resConf, string searchkey) { /* Execute a simple query on a table */ StartQueryExecutionRequest qReq = new StartQueryExecutionRequest() { QueryString = "SELECT * FROM book where bookid='" + searchkey + "'", QueryExecutionContext = qContext, ResultConfiguration = resConf }; try { /* Executes the query in an async manner */ StartQueryExecutionResponse qRes = await client.StartQueryExecutionAsync(qReq); /* Call internal method to parse the results and return a list of key/value dictionaries */ List <Dictionary <String, String> > items = await getQueryExecution(client, qRes.QueryExecutionId); foreach (var item in items) { foreach (KeyValuePair <String, String> pair in item) { Console.WriteLine("Col: {0}", pair.Key); Console.WriteLine("Val: {0}", pair.Value); } } } catch (InvalidRequestException e) { Console.WriteLine("Run Error: {0}", e.Message); } }
async static Task <string> run(IAmazonAthena client, QueryExecutionContext qContext, ResultConfiguration resConf) { /* Execute a simple query on a table */ StartQueryExecutionRequest qReq = new StartQueryExecutionRequest() { QueryString = "SELECT * FROM tbl_logger7;", QueryExecutionContext = qContext, ResultConfiguration = resConf }; try { /* Executes the query in an async manner */ StartQueryExecutionResponse qRes = await client.StartQueryExecutionAsync(qReq); /* Call internal method to parse the results and return a list of key/value dictionaries */ List <Dictionary <String, String> > items = await getQueryExecution(client, qRes.QueryExecutionId); string json = JsonConvert.SerializeObject(items); return(json); } catch (InvalidRequestException e) { return("{\"Error\":\"" + e.Message + "\"}"); } }
public async Task StartQueryExecutionAsync_WhenCalled_ShouldExecuteAndReturnQueryExecutionId() { var database = "test-db-name"; var queryString = "query-string"; var outputLocation = "output-location"; var queryExecutionId = Guid.NewGuid().ToString(); A.CallTo(() => _amazonAthena.StartQueryExecutionAsync( A <StartQueryExecutionRequest> .That.Matches( m => m.QueryString == queryString && m.QueryExecutionContext.Database == database && m.ResultConfiguration.OutputLocation == outputLocation), CancellationToken.None)) .Returns(Task.FromResult(new StartQueryExecutionResponse { HttpStatusCode = HttpStatusCode.OK, QueryExecutionId = queryExecutionId })); var result = await _athenaClientService.StartQueryExecutionAsync(database, queryString, outputLocation); result.Should().Be(queryExecutionId); }
async static Task <List <Dictionary <String, String> > > Run(IAmazonAthena client, QueryExecutionContext qContext, ResultConfiguration resConf, string datestring) { /* Execute a simple query on a table */ StartQueryExecutionRequest qReq = new StartQueryExecutionRequest() { QueryString = $@"SELECT * FROM emptable where emp_dob = '{datestring}'", QueryExecutionContext = qContext, ResultConfiguration = resConf }; List <Dictionary <String, String> > items = null; try { /* Executes the query in an async manner */ StartQueryExecutionResponse qRes = await client.StartQueryExecutionAsync(qReq); /* Call internal method to parse the results and return a list of key/value dictionaries */ items = await getQueryExecution(client, qRes.QueryExecutionId); if (items == null) { Dictionary <string, string> dic1 = new Dictionary <string, string>(); dic1.Add("error", "items from query execution is empty"); items.Add(dic1); } } catch (InvalidRequestException e) { Dictionary <string, string> dic1 = new Dictionary <string, string>(); dic1.Add("error", "exception at " + " (Run method) " + " : " + e.Message); if (items == null) { items = new List <Dictionary <string, string> >(); } items.Add(dic1); Console.WriteLine("Run Error: {0}", e.Message); } return(items); }
private Amazon.Athena.Model.StartQueryExecutionResponse CallAWSServiceOperation(IAmazonAthena client, Amazon.Athena.Model.StartQueryExecutionRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Athena", "StartQueryExecution"); try { #if DESKTOP return(client.StartQueryExecution(request)); #elif CORECLR return(client.StartQueryExecutionAsync(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; } }
async static Task <List <Dictionary <String, String> > > runQuery(IAmazonAthena client, QueryExecutionContext qContext, ResultConfiguration resConf, String dateToQuery) { /* Execute a simple query on a table */ StartQueryExecutionRequest qReq = new StartQueryExecutionRequest() { QueryString = $"SELECT * FROM employee where day(employee.emp_dob) = {dateToQuery}", QueryExecutionContext = qContext, ResultConfiguration = resConf }; try { StartQueryExecutionResponse qRes = await client.StartQueryExecutionAsync(qReq); /* Call internal method to parse the results and return a list of key/value dictionaries */ List <Dictionary <String, String> > items = await getQueryExecution(client, qRes.QueryExecutionId); return(items); } catch (InvalidRequestException e) { LambdaLogger.Log($"Run Error: {e.Message}"); return(new List <Dictionary <String, String> >()); } }
public async Task <List <CountryEnrichedData> > Run(IAmazonAthena client, QueryExecutionContext queryContext, ResultConfiguration resultConfig) { /* Execute a simple query on a table */ var queryRequest = new StartQueryExecutionRequest() { QueryString = AthenaConstants.ATHENA_COUNTRY_DATA_QUERY, QueryExecutionContext = queryContext, ResultConfiguration = resultConfig }; try { var ListOfCountryEnrichedData = new List <CountryEnrichedData>(); /* Executes the query in an async manner */ var queryResult = await client.StartQueryExecutionAsync(queryRequest); /* Call internal method to parse the results and return a list of key/value dictionaries */ List <Dictionary <String, String> > items = await GetQueryExecution(client, queryResult.QueryExecutionId); foreach (var item in items) { var countryUpdate = new CountryEnrichedData(); foreach (KeyValuePair <String, String> pair in item) { switch (pair.Key) { case "iso_code": if (pair.Value == "iso_code") { break; } else { countryUpdate.IsoCode = pair.Value; } break; case "population": if (pair.Value == "population") { break; } else { countryUpdate.Population = Convert.ToDouble(pair.Value); } break; case "population_density": if (pair.Value == "population_density") { break; } else { countryUpdate.PopulationDensity = Convert.ToDouble(pair.Value); } break; case "median_age": if (pair.Value == "median_age") { break; } else { countryUpdate.MedianAge = Convert.ToDouble(pair.Value); } break; case "aged_65_older": if (pair.Value == "aged_65_older") { break; } else { countryUpdate.Aged65Older = Convert.ToDouble(pair.Value); } break; case "aged_70_older": if (pair.Value == "aged_70_older") { break; } else { countryUpdate.Aged70Older = Convert.ToDouble(pair.Value); } break; case "gdp_per_capita": if (pair.Value == "gdp_per_capita") { break; } else { countryUpdate.GdpPerCapita = Convert.ToDouble(pair.Value); } break; case "diabetes_prevalence": if (pair.Value == "diabetes_prevalence") { break; } else { countryUpdate.DiabetesPrevalence = Convert.ToDouble(pair.Value); } break; case "handwashing_facilities": if (pair.Value == "handwashing_facilities") { break; } else { countryUpdate.HandwashingFacilities = Convert.ToDouble(pair.Value); } break; case "hospital_beds_per_thousand": if (pair.Value == "hospital_beds_per_thousand") { break; } else { countryUpdate.HospitalBedsPerThousand = Convert.ToDouble(pair.Value); } break; case "life_expectancy": if (pair.Value == "life_expectancy") { break; } else { countryUpdate.LifeExpectancy = Convert.ToDouble(pair.Value); } break; } } ListOfCountryEnrichedData.Add(countryUpdate); } return(ListOfCountryEnrichedData); } catch (InvalidRequestException e) { _logger.LogInformation("Run Error: {0}", e.Message); } return(new List <CountryEnrichedData>()); }