简体   繁体   中英

big query limit and skip results for pagination

Im setting up queries from bigquery using the php library. but with out the limit on the query itself I get this response "The query has not completed yet.", its around 10k or more, but my pages should limit by 50 anyways. how to setup pagination on bigquery, that I do skip,limit.

select * from table skip,limit

$bigQuery = new BigQueryClient([
    'projectId' => 'xxxxx',
]);
$datasetId = 'dbxxxx';
$dataset = $bigQuery->dataset($datasetId);
$options = array(
    'useLegacySql' => true,
    'maxResults' => 50,
    'startIndex' => 1
    );

$query = "SELECT id FROM [ideas] WHERE date >= '".$datefrom."' AND date <= '".$dateto."' ORDER BY date DESC";
$runquery = $bigQuery->runQuery($query,$options);

Can you please elaborate on what you mean by doing "skip,limit"?

Looking at the source code for the BigQuery PHP library, the recommended use is to wait for the query to finish before attempting to access rows: https://github.com/GoogleCloudPlatform/google-cloud-php/blob/master/src/BigQuery/QueryResults.php

Usage example:

$isComplete = $queryResults->isComplete();
if ($isComplete) {
  $rows = $queryResults->rows(); 
  foreach ($rows as $row) {
      echo $row['name'] . PHP_EOL;
  }
}

If your result set is ~10,000 (not very large), you may find it easier to skip pagination and simply retrieve all rows in the result at once.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM