如何强制bigquery将csv文件的所有列加载为不带模式的字符串,并且autodetect=False



我在gcs中存储了多个csv文件,我想使用云运行将它们加载到bigquery中。

问题是,我不知道架构,而且架构是可变的,所以总是会更改。我也不想在加载文件时使用自动检测选项。我想使用bigquery-api-loadconfig将csv文件加载到bigquery,不带模式和autodetect=False,所有列都被认为是字符串类型。

这可能吗?

我尝试使用pandas数据帧,但文件太大,所以总是存在内存问题。

使用以下函数生成所有列为STRING类型的架构。

def getschema(file_path):
'''Get schema from CSV with all columns as string'''
schema = []
with open(file_path, 'r') as read_obj:
# pass the file object to DictReader() to get the DictReader object
csv_dict_reader = DictReader(read_obj)
# get column names from a csv file
column_names = csv_dict_reader.fieldnames
for c in column_names:
schema.append(bigquery.SchemaField(c,"STRING"))
return schema

最新更新