是否可以在不先用数据填充的情况下创建表模式?最好使用 Google 的 python 客户端。谷歌的文档似乎没有提供明确的是或否的答案。他们建议创建一个表 https://cloud.google.com/bigquery/docs/tables#creatingatable使用查询,但这既不直观,又没有详细记录:
在 python 中,您可以在表 API 端点上运行插入作业,这将创建一个空表,如记录的那样here https://cloud.google.com/bigquery/docs/reference/v2/tables/insert你需要提供一个表资源 https://cloud.google.com/bigquery/docs/reference/v2/tables#resource
project_id = <my project>
dataset_id = <my dataset>
table_id = 'table_001'
dataset_ref = {'datasetId': dataset_id,
'projectId': project_id}
table_ref = {'tableId': table_id,
'datasetId': dataset_id,
'projectId': project_id}
schema_ref = {<schema comes here>}
table = {'tableReference': table_ref,
'schema': schema_ref}
table = bigquery.tables().insert(
body=table, **dataset_ref).execute(http)
**dataset_ref 是一个将内容复制到命名参数的 Python 技巧
浏览其他蟒蛇+大查询 https://stackoverflow.com/questions/tagged/google-bigquery+python问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)