php - Not being able to export a Big Query table
问题描述
I am trying to export a Big Query table into cloud storage using NEWLINE_DELIMITED_JSON as destination format but I keep on receiving the following error: Error running job: Operation cannot be performed on a nested schema.
I know Big Query allows to export nested tables if you choose the json format (as it is stated both on the documentation and on this question), so I don't understand how come I am getting this error... I am using the PHP SDK and this is the code I've been using:
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);
}
}
解决方案
您的问题是您使用了错误的options
字段配置。按照有关该方法的PHP 文档Table.extract
,您将看到该方法中的options
字段extract
必须是一个configuration
对象,例如BigQuery 文档中提供的对象。
您将options
对象定义为:
$options = ['destinationFormat' => $format];
相反,您应该使用以下格式:
$options = ['configuration' => ['extract' => ['destinationFormat' => $format]]];
这是因为该destinationFormat
字段嵌套在configuration
and下extract
。
推荐阅读
- azure - Docker 上的 Azure CosmosDB 模拟器不生成证书
- javascript - ReactJS 类组件使用 contenteditable 元素渲染 array.map
- javascript - 注册表单上的 asp.net + asp:button、HTML 和 Javascript 存在问题
- javascript - Symfony 3/4:通过 AJAX 从数据库中删除表行
- powershell - 使用 Where-Object 打开文件
- firebase - 在特定时间对谷歌通知的操作
- ios - 旧项目停止使用最新的模拟器更新进行构建
- python - Pandas:用于条目的优先级消除重复值
- jquery - 如何使用 jQuery 定位嵌套在另一个元素的兄弟标签中的元素
- tensorflow - tensorflow中处理多类多标签分类时如何计算准确率?