6

有没有办法获得Athena query ID我提交的 Athena JDBC 驱动程序的查询?对查询状态的任何 API 调用(使用其查询 ID?)有什么方法可以通过 API 调用获取查询历史记录?

4

4 回答 4

3

我正在使用以下代码来检索查询 ID:

AthenaResultSet rs = (AthenaResultSet) statement.executeQuery(query);
Object queryId = ((AthenaStatementClient)rs.getClient()).getQueryExecutionId();
于 2017-05-08T14:13:52.603 回答
2

是的,可以注册查询ID,例如日志消息。这些消息将存储在您可以在连接 JDBC 驱动程序时指定的日志文件中。

log_path 属性

参考官方文档

于 2017-03-16T10:59:57.733 回答
1

只需添加我的 2 美分并完成答案。问题是获取 ID 和查询的状态。为了获得 ID,我使用了 was docs 中的示例ListQueryExecutionsExample.java。但是要获取查询的完整状态,您可以检索包含QueryExecutionStatus的QueryExecution对象。下面的示例检索更详细的信息:

import com.amazonaws.services.athena.AmazonAthena;
import com.amazonaws.services.athena.model.BatchGetQueryExecutionRequest;
import com.amazonaws.services.athena.model.BatchGetQueryExecutionResult;
import com.amazonaws.services.athena.model.ListQueryExecutionsRequest;
import com.amazonaws.services.athena.model.ListQueryExecutionsResult;
import com.amazonaws.services.athena.model.QueryExecution;
import java.util.List;
import java.util.function.Predicate;

public class ListQueryExecutionsExample {
    public static void main(String[] args) throws Exception {
        // Build an Athena client
        AthenaClientFactory factory = new AthenaClientFactory();
        AmazonAthena athenaClient = factory.createClient();

        // Build the request
        ListQueryExecutionsRequest listQueryExecutionsRequest = new ListQueryExecutionsRequest();

        // Get the list results.
        ListQueryExecutionsResult listQueryExecutionsResult =
            athenaClient.listQueryExecutions(listQueryExecutionsRequest);

        // Process the results.
        boolean hasMoreResults = true;
        while (hasMoreResults) {
            List<String> queryExecutionIds = listQueryExecutionsResult.getQueryExecutionIds();
            // System.out.println(queryExecutionIds);

            BatchGetQueryExecutionRequest batchGetQueryExecutionRequest =
                new BatchGetQueryExecutionRequest().withQueryExecutionIds(queryExecutionIds);
            BatchGetQueryExecutionResult batchGetQueryExecutionResult =
                athenaClient.batchGetQueryExecution(batchGetQueryExecutionRequest);
            // QueryExecution has all detail information about the queries.
            List<QueryExecution> queryExecutionList = batchGetQueryExecutionResult.getQueryExecutions();
            queryExecutionList.stream().forEach(System.out::println);

            //If nextToken is not null, then there are more results. Get the next page of results.
            if (listQueryExecutionsResult.getNextToken() != null) {
                listQueryExecutionsResult = athenaClient.listQueryExecutions(
                    listQueryExecutionsRequest.withNextToken(listQueryExecutionsResult.getNextToken()));
            } else {
                hasMoreResults = false;
            }
        }
    }
}
于 2022-02-04T16:42:49.217 回答
0

使用 JDBC 驱动程序 (SimbaAthenaJDBC_2.0.13),您可以这样做:

Statement stmt = conn.createStatement();
ResultSet result = stmt.executeQuery("SELECT * FROM table");
String queryId = stmt.unwrap(IStatementQueryInfoProvider.class).getQueryId();
于 2020-09-21T12:05:44.233 回答