BIQ QUERY /通过php覆盖表

时间:2017-10-11 08:28:09

标签: google-bigquery

我正在寻找一种通过客户端库php覆盖BIG Query中现有表的方法。

在WEB UI中,我可以使用“Destination Table”和“ Write Preference“选项可以在php中做同样的事情吗?

1 个答案:

答案 0 :(得分:1)

composer.json

{
    "require": {
        "google/cloud": "^0.13.0",
        "google/apiclient": "^2.0"
    }
}

我有这段代码来覆盖表

        $builder = $this->getServiceBuilder();
        $bigQuery = $builder->bigQuery();
// Get an instance of a previously created table.
        $dataset = $bigQuery->dataset('wr_temp');
        $table = $dataset->table('shop_api_order_id');

// Begin a job to import data from a CSV file into the table.
        if (!is_file($data['params']['filename'])) {
            $this->e('File ' . $data['params']['filename'] . ' cannot be located');
            return false;
        }
        $job = $table->load(
                fopen($data['params']['filename'], 'r'), array(
            'jobConfig' => array(
                "writeDisposition" => 'WRITE_TRUNCATE',
                "schema" => array(
                    "fields" => array(array(
                            "name" => 'order_id',
                            "type" => 'INTEGER',
                            "mode" => 'NULLABLE',
                        )
                    )
                )
            )
                )
        );

        $isComplete = $job->isComplete();

        while (!$isComplete) {
            sleep(1); // let's wait for a moment...
            $job->reload();
            $isComplete = $job->isComplete();
        }