处理 bigquery 中的坏行

Handling bad lines in bigquery

我正在使用 google.bigquery.python api 以便每天自动将数据集从 GCS 存储桶加载到 Bigquery。我为这个数据集指定了一个模式,直到有一天我遇到这个错误:

ERROR - {u'state': u'DONE', u'errors': [{u'reason': u'invalid', u'message': u'Invalid argument: xxxxxxxxxxx@gmail.com', u'location': u'File: 0 / Line:1283011 / Field:44'},
{u'reason': u'invalid', u'message': u'Invalid argument: xxxxxxxxxxx@gmail.com', u'location': u'File: 0 / Line:1338016 / Field:44'}, {u'reason': u'invalid', u'message': u'Too many errors encountered. Limit is: 0.'}], u'errorResult': {u'reason': u'invalid', u'message': u'Too many errors encountered. Limit is: 0.'}}

我的问题是:如何让 bigquery 自动删除不符合架构的行?

如果您使用的是 bq 命令行客户端,则选项为 --max-bad-records。这告诉 BQ 在加载作业失败之前要忽略多少坏记录。默认值为零。我不记得设置这个正数是让坏行进入数据还是只忽略并抑制错误。您可能需要手动测试它。

发件人:https://cloud.google.com/bigquery/bq-command-line-tool

--max_bad_records Type: integer Description: The maximum number of bad rows to skip before the load job is aborted and no updates are performed. If this value is larger than 0, the job will succeed as long as the number of bad records do not exceed this value. This is useful if you would like to load files that may have bad records. The default value for this parameter is 0 (all rows are required to be valid).

Valid Values: Any integer

Usage: bq load --max_bad_records=3 <destination_table> <data_source_uri> [<table_schema>]

在pythonAPI中这个字段叫做maxBadRecords。您可以在 the python BigQuery API repo on Github 中搜索 maxBadRecords,您会在加载作业的作业 API 配置中看到它。

抱歉无法评论 Paul 的回答,因为我的声誉不到 50。

回复:设置这个正数是让坏行进入数据还是只忽略并抑制错误

坏行将被忽略,不会进入加载数据。