2017-07-04 50 views
0

我使用php庫設置來自bigquery的查詢。但沒有查詢本身的限制,我得到這個迴應「查詢尚未完成」,其大約10k或更多,但我的頁面應該限制50。如何在bigquery上設置分頁,我跳過,限制。大查詢限制和跳過分頁結果

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

回答

1

您可以詳細說明您在做「跳過,限制」的意思嗎?

看的BigQuery的PHP庫的源代碼,推薦使用是等待查詢試圖訪問的行之前完成: https://github.com/GoogleCloudPlatform/google-cloud-php/blob/master/src/BigQuery/QueryResults.php

用例:

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

如果您結果集是〜10,000(不是很大),您可能會發現跳過分頁並簡單地一次檢索結果中的所有行更容易。

+0

例如在mysql查詢中,從表20,10中選擇*,意思是跳過20,限制爲2。 – Boy