【问题标题】:BigQuery: too many table dml insert operations for this tableBigQuery:此表的表 dml 插入操作过多
【发布时间】:2021-02-27 19:02:44
【问题描述】:

我正在尝试通过 Python 客户端将不同计算机 (n=20) 上的超过 2 亿条记录导入我的 BigQuery 表。每台计算机每 10. 秒运行一次作业(多行)

from google.cloud import bigquery
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = os.getcwd() + '/api.json'

print('Import job started, total rows:' + str(len(queries)))
client = bigquery.Client()
for q in queries:
    results = client.query(q)
    for err in results:
        print(err)

但我收到以下错误:

google.api_core.exceptions.Forbidden: 403 Exceeded rate limits: too 此表的许多表 dml 插入操作。了解更多信息, 见https://cloud.google.com/bigquery/troubleshooting-errors

数据是在运行时生成的。所以我必须在运行时导入数据。我也不确定 BigQuery 是否适用于此。 Spanner 似乎更好,但它太贵了。

如何避免此错误? 非常感谢。

【问题讨论】:

  • 不要对这项工作使用 DML,而是使用支持每秒 1M 行的流式插入。

标签: python google-bigquery


【解决方案1】:

将数据插入 BigQuery 表的主要方法有 4 种。

  1. 批量加载一组数据记录。
  2. 流式传输单个记录或成批记录。
  3. 使用查询生成新数据并将结果附加或覆盖到表中。
  4. 使用第三方应用程序或服务。

我认为您正在使用第三个选项,即 DML INSERT。它不是为大规模高频数据加载用例而设计的。

在您的用例中,第二个选项(流数据)似乎很合适。

例子

from google.cloud import bigquery

# Construct a BigQuery client object.
client = bigquery.Client()

# TODO(developer): Set table_id to the ID of table to append to.
# table_id = "your-project.your_dataset.your_table"

rows_to_insert = [
    {u"full_name": u"Phred Phlyntstone", u"age": 32},
    {u"full_name": u"Wylma Phlyntstone", u"age": 29},
]

errors = client.insert_rows_json(table_id, rows_to_insert)  # Make an API request.
if errors == []:
    print("New rows have been added.")
else:
    print("Encountered errors while inserting rows: {}".format(errors))

您可以在此处查看更多详细信息。 https://cloud.google.com/bigquery/streaming-data-into-bigquery

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-28
    • 2019-02-19
    • 1970-01-01
    • 2020-06-01
    • 2018-08-20
    • 2015-01-12
    • 2021-09-30
    • 2023-04-06
    相关资源
    最近更新 更多