【问题标题】:BigQuery - Where can I find the error stream?BigQuery - 在哪里可以找到错误流?
【发布时间】:2019-02-05 14:55:49
【问题描述】:

我已将一个包含 300K 行的 CSV 文件从 GCS 上传到 BigQuery,但收到以下错误:

在哪里可以找到错误流?

我已将创建表配置更改为允许 4000 个错误并且它有效,因此消息中的 3894 行肯定有问题,但此错误消息并没有告诉我太多关于哪些行或原因。

谢谢

【问题讨论】:

    标签: google-cloud-platform google-bigquery


    【解决方案1】:

    我终于通过在终端中运行以下命令来查看错误流:

    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"
    

    【讨论】:

    • 我有一份工作有 1k+ badRecords,但只显示 status.error[] 中的 5 个项目。如何查看其他不良记录的所有错误?
    • 这里的 JobID 是什么?
    【解决方案2】:

    您应该能够在 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>
    

    【讨论】:

    • @Thanks Elliot 但我只看到我发布的一行。它有行号,但没有显示错误原因。
    • 艾略特也一样。在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.
    • 我编辑了我的答案,我意识到艾米不久前也添加了一个,展示了如何使用 CLI 打印完整的作业信息。
    • @ElliottBrossard Bigquery 如何计算 CSV 文件中的位置?我在位置 482 处收到错误消息。但是当上传只有 5 行 (480-484) 的表格时,它不会抛出错误
    • 我不再在 BigQuery 团队工作(我搬到了 Snowflake)
    【解决方案3】:

    使用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
    

    【讨论】:

    • 在 Jupyter 中使用它时,这似乎没有为我们打印更多内容。想法?
    • 在我的情况下,job.errors 包含基本消息,但也包含有关我的 CSV 问题的更详细消息。异常没有那么多细节。所以我推荐job.errors
    【解决方案4】:

    按照其余答案,您还可以在 GCP 日志 (Stackdriver) 工具中看到此信息。

    但这可能无法回答您的问题。似乎存在详细的错误(例如 Elliot 发现的错误)和更不精确的错误。与您用来探索它的 UI 无关,这根本不会给您提供任何描述。

    【讨论】:

    • 现在我正在手动读取千兆字节的 CSV,因为 Google Cloud 不知道如何发现错误。或者更好的是,它不想给我看:)
    【解决方案5】:

    你也可以这样做。

    try:
        load_job.result()  # Waits for the job to complete.
    except ClientError as e:
        print(load_job.errors)
        raise e
    

    这会将错误打印到屏幕上,或者您可以记录它们等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-11
      • 2014-09-13
      • 1970-01-01
      • 2019-11-11
      • 2021-12-06
      • 2013-04-04
      • 1970-01-01
      相关资源
      最近更新 更多