为什么以下Bigquery插入失败?

时间:2019-03-08 17:05:09

标签: google-bigquery python-3.6

你好,我试图在表中插入一行,我成功创建了如下表:

schema = [{'name': 'foo', 'type': 'STRING', 'mode': 'nullable'},{'name': 'bar', 'type': 'FLOAT', 'mode': 'nullable'}]
created = client.create_table(dataset='api_data_set_course_33', table='insert_test_333', schema=schema)

print('Creation Result ',created)

但是,当我按下该行时,我得到了False,

rows =  [{'id': 'NzAzYmRiY', 'one': 'uno', 'two': 'dos'}]
inserted = client.push_rows('api_data_set_course_33','insert_test_333', rows, 'id')

print('Insertion Result ',inserted)

所以我不知道出什么问题了,我真的很感谢能够克服这一任务的支持 这是我正在测试的API:

https://github.com/tylertreat/BigQuery-Python

这是我完整的代码:

schema = [{'name': 'foo', 'type': 'STRING', 'mode': 'nullable'},{'name': 'bar', 'type': 'FLOAT', 'mode': 'nullable'}]
created = client.create_table(dataset='api_data_set_course_33', table='insert_test_333', schema=schema)

print('Creation Result ',created)

rows =  [{'id': 'NzAzYmRiY', 'one': 'uno', 'two': 'dos'}]
inserted = client.push_rows('api_data_set_course_33','insert_test_333', rows, 'id')

print('Insertion Result ',inserted)

输出:

Creation Result  True
Insertion Result  False

反馈后,我尝试:

>>> client = get_client(project_id, service_account=service_account,private_key_file=key, readonly=False)
>>> schema = [{'name': 'foo', 'type': 'STRING', 'mode': 'nullable'},{'name': 'bar', 'type': 'FLOAT', 'mode': 'nullable'}]
>>> rows =  [{'id': 'NzAzYmRiY', 'foo': 'uno', 'bar': 'dos'}]
>>> inserted = client.push_rows('api_data_set_course_33','insert_test_333', rows, 'id')
>>> print(inserted)
False

还有:

>>> rows =  [{'id': 'NzAzYmRiY', 'foo': 'uno', 'bar': 45}]
>>> inserted = client.push_rows('api_data_set_course_33','insert_test_333', rows, 'id')
>>> print(inserted)
False

但是我只有假的

1 个答案:

答案 0 :(得分:1)

您的行字段名称与您的架构字段名称不匹配。尝试以下方法:

rows =  [{'id': 'NzAzYmRiY', 'foo': 'uno', 'bar': 'dos'}]