3

我在 Pentaho PDI 中为 Google BigQuery 使用 starschema JDBC 驱动程序:

http://code.google.com/p/starschema-bigquery-jdbc/

我通过 BigQuery Web 控制台的查询返回 129,993 行,但是当我通过 JDBC 驱动程序执行相同的查询时,它只返回 100,000 行。是否有某种我不知道的选项或限制?

4

2 回答 2

1

StarSchema 代码看起来只返回结果的第一页。

这里的代码应该更新以获得其余的结果。它应该看起来像:

public static GetQueryResultsResponse getQueryResults(Bigquery bigquery,
        String projectId, Job completedJob) throws IOException {        
    GetQueryResultsResponse queryResult = bigquery.jobs()
            .getQueryResults(projectId,
                    completedJob.getJobReference().getJobId()).execute();
    while(queryResult.getTotalRows() > queryResult.getRows().size()) {
        queryResult.getRows().addAll(
            bigquery.jobs()
                .getQueryResults(projectId,
                        completedJob.getJobReference().getJobId())
                .setStartIndex(queryResult.getRows().size())
                .execute()
                .getRows());            
    }
    return queryResult;
}
于 2013-01-28T21:57:52.530 回答
1

根据 Jordan 的回答修改了代码,解决方案如下:

    public static GetQueryResultsResponse getQueryResults(Bigquery bigquery,
        String projectId, Job completedJob) throws IOException {
    GetQueryResultsResponse queryResult = bigquery.jobs()
            .getQueryResults(projectId,
                    completedJob.getJobReference().getJobId()).execute();
    long totalRows = queryResult.getTotalRows().longValue();
    if(totalRows == 0){ 
//if we don't have results we'll get a nullPointerException on the queryResult.getRows().size()
        return queryResult;
    }
    while( totalRows  > (long)queryResult.getRows().size() ) {
        queryResult.getRows().addAll(
            bigquery.jobs()
                .getQueryResults(projectId,
                        completedJob.getJobReference().getJobId())
                .setStartIndex(BigInteger.valueOf((long)queryResult.getRows().size()) )
                .execute()
                .getRows());           
    }
    return queryResult;
}

这应该可以解决问题。也将新版本上传到google代码,命名为bqjdbc-1.3.1.jar

于 2013-01-30T08:57:00.030 回答