无法导出Big Query表

时间:2018-05-24 12:48:46

标签: php google-bigquery

我正在尝试使用NEWLINE_DELIMITED_JSON作为目标格式将Big Query表导出到云存储中,但我一直收到以下错误: 运行作业时出错:无法对嵌套架构执行操作

我知道如果您选择json格式,Big Query允许导出嵌套表格(正如documentationquestion上所述),所以我不明白如何来吧,我收到了这个错误...... 我正在使用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);
    }
}

1 个答案:

答案 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字段嵌套在configurationextract下。