我有点困惑,因为我很难找到如何做到这一点的详细文档示例
我想在BigQuery中使用API查询以前的select查询的临时表中的数据
function run_query($query, $useLegacySql, &$result)
{
$builder = new ServiceBuilder([
'projectId' => 'PROJECTID',
]);
$job = new Google_Job();
$bigQuery = $builder->bigQuery();
$queryResults = $bigQuery->runQuery(
$query,
['useLegacySql' => $useLegacySql]);
if ($queryResults->isComplete())
{
$i = 0;
$rows = $queryResults->rows();
foreach ($rows as $row)
{
$i++;
$result[$i] = $row;
}
}
else
{
throw new Exception('The query failed to complete');
}
}
所以我的问题是,如果我运行这个函数来执行我的选择查询,例如"select username FROM user_activities",我怎么能从这个选择查询中得到临时表,并从这个临时表中执行下一个查询?
我知道BigQuery上有Jobs API,但我仍然困惑如何实现它?
谢谢
您需要替换这部分代码:
$queryResults = $bigQuery->runQuery(
$query,
['useLegacySql' => $useLegacySql]);
:
$job = $bigQuery->runQueryAsJob($query);
$isComplete = false;
$queryResults = $job->queryResults();
while (!$isComplete) {
sleep(1); // let's wait for a moment...
$queryResults->reload(); // trigger a network request
$isComplete = $queryResults->isComplete(); // check the query's status
}
! !您还需要现在轮询,直到作业完成,文档链接包含在底部,然后您可以使用:
$info=$job->info();
print_r($info);
,这会返回一堆关于您的工作的信息,例如destinationTable
Array
(
[kind] => bigquery#job
[etag] => "<edited>"
[id] => <edited>
[selfLink] => https://www.googleapis.com/bigquery/v2/projects/<edited>
[jobReference] => Array
(
[projectId] => <edited>
[jobId] => <edited>
)
[configuration] => Array
(
[query] => Array
(
[query] => SELECT repository_url,
repository_has_downloads
FROM [publicdata:samples.github_timeline]
LIMIT 10
[destinationTable] => Array
(
[projectId] => <edited>
[datasetId] => <edited>
[tableId] => anon734f2eebd13d01c49c65dce7359aeab1df285473
)
[createDisposition] => CREATE_IF_NEEDED
[writeDisposition] => WRITE_TRUNCATE
)
)
[status] => Array
(
[state] => RUNNING
)
[statistics] => Array
(
[creationTime] => 1479487171996
[startTime] => 1479487172576
)
[user_email] => <edited>
)
查看更多文档