我在运行下面的php脚本时遇到以下致命错误:
等待工作完成
**Fatal error: Uncaught Error: Call to undefined method
Google\Cloud\BigQuery\CopyJobConfiguration::*reload()*
in /opt/bitnami/apache2/htdocs/test.php:53 Stack trace: #0 [internal function]:
{closure}() #1 /opt/bitnami/apache2/htdocs/vendor/google/cloud/src/Core/ExponentialBackoff.php(74):
call_user_func_array(Object(Closure), Array) #2 /opt/bitnami/apache2/htdocs/test.php(58):
Google\Cloud\Core\ExponentialBackoff->execute(Object(Closure)) #3 /opt/bitnami/apache2/htdocs/test.php(36):
copy_table('aaaa', 'bbbb', 'cccc', 'dddd', 'eeee') #4 {main} thrown in /opt/bitnami/apache2/htdocs/test.php on line 54**
<?php
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Pragma: no-cache"); // HTTP/1.0
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
# Includes the autoloader for libraries installed with composer
require "vendor/autoload.php";
use Google\Cloud\BigQuery\BigQueryClient;
use Google\Cloud\ServiceBuilder;
use Google\Cloud\Core\ExponentialBackoff;
$client = new Google_Client();
putenv('GOOGLE_APPLICATION_CREDENTIALS='.dirname(__FILE__) . '/.ssh/xxx.json');
$client->useApplicationDefaultCredentials();
# Your Google Cloud Platform project stuff
$projectId = 'aaaa';
$datasetIdin = 'bbbb';
$datasetIdout = 'cccc';
$tableIdin = "dddd";
$tableIdout = "eeee";
$gcloud = new ServiceBuilder([
'projectId' => $projectId
]);
copy_table($projectId, $datasetIdin, $datasetIdout, $tableIdin, $tableIdout);
function copy_table($projectId, $datasetIdin, $datasetIdout, $tableIdin, $tableIdout)
{
$bigQuery = new BigQueryClient([
'projectId' => $projectId,
]);
$datasetin = $bigQuery->dataset($datasetIdin);
$datasetout = $bigQuery->dataset($datasetIdout);
$sourceTable = $datasetin->table($tableIdin);
$destinationTable = $datasetout->table($tableIdout);
$job = $sourceTable->copy($destinationTable);
// poll the job until it is complete
$backoff = new ExponentialBackoff(10);
$backoff->execute(function () use ($job) {
print('Waiting for job to complete' . PHP_EOL);
$job->reload();
if (!$job->isComplete()) {
throw new Exception('Job has not yet completed', 500);
}
});
// check if the job has errors
if (isset($job->info()['status']['errorResult'])) {
$error = $job->info()['status']['errorResult']['message'];
printf('Error running job: %s' . PHP_EOL, $error);
} else {
print('Table copied successfully' . PHP_EOL);
}
echo "table copied";
}
?>
看起来虽然没有加载适当的类?我使用的composer.json是:
{
"require": {
"google/cloud": "^0.47.0",
"google/apiclient": "^2.0"
}
}
关于我为什么会遇到此错误的任何想法?谢谢!
答案 0 :(得分:2)
你的方法有些不对劲。
$job = $sourceTable->copy($destinationTable);
这不会返回作业。
返回要传递给Google\Cloud\BigQuery\Table::runJob()
或Google\Cloud\BigQuery\Table::startJob()
的副本作业配置。
因此您还需要添加代码以将此conf传递给上述函数。