from google.cloud import bigquery
client = bigquery.Client()
dataset_ref = client.dataset('bigquery_error')
dataset = bigquery.Dataset(dataset_ref)
dataset.location = 'US'
dataset = client.create_dataset(dataset)
schema = [
bigquery.SchemaField('full_name', 'STRING'),
bigquery.SchemaField('age', 'INTEGER'),
bigquery.SchemaField('other', 'INTEGER'),
]
dataset_ref = client.dataset('bigquery_error')
dataset = bigquery.Dataset(dataset_ref)
table_ref = dataset_ref.table('user_table')
table = bigquery.Table(table_ref, schema=schema)
table = client.create_table(table) # API request
rows = [
('111', 9, 9),
(123, 123, 123),
]
# upload postgres data
table_ref = client.dataset('bigquery_error').table('user_table')
table = client.get_table(table_ref)
errors = client.insert_rows(table, rows)
print(errors)
assert errors == []
Это не запишет в таблицу, но не вызовет ошибок. Я запрашиваю базу данных сразу после этого в пользовательском интерфейсе, чтобы проверить, успешно ли выполнена запись, и она показывает 0 строк. Не должно ли быть ошибки, если запись не завершается успешно?
ПРИМЕЧАНИЕ: прочитав проблему git, инженер заявляет:
Yeah, this is a known backend issue. Basically, it can take 2 minutes for the streaming buffer's cache of where tables are located to update, so the writes after a delete and recreate can end up going to the deleted table's files in that 2 minute window.