本文介绍了可以创建BigQuery Table / Schema而不填充数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以创建一个Table模式,而无需先用数据填充它?最好使用Google的python客户端。 Google的文档似乎没有提供明确的或不是答案。他们建议使用查询 ,但这既非直观,再次,没有高度记录:

解决方案

在python中,您可以在表API API端点上运行插入作业,表中记载了您需要提供

  project_id =<我的项目> 
dataset_id =<我的数据集>
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,$ b $'schema': schema_ref}
table = bigquery.tables()。insert(
body = table,** dataset_ref).execute(http)

** dataset_ref是将内容复制到命名参数的一种python技巧。

浏览其他问题。


Is it possible to create a Table schema without first populating it with data? Preferably using Google's python client. Google's documentation does not seem to provide a clear yes or no answer. They suggest creating a table with a query, but this is both non-intuitive and again, not highly documented:

解决方案

In python you can run an insert job on the tables API endpoint and that will create an empty table as it's documented here you need to supply a TableResource

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 is a python trick to copy the contents to named arguments

Browse other python + bigquery questions.

这篇关于可以创建BigQuery Table / Schema而不填充数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 20:38