[英]Dynamic Handing of Bigquery table schema while inserting data into BQ table from variable
I am trying to append data to BQ table using python code which requires dynamic schema handling. 我正在尝试使用需要动态架构处理的python代码将数据追加到BQ表中。 Can anyone provide me the link to handle above scenario.
谁能为我提供处理上述情况的链接。
An example code of loading a .csv file into BigQuery using the python client library: 使用python客户端库将.csv文件加载到BigQuery中的示例代码:
# from google.cloud import bigquery
# client = bigquery.Client()
# filename = '/path/to/file.csv'
# dataset_id = 'my_dataset'
# table_id = 'my_table'
dataset_ref = client.dataset(dataset_id)
table_ref = dataset_ref.table(table_id)
job_config = bigquery.LoadJobConfig()
job_config.source_format = bigquery.SourceFormat.CSV
job_config.skip_leading_rows = 1
job_config.autodetect = True
with open(filename, "rb") as source_file:
job = client.load_table_from_file(source_file, table_ref, job_config=job_config)
job.result() # Waits for table load to complete.
print("Loaded {} rows into {}:{}.".format(job.output_rows, dataset_id, table_id))
Also check this part of the documentation to know more about appending data into tables from a source file using the same or different schema. 另请参阅文档的此部分,以了解有关使用相同或不同模式将数据从源文件追加到表中的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.