我想从Query结果创建一个BigQuery表,或者用PHP中的模式创建表.
我正在处理这些句子,但他们正在制作一个空的noschema表:
$postBody = array( 'tableReference' =>
array(
'projectId' => $project_id,
'datasetId' => $dataset,
'tableId' => 'josetest'
)
);
$table = $service->tables->insert($project_id, $dataset, new Google_Service_Bigquery_Table($postBody));
我发现可能是python解决方案,但任何人都可以将其翻译为PHP?
它是:
"configuration": {
"query": {
"query": "select count(*) from foo.bar",
"destinationTable": {
"projectId": "my_project",
"datasetId": "my_dataset",
"tableId": "my_table"
},
"createdisposition": "CREATE_IF_NEEDED",
"writedisposition": "WRITE_APPEND",
}
}
解决方法:
>最简单的是使用Google APIs Client Library for PHP
>请参阅this post如何实例化Google_Client对象并进行身份验证
>我们自己的代码中的几个类的一个部分.
.
/**
* @param Google_Client $client
* @param string $project_id
* @param string $dataset_id
* @throws Google_Service_Exception
* @return Google_Service_Bigquery_Table
*/
public function BQ_Tables_Insert($client, $project_id, $dataset_id) {
$bq = new Google_Service_Bigquery($client);
$table_reference = new Google_Service_Bigquery_TableReference();
$table_reference->setProjectId($project_id);
$table_reference->setDatasetId($dataset_id);
$table_reference->setTableId(static::tableId());
$schema = new Google_Service_Bigquery_TableSchema();
$schema->setFields(static::fields());
$table = new Google_Service_Bigquery_Table();
$table->setTableReference($table_reference);
$table->setSchema($schema);
try {
return $bq->tables->insert($project_id, $dataset_id, $table);
} catch (Google_Service_Exception $e) {
$this->setErrors($e->getErrors())->setErrorMessage($e->getMessage());
throw $e;
}
}
其中static :: tableId()是表的名称,static :: fields()是表的数组表示形式
/**
* @see https://developers.google.com/bigquery/docs/reference/v2/tables/insert
*/
public static function fields() {
return array(
array('name' => 'user_id', 'type' => 'integer', 'mode' => 'required'),
array('name' => 'order_id', 'type' => 'integer', 'mode' => 'required'),
array('name' => 'status', 'type' => 'integer', 'mode' => 'nullable'),
array('name' => 'timestamp', 'type' => 'timestamp', 'mode' => 'nullable')
);
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。