Вы можете использовать Python SDK для BigQuery .Вот пример, который вы можете использовать:
from google.cloud import bigquery
#Initiate the client
client = bigquery.Client()
#Load the dataset in which you are going to store the table
dataset_ref = client.dataset('{dataset}')
#Create the Query which is going to get the values
QUERY = (
'SELECT DISTINCT {column} FROM `{project-ID}.{dataset}.{table}`'
)
# API request
query_job = client.query(QUERY)
# Wait for the Query to finish and store the query.
rows = query_job.result()
# Define the schema of the new table
schema = [
bigquery.SchemaField('ExampleField', 'STRING', mode='REQUIRED')
]
#The query is returned as a tuple per row
for value in rows:
table_ref = dataset_ref.table(value[0])
table = bigquery.Table(table_ref, schema=schema)
table = client.create_table(table)
assert table.table_id == value[0]
Имейте в виду, что имя таблицы может содержать только буквы (верхний или нижний регистр), цифры и подчеркивания.Таким образом, вы можете получить исключение, если попытаетесь использовать недопустимые значения.