Я использую клиент Python для создания таблиц с помощью SQL, как описано в документации (https://cloud.google.com/bigquery/docs/tables) примерно так:
# from google.cloud import bigquery
# client = bigquery.Client()
# dataset_id = 'your_dataset_id'
job_config = bigquery.QueryJobConfig()
# Set the destination table
table_ref = client.dataset(dataset_id).table('your_table_id')
job_config.destination = table_ref
sql = """
SELECT corpus
FROM `bigquery-public-data.samples.shakespeare`
GROUP BY corpus;
"""
# Start the query, passing in the extra configuration.
query_job = client.query(
sql,
# Location must match that of the dataset(s) referenced in the query
# and of the destination table.
location='US',
job_config=job_config) # API request - starts the query
query_job.result() # Waits for the query to finish
print('Query results loaded to table {}'.format(table_ref.path))
Это хорошо работает, за исключением того, что клиентская функция для созданияДля таблицы с помощью SQL-запроса используется объект job_config, а job_config получает table_ref, а не объект таблицы.
Я нашел этот документ для создания таблиц с описанием здесь: https://google -cloud-python.readthedocs.io / en / stable / bigquery / creation.html , но это для таблиц, НЕ созданных из запросов.
Есть идеи о том, как создать таблицу из запроса, указав описание для этой таблицы?