使用通配符和自动检测将数据从GCS加载到BigQuery

时间:2017-11-06 10:18:56

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

在StackOverflow上发布的新内容。

使用google.cloud.bigquery python SDK,我一直在努力构建一个解决方案,将数据从GCS加载到BigQuery,而无需定义表架构。

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

我已确认Autodetect适用于通配符,但加载作业失败,因为我正在使用的数据源通常会自动检测特定列为浮点数(例如0.30),但有时会添加运算符符号(例如< 0.10)因此需要是一个字符串。

任何人都可以在不必定义架构的情况下考虑解决方案吗?这是我LoadJobConfig传递给bigquery.client.Client load_table_from_uri方法的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()

{{1}}

1 个答案:

答案 0 :(得分:0)

您的数据似乎在某些方面被破坏了。

我建议使用flag:--max_bad_records来跳过破碎的记录。

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

相关问题