0

我正在尝试使用需要动态模式处理的 python 代码将数据附加到 BQ 表。谁能给我提供处理上述情况的链接。

4

1 回答 1

0

使用 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))

另请查看文档的这一部分,以了解有关使用相同或不同模式将源文件中的数据附加到表中的更多信息。

于 2019-08-08T10:31:57.090 回答