简体   繁体   English

使用 gcloud python 将空数据上传到 Bigquery

[英]Uploading empty data to Bigquery using gcloud python

I try to upload a few rows of data using the gcloud python library and don't succeed.我尝试使用gcloud python 库上传几行数据,但没有成功。 Here is the sample code taken from the latest documentation这是取自最新文档的示例代码

client = bigquery.Client()
dataset = client.dataset('test')
table = dataset.table("test_table")
rows = [("foo", "bar"), ("foo2", "bar2")]
result = table.insert_data(rows)

If I query the latest upload I get:如果我查询最新上传,我会得到:

[(None, None), (None, None)]

So I add empty fields.所以我添加了空字段。 In the documentation it says the uploaded rows should be "list of tuples", but that does not seem to work.在文档中,它说上传的行应该是“元组列表”,但这似乎不起作用。 My schema has two string fields.我的架构有两个字符串字段。 Unicode fields do not work either and I do not get any error result back either, which makes it difficult to debug. Unicode 字段也不起作用,我也没有得到任何错误结果,这使得调试变得困难。 Any hint what I do wrong?任何提示我做错了什么?

Explicitly declaring the schema in your table will help solve this problem.在表中显式声明架构将有助于解决此问题。 Ie, instead of using table = dataset.table('test_table') , you should use the following:即,而不是使用table = dataset.table('test_table') ,您应该使用以下内容:

left = SchemaField('left', 'STRING', 'REQUIRED') right = SchemaField('right', 'STRING', 'REQUIRED') table = dataset.table('test_table', schema=[left, right])

I had opened an issue on Github regarding this.我已经在 Github 上就此问题开了一个问题。 You can read more here if interested.如果有兴趣,您可以在此处阅读更多内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM