最近我的BQ账单越来越高,因为我正在为我的客户运行大量查询。现在,我想知道如何为每个查询定价。
所以,要做到这一点,我需要两个中的一个:
这是我到目前为止所尝试的:
$bq = new Google_Service_Bigquery($client);
$job = new Google_Service_Bigquery_Job();
$config = new Google_Service_Bigquery_JobConfiguration();
// $config->setDryRun(false);
$config->setDryRun(true);
$queryConfig = new Google_Service_Bigquery_JobConfigurationQuery();
$config->setQuery($queryConfig);
$job->setConfiguration($config);
$queryConfig->setQuery($sql);
try {
$job = $bq->jobs->insert($project_id , $job);
$status = new Google_Service_Bigquery_JobStatus();
$status = $job->getStatus();
if ($status->count() != 0) {
$err_res = $status->getErrorResult();
die($err_res->getMessage());
}
} catch (Google_Service_Exception $e) {
// echo $e->getMessage();
exit;
}
$jr = $job->getJobReference();
$jobId = $jr['jobId'];
if ($status)
$state = $status['state'];
$res = $bq->jobs->getQueryResults($project_id, $jobId, array('timeoutMs' => 100000));
if (!$res->jobComplete) {
exit;
}
$rows = $res->getRows();
$r = new Google_Service_Bigquery_TableRow();
$a = array();
foreach ($rows as $r) {
$r = $r->getF();
$temp = array();
foreach ($r as $v) {
$temp[] = $v->v;
}
$a[] = $temp;
}
return $a;
但是,输出是:
- Uncaught Google_Exception: (getQueryResults) missing required param:
'jobId' in
/vendor/google/apiclient/src/Google/Service/Resource.php:165
由于某种原因,当干运行是真的,它不会成为一个jobid。 我做错了什么?