【问题标题】:Loading data from GCS to BigQuery using Wildcards and Autodetect使用通配符和自动检测将数据从 GCS 加载到 BigQuery
【发布时间】:2018-04-18 11:26:36
【问题描述】:

刚刚在 StackOverflow 上发帖。

使用 google.cloud.bigquery python SDK,我一直在尝试制定一种解决方案,在不定义表架构的情况下将数据从 GCS 加载到 BigQuery。

我的 LoadJobConfig 的自动检测设置为 True,并且我在 GCS URI 中使用通配符 (*)。

我已经确认 Autodetect 可以使用通配符,但加载作业失败,因为我正在使用的数据源通常会自动检测特定列为浮点数(例如 0.30),但有时会添加运算符符号(例如

任何人都可以在无需定义架构的情况下想出解决方案吗?这是我传递给bigquery.client.Clientload_table_from_uri 方法的LoadJobConfig

source_uri = 'gs://%s/%s/%s/*' % (source, report_type, date)
job_config = bigquery.LoadJobConfig()
job_config.create_disposition = 'CREATE_IF_NEEDED'
job_config.skip_leading_rows = 1
job_config.source_format = 'CSV'
job_config.write_disposition = 'WRITE_TRUNCATE'
job_config.autodetect = True
job = bigquery_client.load_table_from_uri(source_uri, table_ref, job_config=job_config)
job.result()

【问题讨论】:

    标签: python google-bigquery google-cloud-platform


    【解决方案1】:

    您的数据似乎在某些部分损坏了。

    我建议使用标志:--max_bad_records,它会跳过损坏的记录。

    详情请看这里:https://cloud.google.com/bigquery/docs/loading-data-cloud-storage-csv#bigquery-import-gcs-file-python

    【讨论】:

    • 添加 --max_bad_records 解决了我的问题。我对此唯一担心的可能是如果有任何错误条目,我的LoadJobConfig 可能不够严格。不过,现在将使用它作为我的解决方案,非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多