Boy
Boy

Reputation: 612

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);

Upvotes: 0

Views: 593

Answers (1)

Omid Fatemieh
Omid Fatemieh

Reputation: 66

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.

Upvotes: 1

Related Questions