/// <summary> /// execute athena query and return sample data /// </summary> /// <param name="athenaApi"></param> /// <param name="sql"></param> /// <param name="lines"></param> /// <returns></returns> public static async Task <DataSampleWithSchema> GetSampleDataBySQL(this AWSAthenaAPI athenaApi, string sql) { var result = new DataSampleWithSchema() { FieldMappings = new List <FieldMapping>(), }; var sample = new DataSample() { Rows = new List <DataRow>() }; result.DataSample = sample; // var response = await athenaApi.ExecuteQuery(sql); var getResultRequest = await athenaApi.ExecuteQuery(sql); var response = await athenaApi.ReadOneResult(getResultRequest); var data = response.ReadData(); result.FieldMappings = response.ToFieldMapping(); foreach (var row in data) { var dataRow = new DataRow() { Items = row.Select(item => item.ToString()).ToList() }; sample.Rows.Add(dataRow); } return(result); }
public static async Task <DataSampleWithSchema> TryObtainSampleDataResult(this AWSAthenaAPI athenaApi, string executionId) { if (await athenaApi.IsExecutionCompleted(executionId)) { var result = new DataSampleWithSchema() { FieldMappings = new List <FieldMapping>(), }; var sample = new DataSample() { Rows = new List <DataRow>() }; result.DataSample = sample; var response = await athenaApi.ReadOneResult(new GetQueryResultsRequest() { QueryExecutionId = executionId }); var data = response.ReadData(); result.FieldMappings = response.ToFieldMapping(); foreach (var row in data) { var dataRow = new DataRow() { Items = row.Select(item => item.ToString()).ToList() }; sample.Rows.Add(dataRow); } return(result); } else { return(null); } }