【问题标题】:Loading from AVRO to BigQuery - specify decimal type in the target table从 AVRO 加载到 BigQuery - 在目标表中指定十进制类型
【发布时间】:2021-05-14 13:31:33
【问题描述】:

我正在使用 Google 的 Python SDK (https://googleapis.dev/python/bigquery/latest/index.html) 将 AVRO 文件加载到 BigQuery。由于数据中有BigNumeric 列,我需要指定--decimal_target_types=BIGNUMERIC 标志。有没有办法在 LoadJobConfig 对象中这样做?到目前为止我还没有成功:

import os
from google.cloud import bigquery

os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = './importer_google_credentials.json'

BUCKET_NAME = 'unique-bucket-name'
FILE_NAME = 'small-data-*.avro'

source_uri = 'gs://{}/{}'.format(BUCKET_NAME, FILE_NAME)
table_uri = "unique-table-name"

client = bigquery.Client()

job_config = bigquery.LoadJobConfig()
job_config.use_avro_logical_types = True
job_config.source_format = bigquery.SourceFormat.AVRO
job_config.autodetect = True
job_config.decimal_target_types = "BIGNUMERIC" #throws an AttributeError: Property decimal_target_types is unknown for <class 'google.cloud.bigquery.job.load.LoadJobConfig'>.

load_job = client.load_table_from_uri(
    source_uri, table_uri, job_config=job_config
)
load_job.result()  # Waits for the job to complete.

destination_table = client.get_table(table_uri)
print("Loaded {} rows.".format(destination_table.num_rows))

【问题讨论】:

    标签: python google-bigquery avro


    【解决方案1】:

    截至 26.05.2021 似乎无法使用 Python SDK 实现我想要的。我最终使用了bq 命令行工具和--decimal_target_types=BIGNUMERIC

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-20
      • 2022-01-22
      • 2023-01-24
      • 2019-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多