我试图通过从Google读取一个文件来创建一个BigQuery外部表--它适用于内联方案,但使用autodetect标志失败。
引用的文档:
https://cloud.google.com/bigquery/external-data-drive
模式文件:
$ bq mkdef --autodetect --source_format=CSV "https://drive.google.com/open?id=<file-id>" > schema.jsonschema.json:
{
"autodetect": true,
"csvOptions": {
"encoding": "UTF-8",
"quote": "\""
},
"sourceFormat": "CSV",
"sourceUris": [
"https://drive.google.com/open?id=<file-id>"
]
}外部表:
$ bq mk --external_table_definition=schema.json mydataset.mytable
BigQuery error in mk operation: Access Denied: BigQuery BigQuery: No OAuth token with Google Drive scope was found.它与内联模式一起工作:
$ bq mk --external_table_definition=col1:INTEGER,col2:STRING@CSV=https://drive.google.com/open?id=<file-id> mydataset.mytable
Table 'myproject:mydataset.mytable' successfully created.注意:我已经通过使用
gcloud auth login --enable-gdrive-access启用了Google访问
发布于 2020-09-08 12:45:48
显然,这里的罪魁祸首是"autodetect": true 参数,它在从Google中的源数据创建Bigquery 外部表时在表定义文件--external_table_definition中指定。
实际上,bq命令行工具是一个与Biqquery交互的Python,这意味着我们触发tables.insert API 方法来创建一个永久的外部表,在表格 json请求体中提供适当的ExternalDataConfiguration。
您可以在整个API资源管理器使用来自ExternalDataConfiguration的表定义参数的过程中对Bigquery执行相关的API调用
curl --request POST \
'https://bigquery.googleapis.com/bigquery/v2/projects/<projectid>/datasets/<datasetid>/tables?key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{"tableReference":{"datasetId":"datasetId","projectId":"projectId","tableId":"tableId"},"externalDataConfiguration":{"autodetect":true,"csvOptions":{"encoding":"UTF-8","quote":"\""},"sourceFormat":"CSV","sourceUris":["https://drive.google.com/open?id=<file-id>"]}}' \
--compressed我在响应消息中也收到了同样的错误:
"error": {
"code": 403,
"message": "Access Denied: BigQuery BigQuery: No OAuth token with Google Drive scope was found.",
"errors": [
{
"message": "Access Denied: BigQuery BigQuery: No OAuth token with Google Drive scope was found.",
"domain": "global",
"reason": "accessDenied"
}
],
"status": "PERMISSION_DENIED"
}现在,您可以提供模式内联(在命令行上),也可以提供一个包含模式定义的JSON文件来工作。
为了让开发人员更清楚地看到这个问题的证据,我鼓励您通过Public In 跟踪器提交bug报告,这样我们就可以跟踪发生的任何更新,或者尝试联系Google支持。
https://stackoverflow.com/questions/63788255
复制相似问题