public async Task <bool> ExecuteAsync(SqlSriptData[] scripts) { var requestJson = scripts != null?JsonConvert.SerializeObject(scripts) : ""; _logger.LogDebug($"Request: '{requestJson}'"); if (scripts == null) { return(true); } var queryExecutionIds = new List <string>(); foreach (var script in scripts) { _logger.LogDebug($"Executing script: '{JsonConvert.SerializeObject(script)}'"); var queryString = await _s3ClientService.ReadAllText(script.SqlScriptS3Location); var queryExecutionId = await _athenaClientService.StartQueryExecutionAsync(script.Database, queryString, script.CsvOutputLocation); queryExecutionIds.Add(queryExecutionId); _logger.LogDebug($"Executed script: '{JsonConvert.SerializeObject(script)}' with ExecutionId '{queryExecutionId}'."); } await _athenaClientService.BatchPoolQueryExecutionAsync(queryExecutionIds); _logger.LogDebug($"Completed QueryExecutionIds '{string.Join(", ", queryExecutionIds)}'."); return(await Task.FromResult(true)); }
public async Task ExecuteAsync_WhenExecuted_StartsQueryExecutionsSavedOnS3AndPoolsStatus() { var scriptDataA = CreateSqlSriptData("a"); var scriptDataB = CreateSqlSriptData("b"); var scripts = new SqlSriptData[] { scriptDataA, scriptDataB }; var scriptA = "SELECT ColumnA FROM TableA"; A.CallTo(() => _s3ClientService.ReadAllText(A <string> .That.Matches(m => m.Equals(scriptDataA.SqlScriptS3Location)))) .Returns(scriptA); A.CallTo(() => _athenaClientService.StartQueryExecutionAsync(A <string> .That.IsEqualTo(scriptDataA.Database), A <string> .That.IsEqualTo(scriptA), A <string> .That.IsEqualTo(scriptDataA.CsvOutputLocation))) .Returns("id-a"); var scriptB = "SELECT ColumnB FROM TableB"; A.CallTo(() => _s3ClientService.ReadAllText(A <string> .That.Matches(m => m.Equals(scriptDataB.SqlScriptS3Location)))) .Returns(scriptB); A.CallTo(() => _athenaClientService.StartQueryExecutionAsync(A <string> .That.IsEqualTo(scriptDataB.Database), A <string> .That.IsEqualTo(scriptB), A <string> .That.IsEqualTo(scriptDataB.CsvOutputLocation))) .Returns("id-b"); await _sqlSriptExecutorService.ExecuteAsync(scripts); A.CallTo(() => _athenaClientService.StartQueryExecutionAsync(A <string> .That.IsEqualTo(scriptDataA.Database), A <string> .That.IsEqualTo(scriptA), A <string> .That.IsEqualTo(scriptDataA.CsvOutputLocation))) .MustHaveHappenedOnceExactly(); A.CallTo(() => _athenaClientService.StartQueryExecutionAsync(A <string> .That.IsEqualTo(scriptDataB.Database), A <string> .That.IsEqualTo(scriptB), A <string> .That.IsEqualTo(scriptDataB.CsvOutputLocation))) .MustHaveHappenedOnceExactly(); A.CallTo(() => _athenaClientService.BatchPoolQueryExecutionAsync(A <List <string> > .That.IsSameSequenceAs("id-a", "id-b"), A <int> .That.IsEqualTo(5000))) .MustHaveHappenedOnceExactly(); }