[英]Why do I get all rows with the PHP library for Google BigQuery, even when I set maxresults?
I am trying to paginate the results since its more than 1M rows. 由于它的行数超过100万,因此我试图对结果进行分页。 I am using the PHP version of BigQuery. 我正在使用BigQuery的PHP版本。 but even if I put 10 as maxresults
still gives me all the results. 但是即使我把maxresults
设为10,也仍然可以得到所有结果。 or am I doing it wrong. 还是我做错了。
function run_query_as_job($query, $maxResults = 10, $startIndex = 0)
{
$options = [
'maxResults' => $maxResults,
'startIndex' => $startIndex
];
$bigQuery = new BigQueryClient([
'projectId' => 'xxx',
'keyFilePath' => 'xxxx-21c721cefe2c.json'
]);
$job = $bigQuery->runQueryAsJob(
$query,
['jobConfig' => ['useLegacySql' => true]]);
$backoff = new ExponentialBackoff(10);
$backoff->execute(function () use ($job) {
print('Waiting for job to complete' . PHP_EOL);
$job->reload();
if (!$job->isComplete()) {
throw new Exception('Job has not yet completed', 500);
}
});
$queryResults = $job->queryResults($options);
print_r($options);
if ($queryResults->isComplete()) {
$i = 0;
$rows = $queryResults->rows($options);
foreach ($rows as $row) {
printf('--- Row %s ---' . "<br>", ++$i);
}
printf('Found %s row(s)' . "<br>", $i);
} else {
throw new Exception('The query failed to complete');
}
}
The QueryResults.rows() function returns a Google\\Cloud\\Core\\Iterator\\ItemIterator . QueryResults.rows()函数返回Google \\ Cloud \\ Core \\ Iterator \\ ItemIterator 。 This automatically gets the next page when you loop through it. 当您循环浏览下一页时,它将自动获取下一页。 Setting maxResults = 10
means that it only fetches 10 at a time, but it will still fetch all pages when you loop through. 设置maxResults = 10
表示一次只能获取10,但在循环浏览时仍将获取所有页面。
You can manually access just the first page with 您可以手动访问第一页
$rows -> $queryResults->rows($options);
$firstPage -> $rows->pageIterator->current();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.