【发布时间】:2018-01-27 13:23:15
【问题描述】:
我正在访问来自 Google BigQuery 的数据,数据为 500MB,我需要将其转换为需求的一部分。我正在设置Allow Large Results,设置destination table等。
我已经在 Google 的新云库中编写了一个 java 作业,因为现在推荐使用它 - com.google.cloud:google-cloud-bigquery:0.21.1-beta(我也尝试了 0.20 测试版,但没有任何成果)
我在对这些数据进行分页时遇到问题,该库在获取结果页面方面不一致。这是我的代码sn-p,
代码片段
System.out.println("Accessing Handle of Response");
QueryResponse response = bigquery.getQueryResults(jobId, QueryResultsOption.pageSize(10000));
System.out.println("Got Handle of Response");
System.out.println("Accessing results");
QueryResult result = response.getResult();
System.out.println("Got handle of Result. Total Rows: "+result.getTotalRows());
System.out.println("Reading the results");
int pageIndex = 0;
int rowId = 0;
while (result != null) {
System.out.println("Reading Page: "+ pageIndex);
if(result.hasNextPage())
{
System.out.println("There is Next Page");
}
else
{
System.out.println("No Next Page");
}
for (List<FieldValue> row : result.iterateAll()) {
System.out.println("Row: " + rowId);
rowId++;
}
System.out.println("Getting Next Page: ");
pageIndex++;
result = result.getNextPage();
}
输出打印语句
Accessing Handle of Response
Got Handle of Response
Accessing results
Got handle of Result. Total Rows: 9617008
Reading the results
Reading Page: 0
There is Next Page
Row: 0
Row: 1
Row: 2
Row: 3
:
:
Row: 9999
Row: 10000
Row: 10001
:
:
Row: 19999
:
:
请注意,它永远不会点击/打印 - “获取下一页:”。
我的期望是一次获得 10000 行的数据块。请注意,如果我在返回 10-15K 行的查询上运行相同的代码并将 pageSize 设置为 100 条记录,我会在每 100 行之后得到“获取下一页:”。这是这个 beta 库的一个已知问题吗?
【问题讨论】:
标签: java pagination google-bigquery