我在gcs中存储了多个csv文件,我希望使用云运行将它们加载到bigquery中。
我不知道模式和模式是变量的问题总是会改变,我也不想在加载文件时使用自动检测选项。我希望使用bigquery将csv文件加载到bigquery中,而不使用模式和autodetect=False,所有列都考虑了string类型。
这有可能吗?
我试着使用熊猫的数据格式,但是文件太大了,所以总是存在内存问题。
发布于 2022-11-13 10:01:59
使用以下函数生成所有列都作为字符串类型的架构。
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
https://stackoverflow.com/questions/71750473
复制