Pab*_*o H 5 google-cloud-storage google-bigquery google-cloud-platform
我创建了一个 python 脚本来从 Google Cloud Storage 存储桶中获取 JSON 文件并将其加载到数据集中。我在尝试指定与文本文件位于同一存储桶中的架构时遇到问题
我的架构文件是一个 txt 文件,格式如下Attribute:DataType,Attribute:DataType
这就是我所拥有的
job_config = bigquery.LoadJobConfig()
schema_uri = 'gs://<bucket-name>/FlattenedProduct_schema.txt'
schema = schema_uri
job_config.schema = schema    
job_config.source_format = bigquery.SourceFormat.NEWLINE_DELIMITED_JSON
uri = 'gs://<bucket-name>/FlattenedProduct_JSON.txt'
load_job = client.load_table_from_uri(
    uri,
    dataset_ref.table('us_states'),
    location='US',  # Location must match that of the destination dataset.
    job_config=job_config)  # API request
您需要自己读取文本文件并将其转换为schema所需的格式,即目标表的 List[google.cloud.bigquery.schema.SchemaField] \xe2\x80\x93 Schema。
所需架构的示例:
\n\nfrom google.cloud.bigquery import SchemaField\n\nschem = [\n     SchemaField(\'field1\',\'STRING\'),\n     SchemaField(\'field2\', \'INTEGER\'),\n     SchemaField(\'value\', \'FLOAT\')\n    ]\n| 归档时间: | 
 | 
| 查看次数: | 8404 次 | 
| 最近记录: |