【发布时间】:2019-02-05 14:55:49
【问题描述】:
我已将一个包含 300K 行的 CSV 文件从 GCS 上传到 BigQuery,但收到以下错误:
在哪里可以找到错误流?
我已将创建表配置更改为允许 4000 个错误并且它有效,因此消息中的 3894 行肯定有问题,但此错误消息并没有告诉我太多关于哪些行或原因。
谢谢
【问题讨论】:
标签: google-cloud-platform google-bigquery
我已将一个包含 300K 行的 CSV 文件从 GCS 上传到 BigQuery,但收到以下错误:
在哪里可以找到错误流?
我已将创建表配置更改为允许 4000 个错误并且它有效,因此消息中的 3894 行肯定有问题,但此错误消息并没有告诉我太多关于哪些行或原因。
谢谢
【问题讨论】:
标签: google-cloud-platform google-bigquery
我终于通过在终端中运行以下命令来查看错误流:
bq --format=prettyjson show -j <JobID>
它返回一个包含更多细节的 JSON。 在我的情况下是:
"message": "Error while reading data, error message: Could not parse '16.66666666666667' as int for field Course_Percentage (position 46) starting at location 1717164"
【讨论】:
您应该能够在 BigQuery 用户界面中点击 Job History,然后点击失败的加载作业。我刚才尝试加载一个无效的 CSV 文件,我看到的错误是:
Errors:
Error while reading data, error message: CSV table encountered too many errors, giving up. Rows: 1; errors: 1. Please look into the error stream for more details. (error code: invalid)
Error while reading data, error message: CSV table references column position 1, but line starting at position:0 contains only 1 columns. (error code: invalid)
第一个错误只是指示失败的一般消息,但第二个错误(来自“错误流”)是为失败提供更多上下文的错误,即CSV table references column position 1, but line starting at position:0 contains only 1 columns。
编辑:给定作业 ID,您还可以使用 BigQuery CLI 查看有关失败的完整信息。你会使用:
bq --format=prettyjson show -j <job ID>
【讨论】:
Job Details 我只是发现了这个错误:Error while reading data, error message: CSV table encountered too many errors, giving up. Rows: 1; errors: 1. Please look into the error stream for more details.
使用python客户端
from google.api_core.exceptions import BadRequest
job = client.load_table_from_file(*args, **kwargs)
try:
result = job.result()
except BadRequest as ex:
for err in ex.errors:
print(err)
raise
# or alternatively
# job.errors
【讨论】:
job.errors 包含基本消息,但也包含有关我的 CSV 问题的更详细消息。异常没有那么多细节。所以我推荐job.errors
按照其余答案,您还可以在 GCP 日志 (Stackdriver) 工具中看到此信息。
但这可能无法回答您的问题。似乎存在详细的错误(例如 Elliot 发现的错误)和更不精确的错误。与您用来探索它的 UI 无关,这根本不会给您提供任何描述。
【讨论】:
你也可以这样做。
try:
load_job.result() # Waits for the job to complete.
except ClientError as e:
print(load_job.errors)
raise e
这会将错误打印到屏幕上,或者您可以记录它们等。
【讨论】: