我正在尝试使用NEWLINE_DELIMITED_JSON作为目标格式将Big Query表导出到云存储中,但我一直收到以下错误: 运行作业时出错:无法对嵌套架构执行操作。
我知道如果您选择json格式,Big Query允许导出嵌套表格(正如documentation和question上所述),所以我不明白如何来吧,我收到了这个错误...... 我正在使用PHP SDK,这是我一直在使用的代码:
extract_table($projectId, $datasetId, $tableId, $bucketName, $objectName);
function extract_table($projectId, $datasetId, $tableId, $bucketName, $objectName, $format = 'NEWLINE_DELIMITED_JSON'){
$bigQuery = new BigQueryClient(['projectId' => $projectId,]);
$dataset = $bigQuery->dataset($datasetId);
$table = $dataset->table($tableId);
// load the storage object
$storage = new StorageClient([
'projectId' => $projectId,
]);
$destinationObject = $storage->bucket($bucketName)->object($objectName);
// create the extract job
$options = ['destinationFormat' => $format];
$extractConfig = $table->extract($destinationObject, $options);
$job = $table->runJob($extractConfig);
// poll the job until it is complete
$backoff = new ExponentialBackoff(10);
try {
$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);
}
});
} catch (Exception $e) {
}
// 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('Data extracted successfully' . PHP_EOL);
}
}
答案 0 :(得分:0)
您的问题是您使用了错误的options
字段配置。在PHP documentation on the Table.extract
method之后,您会看到options
方法中的extract
字段必须是configuration
对象,例如BigQuery documentation中显示的对象。 / p>
您将options
对象定义为:
$options = ['destinationFormat' => $format];
相反,您应该使用以下格式:
$options = ['configuration' => ['extract' => ['destinationFormat' => $format]]];
这是因为destinationFormat
字段嵌套在configuration
和extract
下。