why the following Bigquery insertion is failing?

烈酒焚心 提交于 2019-12-11 14:26:01

问题


Hello I am trying to insert one row into a table, I succesfully created the table as follows:

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)

However when I push the row I got 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)

So I don't have idea what is wrong, I really would like to appreciate support to overcome this task This is the API that I am testing:

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

This is my complete code:

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)

Output:

Creation Result  True
Insertion Result  False

After feedback I tried:

>>> 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

and also:

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

However I only got false


回答1:


Your row field names don't match your schema field names. Try this instead:

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


来源:https://stackoverflow.com/questions/55067816/why-the-following-bigquery-insertion-is-failing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!