首页 文章

Google Big Query未捕获的异常'Google \ Cloud \ Core \ Exception \ ServiceException

提问于
浏览
0

我正在尝试实施Google Big Query . 我不得不使用composer来安装谷歌库,因为它不适用于存储客户端和大查询客户端 . 我的代码从 Cloud 存储读取文件并将数据插入Big查询表 . 我收到了以下错误和警告

PHP致命错误:此curl实现不支持带有消息'Option 20056'的未捕获异常'Google \ Cloud \ Core \ Exception \ ServiceException' . 在/base/data/home/apps/s~xxx/1.402961109127965627/vendor/google/cloud/src/Core/RequestWrapper.php:241堆栈跟踪:0 /base/data/home/apps/s~xxx/1.402961109127965627/ vendor / google / cloud / src / Core / RequestWrapper.php(150):Google \ Cloud \ Core \ RequestWrapper-> convertToGoogleException(Object(google \ appengine \ runtime \ CurlLiteOptionNotSupportedException))1 / base / data / home / apps / s ~xxx / 1.402961109127965627 / vendor / google / cloud / src / Core / RestTrait.php(96):Google \ Cloud \ Core \ RequestWrapper-> send(对象(GuzzleHttp \ Psr7 \ Request),数组)2 / base / data / home / apps / s~xxx / 1.402961109127965627 / vendor / google / cloud / src / BigQuery / Connection / Rest.php(220):Google \ Cloud \ BigQuery \ Connection \ Rest-> send('jobs','insert',数组)3 /base/data/home/apps/s~xxx/1.402961109127965627/vendor/google/cloud/src/BigQuery/Table.php(344):Google \ Cloud in / base / data / home / apps / s~第241行上的xxx / 1.402961109127965627 / vendor / google / cloud / src / Core / RequestWrapper.php PHP警告:出于安全原因,已禁用php_sapi_name() . 可以通过将其添加到/base/data/home/apps/s~datascrub-152522/1.402961109127965627/vendor/guzzlehttp/guzzle/src/Client中的应用程序php.ini中的google_app_engine.enable_functions ini变量来重新启用它 . php在173行

<?php
session_start();

# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';

# Imports the Google Cloud client library
use Google\Cloud\BigQuery\BigQueryClient;

use Google\Cloud\Storage\StorageClient;
use Google\Cloud\Core\ExponentialBackoff;

$projectId="xxx-1111";
$datasetId="datasetid";
$tableId="test";
$bucketName="gs://my-bucket";

$objectName="Cloud_SQL_Export.csv";
echo "\n".$projectId."==".$datasetId."==".$tableId."==".$bucketName."==".$objectName."\n";

import_from_storage($projectId, $datasetId, $tableId, $bucketName, $objectName);


function import_from_storage($projectId, $datasetId, $tableId, $bucketName, $objectName)
{

    echo "inside function";

    // determine the import options from the object name
    $options = [];
    /*if ('.backup_info' === substr($objectName, -12)) {
        $options['jobConfig'] = ['sourceFormat' => 'DATASTORE_BACKUP'];
    } elseif ('.json' === substr($objectName, -5)) {
        $options['jobConfig'] = ['sourceFormat' => 'NEWLINE_DELIMITED_JSON'];
    }*/
    $options['jobConfig'] = [ 'sourceFormat' => 'CSV', 'skipLeadingRows' => 1 ];
    print_r($options);
    echo "gfgfhg".$projectId;
    // instantiate the bigquery table service
    $bigQuery = new BigQueryClient([
            'projectId' => $projectId,
    ]);


    $dataset = $bigQuery->dataset($datasetId);


    $table = $dataset->table($tableId);
    // load the storage object
    $storage = new StorageClient([
            'projectId' => $projectId,
    ]);

    $object = $storage->bucket($bucketName)->object($objectName);


    // create the import job
    $job = $table->loadFromStorage($object, $options);
    echo "job set";
    // poll the job until it is complete
    $backoff = new ExponentialBackoff(10);
    $backoff->execute(function () use ($job) {
        echo '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'];
            echo 'Error running job: ' . PHP_EOL." ". $error;
        } else {
            echo 'Data imported successfully' . PHP_EOL;
        }
}

1 回答

  • 1

    通过在php.ini文件中添加extension =“php_curl.dll”解决了问题

相关问题