'Code snippet to download athena result set in a pdf format

We have a java application which connects with AWS Athena and executes the SQL on Athena side. There are some SQL queries whose result-set is very large. In such cases, we limit the output to 500 rows.

Now we want to allow the users to download the full result-set in pdf/csv format.

I have seen that Athena queries and their resultsets are stored in a s3 location.

Is there any way that we can leverage this functionality to download the resultset.

Also if there is any other API that we can use to download the result set.

The current code snippet:

public String submitAthenaQuery(AmazonAthena athenaClient, String query) { QueryExecutionContext context = new QueryExecutionContext().withDatabase(db);

    ResultConfiguration config = new ResultConfiguration()
            .withOutputLocation(outputBucket);

    StartQueryExecutionRequest executionRequest = new StartQueryExecutionRequest().withQueryString(query)
            .withQueryExecutionContext(context).withResultConfiguration(config);

    StartQueryExecutionResult executionResult = athenaClient
            .startQueryExecution(executionRequest);
    return executionResult.getQueryExecutionId();
}

and

GetQueryResultsRequest queryResult = new GetQueryResultsRequest()
                .withQueryExecutionId(queryExecutionId);
        GetQueryResultsResult getQueryResultsResult = athenaClient.getQueryResults(queryResult);
        List<ColumnInfo> columnInfoList = getQueryResultsResult.getResultSet().getResultSetMetadata().getColumnInfo();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source