简体   繁体   English

为什么即使我设置了maxresults,我仍然使用Google BigQuery的PHP库获得所有行?

[英]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.

相关问题 为什么我在使用 google-ads-php getCampaigns 示例库时没有获得所有广告系列的列表? - Why am I not getting a list of all campaigns when using the google-ads-php getCampaigns example library? 为什么在没有列出 foreach 中的所有行时会得到未定义的偏移量? - Why do I get undefined offset when not listing all the rows in foreach? 为什么在使用“ Amazon ECS PHP库”时出现空白页? - Why do I get a blank page when using the 'Amazon ECS PHP Library'? 当maxResults设置为100时,Gmail List API会返回所有邮件 - Gmail List API returning all messages when maxResults set to 100 当我将所有图像都设置为col-6时,为什么我的图像彼此位于较低的位置? - Why do my images get positioned below each other when I set all of them to col-6? 为什么在PHP中执行if代码时会得到一个值 - Why is that when I do an if code in PHP i get a value 如何使用 PHP bigquery 客户端库对 bigquery 数据进行分页? - How do I paginate the bigquery data using PHP bigquery client library? 为什么我使用 PHP 查询时出现错误 - Why do I get an error when I query using PHP 为什么即使我设置content-type =“ image / jpeg”,我的图像图标也会损坏? - Why do i get broken image icon even if i set content-type=“image/jpeg”? 什么时候/我应该在PHP中使用__construct(),__ get(),__ set()和__call()? - When do/should I use __construct(), __get(), __set(), and __call() in PHP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM