【问题标题】:Exception when trying to connect to AWS Athena using JAVA API尝试使用 JAVA API 连接到 AWS Athena 时出现异常
【发布时间】:2018-03-14 09:05:07
【问题描述】:

我正在尝试使用 Java API 在 AWS Athena 中执行查询:

public class AthenaClientFactory
{     
    String accessKey = "access";
    String secretKey = "secret";
    BasicAWSCredentials awsCredentials = new 
    BasicAWSCredentials(accessKey, secretKey);

    private final AmazonAthenaClientBuilder builder = AmazonAthenaClientBuilder.standard()
            .withRegion(Regions.US_WEST_1)
            .withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
            .withClientConfiguration(new ClientConfiguration().withClientExecutionTimeout(10));

    public AmazonAthena createClient()
    {
        return builder.build();
    }
}


private static String submitAthenaQuery(AmazonAthena client) {
        QueryExecutionContext queryExecutionContext = new QueryExecutionContext().withDatabase("my_db");

        ResultConfiguration resultConfiguration = new ResultConfiguration().withOutputLocation("my_bucket");

        StartQueryExecutionRequest startQueryExecutionRequest = new StartQueryExecutionRequest()
                                                                    .withQueryString("select * from my_db limit 3;")
                                                                    .withQueryExecutionContext(queryExecutionContext)
                                                                    .withResultConfiguration(resultConfiguration);

        StartQueryExecutionResult startQueryExecutionResult = client.startQueryExecution(startQueryExecutionRequest);
        return startQueryExecutionResult.getQueryExecutionId();
}   

public void run() throws InterruptedException {
        AthenaClientFactory factory = new AthenaClientFactory();
        AmazonAthena client = factory.createClient(); 

        String queryExecutionId = submitAthenaQuery(client);
}

但是我从 startQueryExecutionResult 中得到一个异常。 例外是:

客户端执行在指定的超时之前没有完成 配置。

有没有人遇到过类似的情况?

【问题讨论】:

  • 我在运行示例时收到Exception in thread "main" java.lang.NoClassDefFoundError

标签: amazon-web-services amazon-athena


【解决方案1】:

问题出在withClientExecutionTimeout(10)

将此数字增加到 5000 解决了问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-23
    相关资源
    最近更新 更多