gpt4 book ai didi

python - "Response too large to return"在 BigQuery 中的简单 SELECT,即使 allowLargeResults=True?

转载 作者:太空宇宙 更新时间:2023-11-04 10:18:24 25 4
gpt4 key购买 nike

我将 BigQuery 与 Python 结合使用。我正在尝试弄清楚如何运行一个简单的 SELECT 查询,但我收到有关大结果的错误。

在用 Python 编写查询之前,我已经在 BigQuery 界面中测试了我的查询。它运行良好,返回 1 行,耗时 4.0 秒,处理 18.2GB。底层表约为 150GB,200m 行。

这是我的代码:

credentials = GoogleCredentials.get_application_default()
bigquery_service = build('bigquery', 'v2', credentials=credentials)
try:
query_request = bigquery_service.jobs()
query_data = {
"allowLargeResults": True,
'query': (
'SELECT org_code, item_code FROM [mytable] ',
"WHERE (time_period='201501') ",
"AND item_code='0212000AAAAAAAA' ",
"AND (org_code='B82005') "
"LIMIT 10;"
)
}
print ' '.join(query_data['query'])
response = query_request.query(
projectId=project_id,
body=query_data).execute()
job_ref = response['jobReference']
print 'job_ref', job_ref

except HttpError as err:
print('Error: {}'.format(err.content))
raise err

这是我得到的输出:

SELECT org_code, item_code FROM [mytable]  WHERE (time_period='201501')  AND (item_code='0212000AAAAAAAA')  AND (org_code='B82005') LIMIT 10;
Error: {
"error": {
"errors": [
{
"domain": "global",
"reason": "responseTooLarge",
"message": "Response too large to return. Consider setting allowLargeResults to true in your job configuration. For more information, see https://cloud.google.com/bigquery/troubleshooting-errors"
}
],
"code": 403,
"message": "Response too large to return. Consider setting allowLargeResults to true in your job configuration. For more information, see https://cloud.google.com/bigquery/troubleshooting-errors"
}
}

Traceback (most recent call last):
File "query.py", line 93, in <module>
main(args.project_id)
File "query.py", line 82, in main
raise err
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/bigquery/v2/projects/824821804911/queries?alt=json returned "Response too large to return. Consider setting allowLargeResults to true in your job configuration. For more information, see https://cloud.google.com/bigquery/troubleshooting-errors">

有几个不同的事情让我对此感到困惑:

  1. 它说我应该使用 allowLargeResults,即使我已经在使用了。
  2. 虽然这是一个没有分组的简单 SELECT 查询,但它向我发出了关于大结果的警告,并且它返回 1 行。

我知道如果查询处理的任何部分变得太大,就会触发警告。但我真的不知道如何解决这个问题,因为我正在做的查询只是一个 SELECT 没有分组等。我什至没有使用 SELECT *

BigQuery 的全部意义就在于它可以处理这种事情吗?

我该如何解决这个问题?

最佳答案

如果 configuration.query.allowLargeResults 设置为 true - 它还需要 configuration.query.destinationTable

您应该添加 destinationTable 对象或(因为您的输出看起来很小)将 allowLargeResults 设置为 false

Added example of configuration:

'query': {
'query': 'my_query_text',
'destinationTable': {
'projectId': 'my_project',
'datasetId': 'my_dataset',
'tableId': 'my_table'
},
'createDisposition': 'CREATE_IF_NEEDED',
'writeDisposition': 'WRITE_TRUNCATE',
'allowLargeResults': True
}

关于python - "Response too large to return"在 BigQuery 中的简单 SELECT,即使 allowLargeResults=True?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33842657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com