【问题标题】:export data from bigquery to cloud storage- php client library - there is one extra empty new line in the cloud storage file将数据从 bigquery 导出到云存储 - php 客户端库 - 云存储文件中有一个额外的空新行
【发布时间】:2017-04-24 18:31:02
【问题描述】:

我关注了这个示例

https://cloud.google.com/bigquery/docs/exporting-data

public function exportDailyRecordsToCloudStorage($date, $tableId)
{
    $validTableIds = ['table1', 'table2'];

    if (!in_array($tableId, $validTableIds))
    {
        die("Wrong TableId");
    }

    $date = date("Ymd", date(strtotime($date)));
    $datasetId = $date;
    $dataset = $this->bigQuery->dataset($datasetId);
    $table = $dataset->table($tableId);

    // load the storage object
    $storage = $this->storage;

    $bucketName = 'mybucket';
    $objectName = "daily_records/{$tableId}_" . $date;
    $destinationObject = $storage->bucket($bucketName)->object($objectName);

    // create the import job
    $format = 'NEWLINE_DELIMITED_JSON';

    $options = ['jobConfig' => ['destinationFormat' => $format]];
    $job = $table->export($destinationObject, $options);

    // 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('Data exported successfully' . PHP_EOL);
    }

我的table1有37670行,云存储文件有37671行。

而我的table2有388065,云存储文件有388066行。

两个云存储文件的最后一行都是空行。

这是一项 Google BigQuery 功能改进请求吗?还是我在上面的代码中做错了什么?

【问题讨论】:

  • 我来自 bigquery,我为此问题创建了一个勾选。不过以后你也可以使用BigQuery Issue Tracker来报告这类问题。

标签: google-bigquery google-cloud-storage


【解决方案1】:

你所描述的似乎是一个意想不到的结果。输出文件的行数一般应与源表的行数相同。

您的 PHP 代码看起来不错,应该不是问题的原因。

我正在尝试重现它,但无法重现。您能否仔细检查最后一个空行是否是由另一个工具(如文本编辑器或其他工具)以某种方式添加的?您如何计算结果输出的行数。

如果您已排除这种可能性并确定 BigQuery 导出功能确实添加了换行符,请考虑按照 xuejian 的建议使用 BigQuery 问题跟踪器打开一个错误,并附上您的工作 ID,以便我们进一步调查。

【讨论】:

    猜你喜欢
    • 2017-12-08
    • 2016-03-21
    • 2017-08-16
    • 2014-01-07
    • 2013-01-04
    • 2018-07-08
    • 1970-01-01
    • 2017-02-10
    • 2016-08-10
    相关资源
    最近更新 更多